org.crosswire.jsword.book.sword
Class RawFileBackend

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

public class RawFileBackend
extends RawBackend

A Raw File format that allows for each verse to have it's own storage. The basic structure of the index is as follows:

Author:
mbergmann, DM Smith [dmsmith555 at yahoo dot com]
See Also:
for license details.
The copyright to this program is held by it's authors.

Field Summary
private  File incfile
           
private static String INCFILE
           
private  int incfileValue
           
private static Logger log
           
 
Fields inherited from class org.crosswire.jsword.book.sword.RawBackend
active, datasize, entrysize, ntIdxFile, ntIdxRaf, ntTxtFile, ntTxtRaf, OFFSETSIZE, otIdxFile, otIdxRaf, otTxtFile, otTxtRaf
 
Constructor Summary
RawFileBackend(SwordBookMetaData sbmd, int datasize)
           
 
Method Summary
private  void checkAndIncrementIncfile(int index)
           
 void create()
          Create the directory to hold the Book if it does not exist.
private  void createDataFiles()
           
private  File createDataTextFile(int index)
           
private  void createIncfile()
           
private  void createIndexFiles()
           
private  File getDataTextFile(RandomAccessFile txtRaf, DataIndex dataIndex)
          Gets the File having the verse text.
protected  String getEntry(String name, Testament testament, long index)
          Get the text for an indexed entry in the book.
 String getRawText(Key key)
          Get the text allotted for the given entry
private  String getTextFilename(RandomAccessFile txtRaf, DataIndex dataIndex)
          Gets the Filename for the File having the verse text.
private  void initIncFile()
           
 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.
private  byte[] littleEndian16BitByteArrayFromShort(short val)
           
private  byte[] littleEndian32BitByteArrayFromInt(int val)
           
private  void prepopulateIncfile()
           
private  void prepopulateIndexFiles()
           
private  int readIncfile()
           
private  byte[] readTextDataFile(File dataFile)
           
 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
protected  void updateDataFile(long ordinal, File txtFile)
           
protected  void updateIndexFile(RandomAccessFile idxRaf, long index, long dataFileStartPosition)
           
private  void writeIncfile(int value)
           
private  void writeInitialIndex(BufferedOutputStream outStream)
           
private  void writeTextDataFile(File dataFile, byte[] textData)
           
 
Methods inherited from class org.crosswire.jsword.book.sword.RawBackend
activate, checkActive, contains, deactivate, getIndex
 
Methods inherited from class org.crosswire.jsword.book.sword.AbstractBackend
decipher, encipher, getBookMetaData, getExpandedDataPath, isSupported, readIndex
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INCFILE

private static final String INCFILE
See Also:
Constant Field Values

incfile

private File incfile

incfileValue

private int incfileValue

log

private static final Logger log
Constructor Detail

RawFileBackend

public RawFileBackend(SwordBookMetaData sbmd,
                      int datasize)
Method Detail

getRawText

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

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

getEntry

protected String getEntry(String name,
                          Testament testament,
                          long index)
                   throws IOException
Description copied from class: RawBackend
Get the text for an indexed entry in the book.

Overrides:
getEntry in class RawBackend
Parameters:
name - name of the entry
testament - the testament for the entry
index - the entry to get
Returns:
the text for the entry.
Throws:
IOException - on a IO problem

setRawText

public void setRawText(Key key,
                       String text)
                throws BookException,
                       IOException
Description copied from class: AbstractBackend
Set the text allotted for the given verse

Overrides:
setRawText in class RawBackend
Parameters:
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.

setAliasKey

public void setAliasKey(Key alias,
                        Key source)
                 throws IOException
Description copied from class: AbstractBackend
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

Overrides:
setAliasKey in class RawBackend
Parameters:
alias - Alias Key
source - Source Key
Throws:
IOException - Exception when anything goes wrong on writing the alias

initIncFile

private void initIncFile()

createDataTextFile

private File createDataTextFile(int index)
                         throws BookException,
                                IOException
Throws:
BookException
IOException

getTextFilename

private String getTextFilename(RandomAccessFile txtRaf,
                               DataIndex dataIndex)
                        throws IOException
Gets the Filename for the File having the verse text.

Parameters:
txtRaf - The random access file containing the file names for the verse storage.
dataIndex - The index of where to get the data
Returns:
the file having the verse text.
Throws:
IOException

getDataTextFile

private File getDataTextFile(RandomAccessFile txtRaf,
                             DataIndex dataIndex)
                      throws IOException,
                             BookException
Gets the File having the verse text.

Parameters:
txtRaf - The random access file containing the file names for the verse storage.
dataIndex - The index of where to get the data
Returns:
the file having the verse text.
Throws:
IOException
BookException

updateIndexFile

protected void updateIndexFile(RandomAccessFile idxRaf,
                               long index,
                               long dataFileStartPosition)
                        throws IOException
Throws:
IOException

updateDataFile

protected void updateDataFile(long ordinal,
                              File txtFile)
                       throws IOException
Throws:
IOException

checkAndIncrementIncfile

private void checkAndIncrementIncfile(int index)
                               throws IOException
Throws:
IOException

create

public void create()
            throws IOException,
                   BookException
Description copied from class: AbstractBackend
Create the directory to hold the Book if it does not exist.

Overrides:
create in class AbstractBackend
Throws:
IOException
BookException

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 RawBackend
Returns:
true if the book is writable

createDataFiles

private void createDataFiles()
                      throws IOException,
                             BookException
Throws:
IOException
BookException

createIndexFiles

private void createIndexFiles()
                       throws IOException,
                              BookException
Throws:
IOException
BookException

prepopulateIndexFiles

private void prepopulateIndexFiles()
                            throws IOException
Throws:
IOException

createIncfile

private void createIncfile()
                    throws IOException,
                           BookException
Throws:
IOException
BookException

prepopulateIncfile

private void prepopulateIncfile()
                         throws IOException
Throws:
IOException

writeIncfile

private void writeIncfile(int value)
                   throws IOException
Throws:
IOException

readIncfile

private int readIncfile()
                 throws IOException
Throws:
IOException

writeInitialIndex

private void writeInitialIndex(BufferedOutputStream outStream)
                        throws IOException
Throws:
IOException

readTextDataFile

private byte[] readTextDataFile(File dataFile)
                         throws IOException
Throws:
IOException

writeTextDataFile

private void writeTextDataFile(File dataFile,
                               byte[] textData)
                        throws IOException
Throws:
IOException

littleEndian32BitByteArrayFromInt

private byte[] littleEndian32BitByteArrayFromInt(int val)

littleEndian16BitByteArrayFromShort

private byte[] littleEndian16BitByteArrayFromShort(short val)

Copyright ? 2003-2011