What's new? | Help | Directory | Sign in
Google
                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
//
// MultiFileBibleSource.java
// GoBible
//
// Created by Jolon Faichney on Thu Jul 24 2003.
// Copyright (c) 2003. All rights reserved.
//

import java.io.*;

public class MultiFileBibleSource extends BibleSource
{
private GoBible goBible;

// Current chapter loaded
private int currentBookIndex = -1;
private int currentChapterIndex = -1;

// Bible index

private int numberOfBooks;
private String[] bookNames;

/** Short book names are for file names as they are ensured to be 7-bit ASCII. **/
private String[] shortBookNames;

// The chapter number that the book starts with, usually 1 but may be
// a larger chapter if the book has been split
private int[] startChapters;
private int[] numberOfChapters;
private int[][] numberOfVerses;

// Book index
private int[][] bookIndex;

// Current chapter data
private char[] verseData;

// The verse bytes are converted to verse data but the array is reused
// for future chapters
private byte[] verseBytes;

private int verseDataSize;

public MultiFileBibleSource(GoBible goBible) throws IOException
{
// We record the midlet as it may be required to access resources
this.goBible = goBible;

// Read in the main index

DataInputStream input = new DataInputStream(goBible.getClass().getResourceAsStream("Bible Data/Index"));

// Read in the number of books
numberOfBooks = input.read();

bookNames = new String[numberOfBooks];
shortBookNames = new String[numberOfBooks];
startChapters = new int[numberOfBooks];
numberOfChapters = new int[numberOfBooks];
numberOfVerses = new int[numberOfBooks][];

for (int bookIndex = 0; bookIndex < numberOfBooks; bookIndex++)
{
// Read in the name of the book
bookNames[bookIndex] = input.readUTF();

// Read in the short book name
shortBookNames[bookIndex] = input.readUTF();
startChapters[bookIndex] = input.read();

// Read in the number of chapters in this book
int numberOfChapters = input.read();
this.numberOfChapters[bookIndex] = numberOfChapters;
numberOfVerses[bookIndex] = new int[numberOfChapters];

// Read in the number of verses for each chapter
for (int chapterIndex = 0; chapterIndex < numberOfChapters; chapterIndex++)
{
numberOfVerses[bookIndex][chapterIndex] = input.read();
}
}

input.close();
}

public char[] getChapter(int bookIndex, int chapterIndex) throws IOException
{
// Load the chapter if it isn't loaded
loadChapter(bookIndex, chapterIndex);

return verseData;
}

public int[] getChapterIndex(int bookIndex, int chapterIndex) throws IOException
{
// Load the chapter if it isn't loaded
loadChapter(bookIndex, chapterIndex);

return this.bookIndex[chapterIndex];
}

private void loadChapter(int bookIndex, int chapterIndex) throws IOException
{
// If the chapter isn't loaded then load it
if (currentBookIndex != bookIndex || currentChapterIndex != chapterIndex)
{
// If the bible canvas is displayed then indicate that we are loading a chapter
if (goBible.display.getCurrent() == goBible.bibleCanvas)
{
// Notify the application that we'll be spending some time loading
goBible.bibleCanvas.enterLoadingMode();
}

// If the book is different then we need to load its index
if (currentBookIndex != bookIndex)
{
loadBookIndex(bookIndex);
}

// Load the chapter as it will be different if either the chapter or book changed
//start = System.currentTimeMillis();

DataInputStream input = new DataInputStream(goBible.getClass().getResourceAsStream("Bible Data/" + shortBookNames[bookIndex] + "/" + shortBookNames[bookIndex] + " " + (chapterIndex + startChapters[bookIndex])));

currentChapterIndex = chapterIndex;

verseData = input.readUTF().toCharArray();
verseDataSize = verseData.length;

//goBible.loadChapterTime = System.currentTimeMillis() - start;
}
}

private void loadBookIndex(int bookIndex) throws IOException
{
int numberOfChapters = this.numberOfChapters[bookIndex];
this.bookIndex = new int[numberOfChapters][];

currentBookIndex = bookIndex;

DataInputStream input = new DataInputStream(goBible.getClass().getResourceAsStream("Bible Data/" + shortBookNames[bookIndex] + "/Index"));

// Read each verse length in for each chapter
for (int chapter = 0; chapter < numberOfChapters; chapter++)
{
// There are two verse entries (offset, length) for every verse
int numberOfVerses = 2 * this.numberOfVerses[bookIndex][chapter];
int[] chapterIndex = new int[numberOfVerses];
this.bookIndex[chapter] = chapterIndex;

int offset = 0;

// Read in each verse length
for (int verse = 0; verse < numberOfVerses; )
{
chapterIndex[verse++] = offset;
offset += input.readUnsignedShort();
chapterIndex[verse++] = offset;
}
}

input.close();
}

public String[] getBookNames()
{
return bookNames;
}

public String getBookName(int bookIndex)
{
return bookNames[bookIndex];
}

public int getNumberOfBooks()
{
return numberOfBooks;
}

public int getStartChapter(int bookIndex)
{
return startChapters[bookIndex];
}

public int getNumberOfChapters(int bookIndex)
{
return numberOfChapters[bookIndex];
}

public int getNumberOfVerses(int bookIndex, int chapterIndex)
{
return numberOfVerses[bookIndex][chapterIndex];
}

public int getVerseDataSize()
{
return verseDataSize;
}
}
Show details Hide details

Change log

r29 by jolonf on Feb 17, 2008   Diff
Initial commit.
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 5434 bytes, 200 lines