|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.crosswire.jsword.book.sword.AbstractBackend<ZVerseBackendState>
org.crosswire.jsword.book.sword.ZVerseBackend
public class ZVerseBackend
A backend to read compressed data verse based files. While the text file contains data compressed with ZIP or LZSS, it cannot be uncompressed using a stand alone zip utility, such as WinZip or gzip. The reason for this is that the data file is a concatenation of blocks of compressed data.
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 (comp) 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 (idx) gives the location of the compressed block, its compressed size and its uncompressed size.
There are 3 files for each testament, 2 (comp and idx) 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 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:
in the comp file, seek to the index * 10 read 10 bytes. the block-index is the first 4 bytes (32-bit number) the next bytes are the verse offset and length of the uncompressed block. in the idx file seek to block-index * 12 read 12 bytes the text-block-index is the first 4 bytes the data-size is the next 4 bytes the uncompressed-size is the next 4 bytes in the text file seek to the text-block-index read data-size bytes decipher them if they are encrypted unGZIP them into a byte uncompressed-size
for license details.
The copyright to this program is held by it's authors.
Field Summary | |
---|---|
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 Summary | |
---|---|
ZVerseBackend(SwordBookMetaData sbmd,
BlockType blockType)
Simple ctor |
Method Summary | |
---|---|
boolean |
contains(Key key)
Determine whether this Book contains the key in question |
void |
dumpCompRaf(Versification v11n,
int ordinalStart,
RandomAccessFile raf)
Experimental code. |
void |
dumpIdxRaf(RandomAccessFile raf)
Experimental code. |
Key |
getGlobalKeyList()
Gets the fast global key list, and if this operation is not supported, throws a UnsupportedOperationException |
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 |
Methods inherited from class org.crosswire.jsword.book.sword.AbstractBackend |
---|
create, decipher, encipher, getBookMetaData, getVersification, isSupported, isWritable, readIndex, readToOsis |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private final BlockType blockType
private static final int COMP_ENTRY_SIZE
private static final int IDX_ENTRY_SIZE
private static final org.slf4j.Logger log
Constructor Detail |
---|
public ZVerseBackend(SwordBookMetaData sbmd, BlockType blockType)
Method Detail |
---|
public boolean contains(Key key)
AbstractBackend
contains
in class AbstractBackend<ZVerseBackendState>
key
- The key whose presence is desired.
public Key getGlobalKeyList() throws BookException
AbstractBackend
UnsupportedOperationException
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 sought
IOException
- something went wrong when reading the versepublic void setAliasKey(ZVerseBackendState rafBook, Key alias, Key source) throws IOException
StatefulFileBackedBackend
alias
- Alias Keysource
- Source Key
IOException
- 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 key
BookException
- If the data can not be set.
IOException
- If the module data path could not be created.public void dumpCompRaf(Versification v11n, int ordinalStart, RandomAccessFile raf)
v11n
- ordinalStart
- raf
- public void dumpIdxRaf(RandomAccessFile raf)
raf
-
|
Copyright ? 2003-2011 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |