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 int
charsToQuad
(char c1, char c2, char c3, char c4) static boolean
compareBytes
(byte[] a, int aStart, byte[] b, int bStart, int length) static int
static int
static byte[]
getBytes
(RandomAccessFile raf, long pos, int length, String exception) static byte[]
head
(byte[] bytes, int count) static void
logByteBits
(String msg, byte i) static void
logCharQuad
(String msg, int i) static void
printCharQuad
(PrintWriter pw, String msg, int i) static byte[]
quadsToByteArray
(int quad) Convert a quad into a byte array.static int
read2Bytes
(String name, InputStream is, String exception, ByteOrder byteOrder) static int
read3Bytes
(String name, InputStream is, String exception, ByteOrder byteOrder) static int
read4Bytes
(String name, InputStream is, String exception, ByteOrder byteOrder) static long
read8Bytes
(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 void
readAndVerifyBytes
(InputStream is, byte[] expected, String exception) static void
readAndVerifyBytes
(InputStream is, BinaryConstant expected, String exception) static byte
readByte
(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 boolean
searchQuad
(int quad, InputStream bis) Consumes theInputStream
(without closing it) searching for a quad.static long
skipBytes
(InputStream is, long length) static long
skipBytes
(InputStream is, long length, String exception) static byte[]
slice
(byte[] bytes, int start, int count) static boolean
startsWith
(byte[] buffer, byte[] search) static boolean
startsWith
(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:
ImagingException
IOException
-
readAndVerifyBytes
public static void readAndVerifyBytes(InputStream is, byte[] expected, String exception) throws ImagingException, IOException - Throws:
ImagingException
IOException
-
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
true
if it found the quad, andfalse
otherwise.- Parameters:
quad
- a quad (the needle)bis
- an input stream (the haystack)- Returns:
true
if it found the quad, andfalse
otherwise- Throws:
IOException
- if it fails to read from the given input stream
-
skipBytes
- Throws:
IOException
-
skipBytes
- Throws:
IOException
-
slice
-
startsWith
-
startsWith
-