org.crosswire.jsword.book.sword
Class SwordUtil

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

public class SwordUtil
extends Object

Various utilities used by different Sword classes.

Distribution Licence:
JSword is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
The License is available on the internet here, or by writing to: Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
The copyright to this program is held by it's authors.

Version:
$Id: SwordUtil.java,v 1.16 2004/08/16 22:08:42 joe Exp $
Author:
Joe Walker [joe at eireneh dot com]
See Also:
Licence

Field Summary
private static Logger log
          The log stream
 
Constructor Summary
private SwordUtil()
          Prevent Instansiation
 
Method Summary
static String clean(Key key, String 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 long decodeLittleEndian32(byte[] data, int offset)
          Decode little endian data from a byte array
protected static int decodeLittleEndian32AsInt(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, long offset, int size)
          Read a RandomAccessFile
protected static int un2complement(byte data)
          Un 2-s complement a byte
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,
                                long offset,
                                int size)
                         throws IOException
Read a RandomAccessFile

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

decodeLittleEndian32

protected static long decodeLittleEndian32(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

decodeLittleEndian32AsInt

protected static int decodeLittleEndian32AsInt(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

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

un2complement

protected static int un2complement(byte data)
Un 2-s complement a byte


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

clean

public static String clean(Key key,
                           String data)
Remove rogue characters in the source. These are characters that are not valid in ISO-LATIN-1 (8859-1) and in UTF-8 or are non-printing control characters in the range of 0-32.


Copyright ? 2003-2004