org.crosswire.jsword.book.sword
Class SwordUtil

java.lang.Object
  extended by org.crosswire.jsword.book.sword.SwordUtil

public final class SwordUtil
extends Object

Various utilities used by different Sword classes.

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 static Logger log
          The log stream
 
Constructor Summary
private SwordUtil()
          Prevent Instansiation
 
Method Summary
static void clean1252(Key key, byte[] data)
          Remove rogue characters in the source.
static String decode(Key key, byte[] data, String charset)
          Transform a byte array into a string given the encoding.
protected static int decodeLittleEndian16(byte[] data, int offset)
          Decode little endian data from a byte array
protected static int decodeLittleEndian32(byte[] data, int offset)
          Decode little endian data from a byte array.
protected static int findByte(byte[] data, byte sought)
          Find a byte of data in an array
protected static byte[] readRAF(RandomAccessFile raf, int offset, int theSize)
          Read a RandomAccessFile
static byte[] uncompress(byte[] compressed, int endsize)
          Uncompress a block of GZIP compressed data
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static final Logger log
The log stream

Constructor Detail

SwordUtil

private SwordUtil()
Prevent Instansiation

Method Detail

readRAF

protected static byte[] readRAF(RandomAccessFile raf,
                                int offset,
                                int theSize)
                         throws IOException
Read a RandomAccessFile

Parameters:
raf - The file to read
offset - The record to read
theSize - The number of bytes to read
Returns:
the read data
Throws:
IOException

decodeLittleEndian32

protected static int decodeLittleEndian32(byte[] data,
                                          int offset)
Decode little endian data from a byte array. This assumes that the high order bit is not set as this is used solely for an offset in a file in bytes. For a practical limit, 2**31 is way bigger than any document that we can have.

Parameters:
data - the byte[] from which to read 4 bytes
offset - the offset into the array
Returns:
The decoded data

decodeLittleEndian16

protected static int decodeLittleEndian16(byte[] data,
                                          int offset)
Decode little endian data from a byte array

Parameters:
data - the byte[] from which to read 4 bytes
offset - the offset into the array
Returns:
The decoded data

findByte

protected static int findByte(byte[] data,
                              byte sought)
Find a byte of data in an array

Parameters:
data - The array to search
sought - The data to search for
Returns:
The index of the found position or -1 if not found

uncompress

public static byte[] uncompress(byte[] compressed,
                                int endsize)
                         throws DataFormatException,
                                BookException
Uncompress a block of GZIP compressed data

Parameters:
compressed - The data to uncompress
endsize - The expected resultant data size
Returns:
The uncompressed data
Throws:
DataFormatException
BookException

decode

public static String decode(Key key,
                            byte[] data,
                            String charset)
Transform a byte array into a string given the encoding. If the encoding is bad then it just does it as a string.

Parameters:
data - The byte array to be converted
charset - The encoding of the byte array
Returns:
a string that is UTF-8 internally

clean1252

public static void clean1252(Key key,
                             byte[] data)
Remove rogue characters in the source. These are characters that are not valid in cp1252 aka WINDOWS-1252 and in UTF-8 or are non-printing control characters in the range of 0-32.


Copyright ยจ 2003-2006