|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.crosswire.jsword.book.sword.AbstractBackend
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 boolean |
active
Are we active |
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 long |
lastBlockNum
|
private Testament |
lastTestament
|
private byte[] |
lastUncompressed
|
private static Logger |
log
The log stream |
private File |
ntCompFile
|
private RandomAccessFile |
ntCompRaf
|
private File |
ntIdxFile
|
private RandomAccessFile |
ntIdxRaf
|
private File |
ntTextFile
|
private RandomAccessFile |
ntTextRaf
|
private File |
otCompFile
The compressed random access files |
private RandomAccessFile |
otCompRaf
The compressed random access files |
private File |
otIdxFile
The index random access files |
private RandomAccessFile |
otIdxRaf
The index random access files |
private File |
otTextFile
The data random access files |
private RandomAccessFile |
otTextRaf
The data random access files |
private static String |
SUFFIX_COMP
|
private static String |
SUFFIX_INDEX
|
private static String |
SUFFIX_PART1
|
private static String |
SUFFIX_TEXT
|
| Constructor Summary | |
|---|---|
ZVerseBackend(SwordBookMetaData sbmd,
BlockType blockType)
Simple ctor |
|
| Method Summary | |
|---|---|
void |
activate(Lock lock)
Called to indicate that the Book should initialize itself, and consume whatever system resources it needs to be able to respond to other queries. |
protected void |
checkActive()
Helper method so we can quickly activate ourselves on access |
boolean |
contains(Key key)
Determine whether this Book contains the key in question |
void |
deactivate(Lock lock)
Called to indicate that the Book should release whatever system resources it can to make way for other uses. |
String |
getRawText(Key key)
Get the text allotted for the given entry |
void |
setAliasKey(Key alias,
Key source)
Sets alias for a comment on a verse range I.e. |
void |
setRawText(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, getExpandedDataPath, isSupported, isWritable, readIndex |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final String SUFFIX_COMP
private static final String SUFFIX_INDEX
private static final String SUFFIX_PART1
private static final String SUFFIX_TEXT
private BlockType blockType
private Testament lastTestament
private long lastBlockNum
private byte[] lastUncompressed
private boolean active
private RandomAccessFile otIdxRaf
private RandomAccessFile ntIdxRaf
private RandomAccessFile otTextRaf
private RandomAccessFile ntTextRaf
private RandomAccessFile otCompRaf
private RandomAccessFile ntCompRaf
private File otIdxFile
private File ntIdxFile
private File otTextFile
private File ntTextFile
private File otCompFile
private File ntCompFile
private static final int COMP_ENTRY_SIZE
private static final int IDX_ENTRY_SIZE
private static final Logger log
| Constructor Detail |
|---|
public ZVerseBackend(SwordBookMetaData sbmd,
BlockType blockType)
| Method Detail |
|---|
public final void activate(Lock lock)
Activatable
lock - An attempt to ensure that only the Activator calls this methodpublic final void deactivate(Lock lock)
Activatable
lock - An attempt to ensure that only the Activator calls this methodpublic boolean contains(Key key)
AbstractBackend
contains in class AbstractBackendkey - The key whose presence is desired.
public String getRawText(Key key)
throws BookException
AbstractBackend
getRawText in class AbstractBackendkey - The key to fetch
BookException - If the data can not be read.
public void setAliasKey(Key alias,
Key source)
throws IOException
AbstractBackend
setAliasKey in class AbstractBackendalias - Alias Keysource - Source Key
IOException - Exception when anything goes wrong on writing the alias
public void setRawText(Key key,
String text)
throws BookException,
IOException
AbstractBackend
setRawText in class AbstractBackendkey - 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.protected final void checkActive()
|
Copyright ? 2003-2011 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||