Class BinaryFunctions
java.lang.Object
org.apache.commons.imaging.common.BinaryFunctions
Convenience methods for various binary and I/O operations.
-
Method Summary
Modifier and TypeMethodDescriptionstatic intcharsToQuad(char c1, char c2, char c3, char c4) static booleancompareBytes(byte[] a, int aStart, byte[] b, int bStart, int length) static intstatic intstatic byte[]getBytes(RandomAccessFile raf, long pos, int length, String exception) static byte[]head(byte[] bytes, int count) static voidlogByteBits(String msg, byte i) static voidlogCharQuad(String msg, int i) static voidprintCharQuad(PrintWriter pw, String msg, int i) static byte[]quadsToByteArray(int quad) Convert a quad into a byte array.static intread2Bytes(String name, InputStream is, String exception, ByteOrder byteOrder) static intread3Bytes(String name, InputStream is, String exception, ByteOrder byteOrder) static intread4Bytes(String name, InputStream is, String exception, ByteOrder byteOrder) static longread8Bytes(String name, InputStream is, String exception, ByteOrder byteOrder) Read eight bytes from the specified input stream, adjust for byte order, and return a long integer.static voidreadAndVerifyBytes(InputStream is, byte[] expected, String exception) static voidreadAndVerifyBytes(InputStream is, BinaryConstant expected, String exception) static bytereadByte(String name, InputStream is, String exceptionMessage) static byte[]readBytes(InputStream is, int count) static byte[]readBytes(String name, InputStream is, int length) static byte[]readBytes(String name, InputStream is, int length, String exception) static byte[]remainingBytes(String name, byte[] bytes, int count) static booleansearchQuad(int quad, InputStream bis) Consumes theInputStream(without closing it) searching for a quad.static longskipBytes(InputStream is, long length) static longskipBytes(InputStream is, long length, String exception) static byte[]slice(byte[] bytes, int start, int count) static booleanstartsWith(byte[] buffer, byte[] search) static booleanstartsWith(byte[] buffer, BinaryConstant search)
-
Method Details
-
charsToQuad
-
compareBytes
-
findNull
- Throws:
ImagingException
-
findNull
- Throws:
ImagingException
-
getBytes
public static byte[] getBytes(RandomAccessFile raf, long pos, int length, String exception) throws IOException - Throws:
IOException
-
head
-
logByteBits
-
logCharQuad
-
printCharQuad
-
quadsToByteArray
Convert a quad into a byte array.- Parameters:
quad- quad- Returns:
- a byte array
-
read2Bytes
public static int read2Bytes(String name, InputStream is, String exception, ByteOrder byteOrder) throws IOException - Throws:
IOException
-
read3Bytes
public static int read3Bytes(String name, InputStream is, String exception, ByteOrder byteOrder) throws IOException - Throws:
IOException
-
read4Bytes
public static int read4Bytes(String name, InputStream is, String exception, ByteOrder byteOrder) throws IOException - Throws:
IOException
-
read8Bytes
public static long read8Bytes(String name, InputStream is, String exception, ByteOrder byteOrder) throws IOException Read eight bytes from the specified input stream, adjust for byte order, and return a long integer.- Parameters:
name- a descriptive identifier used for diagnostic purposesis- a valid input streamexception- application-defined message to be used for constructing an exception if an error condition is triggered.byteOrder- the order in which the InputStream marshals data- Returns:
- a long integer interpreted from next 8 bytes in the InputStream
- Throws:
IOException- in the event of a non-recoverable error, such as an attempt to read past the end of file.
-
readAndVerifyBytes
public static void readAndVerifyBytes(InputStream is, BinaryConstant expected, String exception) throws ImagingException, IOException - Throws:
ImagingExceptionIOException
-
readAndVerifyBytes
public static void readAndVerifyBytes(InputStream is, byte[] expected, String exception) throws ImagingException, IOException - Throws:
ImagingExceptionIOException
-
readByte
public static byte readByte(String name, InputStream is, String exceptionMessage) throws IOException - Throws:
IOException
-
readBytes
- Throws:
IOException
-
readBytes
- Throws:
IOException
-
readBytes
public static byte[] readBytes(String name, InputStream is, int length, String exception) throws IOException - Throws:
IOException
-
remainingBytes
-
searchQuad
Consumes theInputStream(without closing it) searching for a quad. It will stop either when the quad is found, or when there are no more bytes in the input stream.Returns
trueif it found the quad, andfalseotherwise.- Parameters:
quad- a quad (the needle)bis- an input stream (the haystack)- Returns:
trueif it found the quad, andfalseotherwise- Throws:
IOException- if it fails to read from the given input stream
-
skipBytes
- Throws:
IOException
-
skipBytes
- Throws:
IOException
-
slice
-
startsWith
-
startsWith
-