public final class SwordUtil extends Object
The GNU Lesser General Public License for details.
Modifier and Type | Field and Description |
---|---|
private static org.slf4j.Logger |
log
The log stream
|
Modifier | Constructor and Description |
---|---|
private |
SwordUtil()
Prevent instantiation
|
Modifier and Type | Method and Description |
---|---|
private static void |
clean1252(String key,
byte[] data,
int offset,
int length)
Remove rogue characters in the source.
|
static String |
decode(String key,
byte[] data,
int offset,
int length,
String charset)
Transform a portion of a byte array starting at an offset into a string
given the encoding.
|
static String |
decode(String key,
byte[] data,
int length,
String charset)
Transform a portion of a byte array into a string given the encoding.
|
static String |
decode(String 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
|
static int |
decodeLittleEndian32(byte[] data,
int offset)
Decode little endian data from a byte array.
|
protected static void |
encodeLittleEndian16(int val,
byte[] data,
int offset)
Encode a 16-bit little endian from an integer.
|
protected static void |
encodeLittleEndian32(int val,
byte[] data,
int offset)
Encode 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 int |
findByte(byte[] data,
int offset,
byte sought)
Find a byte of data in an array
|
static URI |
getExpandedDataPath(BookMetaData bookMetaData)
Returns where the book should be located
|
protected static byte[] |
readNextRAF(RandomAccessFile raf,
int theSize)
Read a RandomAccessFile from the current location in the file.
|
protected static byte[] |
readRAF(RandomAccessFile raf,
long offset,
int theSize)
Read a RandomAccessFile
|
protected static byte[] |
readUntilRAF(RandomAccessFile raf,
byte stopByte)
Read a RandomAccessFile until a particular byte is seen
|
protected static byte[] |
readUntilRAF(RandomAccessFile raf,
int offset,
byte stopByte)
Read a RandomAccessFile until a particular byte is seen
|
protected static void |
writeNextRAF(RandomAccessFile raf,
byte[] data) |
protected static void |
writeRAF(RandomAccessFile raf,
long offset,
byte[] data)
Writes "data" to a RandomAccessFile at the "offset" position
|
protected static byte[] readRAF(RandomAccessFile raf, long offset, int theSize) throws IOException
raf
- The file to readoffset
- The start of the record to readtheSize
- The number of bytes to readIOException
- on errorprotected static byte[] readNextRAF(RandomAccessFile raf, int theSize) throws IOException
raf
- The file to readtheSize
- The number of bytes to readIOException
- on errorprotected static void writeRAF(RandomAccessFile raf, long offset, byte[] data) throws IOException
raf
- RandomAccessFileoffset
- offset to write atdata
- data to writeIOException
- on errorprotected static void writeNextRAF(RandomAccessFile raf, byte[] data) throws IOException
IOException
protected static byte[] readUntilRAF(RandomAccessFile raf, int offset, byte stopByte) throws IOException
raf
- The file to readoffset
- The start of the record to readstopByte
- The point at which to stop readingIOException
- on errorprotected static byte[] readUntilRAF(RandomAccessFile raf, byte stopByte) throws IOException
raf
- The file to readstopByte
- The point at which to stop readingIOException
- on errorpublic static int decodeLittleEndian32(byte[] data, int offset)
data
- the byte[] from which to read 4 bytesoffset
- the offset into the arrayprotected static void encodeLittleEndian32(int val, byte[] data, int offset)
val
- the number to encode into little endiandata
- the byte[] from which to write 4 bytesoffset
- the offset into the arrayprotected static int decodeLittleEndian16(byte[] data, int offset)
data
- the byte[] from which to read 2 bytesoffset
- the offset into the arrayprotected static void encodeLittleEndian16(int val, byte[] data, int offset)
data
- the byte[] from which to write 2 bytesoffset
- the offset into the arrayprotected static int findByte(byte[] data, byte sought)
data
- The array to searchsought
- The data to search forprotected static int findByte(byte[] data, int offset, byte sought)
data
- The array to searchoffset
- The position in the array to begin lookingsought
- The data to search forpublic static String decode(String key, byte[] data, String charset)
key
- the keydata
- The byte array to be convertedcharset
- The encoding of the byte arraypublic static String decode(String key, byte[] data, int length, String charset)
key
- the keydata
- The byte array to be convertedlength
- The number of bytes to use.charset
- The encoding of the byte arraypublic static String decode(String key, byte[] data, int offset, int length, String charset)
key
- the keydata
- The byte array to be convertedoffset
- The starting position in the byte arraylength
- The number of bytes to use.charset
- The encoding of the byte arrayprivate static void clean1252(String key, byte[] data, int offset, int length)
public static URI getExpandedDataPath(BookMetaData bookMetaData) throws BookException
bookMetaData
- meta information about the bookBookException
- thrown if an issue is encountered, e.g. missing data files.