org.crosswire.jsword.book.sword
Class RawBackend

java.lang.Object
  extended by org.crosswire.jsword.book.sword.AbstractBackend
      extended by org.crosswire.jsword.book.sword.RawBackend
All Implemented Interfaces:
Activatable

public class RawBackend
extends AbstractBackend

Both Books and Commentaries seem to use the same format so this class abstracts out the similarities.

Author:
Joe Walker [joe at eireneh dot com]
See Also:
for license details. The copyright to this program is held by it's authors.

Field Summary
private  boolean active
          Are we active
private  int datasize
          How many bytes in the size count in the index
private  int entrysize
          The number of bytes for each entry in the index: either 6 or 8
private  File[] idxFile
          The array of index random access files
private  RandomAccessFile[] idxRaf
          The array of index files
private static Logger log
          The log stream
private static int OFFSETSIZE
          How many bytes in the offset pointers in the index
private  File[] txtFile
          The array of data random access files
private  RandomAccessFile[] txtRaf
          The array of data files
 
Constructor Summary
RawBackend(SwordBookMetaData sbmd, int datasize)
          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)
           
 void create(String path)
           
 void deactivate(Lock lock)
          Called to indicate that the Book should release whatever system resources it can to make way for other uses.
private  String getEntry(String name, int testament, long index)
          Get the text for an indexed entry in the book.
private  DataIndex getIndex(RandomAccessFile raf, long entry)
          Get the Index (that is offset and size) for an entry.
 String getRawText(Key key)
          Get the text allotted for the given entry
 boolean isWritable()
          A Backend is writable if the file system allows the underlying files to be opened for writing and if the backend has implemented writing.
 
Methods inherited from class org.crosswire.jsword.book.sword.AbstractBackend
decipher, encipher, getBookMetaData, getExpandedDataPath, isSupported, readIndex, setRawText
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

active

private boolean active
Are we active


datasize

private int datasize
How many bytes in the size count in the index


entrysize

private int entrysize
The number of bytes for each entry in the index: either 6 or 8


log

private static final Logger log
The log stream


idxRaf

private RandomAccessFile[] idxRaf
The array of index files


txtRaf

private RandomAccessFile[] txtRaf
The array of data files


idxFile

private File[] idxFile
The array of index random access files


txtFile

private File[] txtFile
The array of data random access files


OFFSETSIZE

private static final int OFFSETSIZE
How many bytes in the offset pointers in the index

See Also:
Constant Field Values
Constructor Detail

RawBackend

public RawBackend(SwordBookMetaData sbmd,
                  int datasize)
Simple ctor

Method Detail

contains

public boolean contains(Key key)
Specified by:
contains in class AbstractBackend

getRawText

public String getRawText(Key key)
                  throws BookException
Description copied from class: AbstractBackend
Get the text allotted for the given entry

Specified by:
getRawText in class AbstractBackend
Parameters:
key - The key to fetch
Returns:
String The data for the verse in question
Throws:
BookException - If the data can not be read.

isWritable

public boolean isWritable()
Description copied from class: AbstractBackend
A Backend is writable if the file system allows the underlying files to be opened for writing and if the backend has implemented writing. Ultimately, all drivers should allow writing. At this time writing is not supported by backends, so abstract implementations should return false and let specific implementations return true otherwise.

Overrides:
isWritable in class AbstractBackend
Returns:
true if the book is writable

create

public void create(String path)

activate

public final void activate(Lock lock)
Description copied from interface: Activatable
Called to indicate that the Book should initialize itself, and consume whatever system resources it needs to be able to respond to other queries.

Parameters:
lock - An attempt to ensure that only the Activator calls this method

deactivate

public final void deactivate(Lock lock)
Description copied from interface: Activatable
Called to indicate that the Book should release whatever system resources it can to make way for other uses.

Parameters:
lock - An attempt to ensure that only the Activator calls this method

checkActive

protected final void checkActive()
Helper method so we can quickly activate ourselves on access


getIndex

private DataIndex getIndex(RandomAccessFile raf,
                           long entry)
                    throws IOException
Get the Index (that is offset and size) for an entry.

Parameters:
entry -
Returns:
the index for the entry
Throws:
IOException

getEntry

private String getEntry(String name,
                        int testament,
                        long index)
                 throws IOException
Get the text for an indexed entry in the book.

Parameters:
index - the entry to get
Returns:
the text for the entry.
Throws:
IOException

Copyright ยจ 2003-2007