org.crosswire.jsword.book.sword
Class RawBackend<T extends RawBackendState>

java.lang.Object
  extended by org.crosswire.jsword.book.sword.AbstractBackend<RawBackendState>
      extended by org.crosswire.jsword.book.sword.RawBackend<T>
Type Parameters:
T - The type of the RawBackendState that this class extends.
All Implemented Interfaces:
Backend<RawBackendState>, StatefulFileBackedBackend<RawBackendState>
Direct Known Subclasses:
RawFileBackend

public class RawBackend<T extends RawBackendState>
extends AbstractBackend<RawBackendState>

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

Author:
Joe Walker
See Also:
The GNU Lesser General Public License for details.

Field Summary
protected  int datasize
          How many bytes in the size count in the index
protected  int entrysize
          The number of bytes for each entry in the index: either 6 or 8
private static org.slf4j.Logger log
          The log stream
protected static int OFFSETSIZE
          How many bytes in the offset pointers in the index
 
Constructor Summary
RawBackend(SwordBookMetaData sbmd, int datasize)
          Simple ctor
 
Method Summary
 boolean contains(Key key)
          Determine whether this Book contains the key in question
protected  String getEntry(RawBackendState state, String name, Testament testament, long index)
          Get the text for an indexed entry in the book.
 Key getGlobalKeyList()
          Gets the fast global key list, and if this operation is not supported, throws a UnsupportedOperationException
protected  DataIndex getIndex(RandomAccessFile raf, long entry)
          Get the Index (that is offset and size) for an entry.
 String getRawText(RawBackendState state, Key key)
           
 int getRawTextLength(Key key)
          Determine the size of the raw data for the key in question.
 T initState()
          Initialises the state required to read from files, specific to each different backend
 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.
 String readRawContent(RawBackendState state, Key key)
           
 void setAliasKey(RawBackendState state, Key alias, Key source)
          Sets alias for a comment on a verse range I.e.
 void setRawText(RawBackendState state, 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, getRawText, isSupported, readIndex, readToOsis, setAliasKey
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

datasize

protected final int datasize
How many bytes in the size count in the index


entrysize

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


OFFSETSIZE

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

See Also:
Constant Field Values

log

private static final org.slf4j.Logger log
The log stream

Constructor Detail

RawBackend

public RawBackend(SwordBookMetaData sbmd,
                  int datasize)
Simple ctor

Parameters:
sbmd -
datasize -
Method Detail

contains

public boolean contains(Key key)
Description copied from interface: Backend
Determine whether this Book contains the key in question

Specified by:
contains in interface Backend<RawBackendState>
Specified by:
contains in class AbstractBackend<RawBackendState>
Parameters:
key - The key whose presence is desired.
Returns:
true if the Book contains the key

getRawTextLength

public int getRawTextLength(Key key)
Description copied from interface: Backend
Determine the size of the raw data for the key in question. This method may not be faster than getting the raw text and getting its size.

Specified by:
getRawTextLength in interface Backend<RawBackendState>
Overrides:
getRawTextLength in class AbstractBackend<RawBackendState>
Parameters:
key - The key whose raw data length is desired.
Returns:
The length of the raw data, 0 if not a valid key.

getGlobalKeyList

public Key getGlobalKeyList()
                     throws BookException
Description copied from interface: Backend
Gets the fast global key list, and if this operation is not supported, throws a UnsupportedOperationException

Specified by:
getGlobalKeyList in interface Backend<RawBackendState>
Overrides:
getGlobalKeyList in class AbstractBackend<RawBackendState>
Returns:
the fast global key list
Throws:
BookException - the book exception if for some reason the book failed to be read properly.

initState

public T initState()
                                    throws BookException
Description copied from interface: StatefulFileBackedBackend
Initialises the state required to read from files, specific to each different backend

Returns:
the state that has been initialised
Throws:
BookException

getRawText

public String getRawText(RawBackendState state,
                         Key key)
                  throws IOException
Throws:
IOException

readRawContent

public String readRawContent(RawBackendState state,
                             Key key)
                      throws IOException
Parameters:
state - the state object containing all the open random access files
key - the verse that is sought
Returns:
the raw text
Throws:
IOException - something went wrong when reading the verse

setRawText

public void setRawText(RawBackendState state,
                       Key key,
                       String text)
                throws BookException,
                       IOException
Description copied from interface: StatefulFileBackedBackend
Set the text allotted for the given verse

Parameters:
state - TODO
key - The key to set text to
text - The text to be set for key
Throws:
BookException - If the data can not be set.
IOException - If the module data path could not be created.

isWritable

public boolean isWritable()
Description copied from interface: Backend
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 most backends, so abstract implementations should return false and let specific implementations return true otherwise.

Specified by:
isWritable in interface Backend<RawBackendState>
Overrides:
isWritable in class AbstractBackend<RawBackendState>
Returns:
true if the book is writable

setAliasKey

public void setAliasKey(RawBackendState state,
                        Key alias,
                        Key source)
                 throws IOException
Description copied from interface: StatefulFileBackedBackend
Sets alias for a comment on a verse range I.e. setRawText() was for verse range Gen.1.1-3 then setAliasKey should be called for Gen.1.1.2 and Gen.1.1.3

Parameters:
state - the open file state
alias - Alias Key
source - Source Key
Throws:
IOException - Exception when anything goes wrong on writing the alias

getIndex

protected 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

protected String getEntry(RawBackendState state,
                          String name,
                          Testament testament,
                          long index)
                   throws IOException
Get the text for an indexed entry in the book.

Parameters:
state -
index - the entry to get
name - name of the entry
testament - the testament for the entry
Returns:
the text for the entry.
Throws:
IOException - on a IO problem

Copyright ยจ 2003-2015