public class ZVerseBackend extends AbstractBackend<ZVerseBackendState>
The blocks can either be "b", book (aka testament); "c", chapter or "v", verse. The choice is a matter of trade offs. The program needs to uncompress a block into memory. Having it at the book level is very memory expensive. Having it at the verse level is very disk expensive, but takes the least amount of memory. The most common is chapter.
In order to find the data in the text file, we need to find the block. The first index (idx) is used for this. Each verse is indexed to a tuple (block number, verse start, verse size). This data allows us to find the correct block, and to extract the verse from the uncompressed block, but it does not help us uncompress the block.
Once the block is known, then the next index (comp) gives the location of the compressed block, its compressed size and its uncompressed size.
There are 3 files for each testament, 2 (idx and comp) are indexes into the third (text) which contains the data. The key into each index is the verse index within that testament, which is determined by book, chapter and verse of that key.
All unsigned numbers are stored 2-complement, little endian.
Then proceed as follows, at all times working on the set of files for the testament in question:
The three files are laid out in the following fashion:The GNU Lesser General Public License for details.
Modifier and Type | Field and Description |
---|---|
private BlockType |
blockType
Whether the book is blocked by Book, Chapter or Verse.
|
private static int |
COMP_ENTRY_SIZE
How many bytes in the comp index?
|
private static int |
IDX_ENTRY_SIZE
How many bytes in the idx index?
|
private static org.slf4j.Logger |
log
The log stream
|
Constructor and Description |
---|
ZVerseBackend(SwordBookMetaData sbmd,
BlockType blockType)
Simple ctor
|
Modifier and Type | Method and Description |
---|---|
boolean |
contains(Key key)
Determine whether this Book contains the key in question
|
void |
dumpCompRaf(RandomAccessFile raf)
Experimental code.
|
void |
dumpIdxRaf(Versification v11n,
int ordinalStart,
RandomAccessFile raf)
Experimental code.
|
Key |
getGlobalKeyList()
Gets the fast global key list, and if this operation is not supported, throws a
UnsupportedOperationException |
int |
getRawTextLength(Key key)
Determine the size of the raw data for the key in question.
|
ZVerseBackendState |
initState()
Initialises the state required to read from files, specific to each
different backend
|
String |
readRawContent(ZVerseBackendState rafBook,
Key key) |
void |
setAliasKey(ZVerseBackendState rafBook,
Key alias,
Key source)
Sets alias for a comment on a verse range I.e.
|
void |
setRawText(ZVerseBackendState rafBook,
Key key,
String text)
Set the text allotted for the given verse
|
create, decipher, encipher, getBookMetaData, getRawText, isSupported, isWritable, readIndex, readToOsis, setAliasKey
private final BlockType blockType
private static final int IDX_ENTRY_SIZE
private static final int COMP_ENTRY_SIZE
private static final org.slf4j.Logger log
public ZVerseBackend(SwordBookMetaData sbmd, BlockType blockType)
sbmd
- blockType
- public boolean contains(Key key)
Backend
contains
in interface Backend<ZVerseBackendState>
contains
in class AbstractBackend<ZVerseBackendState>
key
- The key whose presence is desired.public int getRawTextLength(Key key)
Backend
getRawTextLength
in interface Backend<ZVerseBackendState>
getRawTextLength
in class AbstractBackend<ZVerseBackendState>
key
- The key whose raw data length is desired.public Key getGlobalKeyList() throws BookException
Backend
UnsupportedOperationException
getGlobalKeyList
in interface Backend<ZVerseBackendState>
getGlobalKeyList
in class AbstractBackend<ZVerseBackendState>
BookException
- the book exception if for some reason the book failed to be read properly.public ZVerseBackendState initState() throws BookException
StatefulFileBackedBackend
BookException
public String readRawContent(ZVerseBackendState rafBook, Key key) throws IOException
rafBook
- the state object containing all the open random access fileskey
- the verse that is soughtIOException
- something went wrong when reading the versepublic void setAliasKey(ZVerseBackendState rafBook, Key alias, Key source) throws IOException
StatefulFileBackedBackend
rafBook
- the open file statealias
- Alias Keysource
- Source KeyIOException
- Exception when anything goes wrong on writing the aliaspublic void setRawText(ZVerseBackendState rafBook, Key key, String text) throws BookException, IOException
StatefulFileBackedBackend
rafBook
- TODOkey
- The key to set text totext
- The text to be set for keyBookException
- If the data can not be set.IOException
- If the module data path could not be created.public void dumpIdxRaf(Versification v11n, int ordinalStart, RandomAccessFile raf)
v11n
- ordinalStart
- raf
- public void dumpCompRaf(RandomAccessFile raf)
raf
-