Class BinaryFunctions
java.lang.Object
org.apache.commons.imaging.common.BinaryFunctions
Convenience methods for various binary and I/O operations.
-
Field Summary
Fields -
Constructor Summary
Constructors -
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 void
static int
findNull
(byte[] src) static int
findNull
(byte[] src, int start) static byte[]
getRAFBytes
(RandomAccessFile raf, long pos, int length, String exception) static byte[]
static byte[]
head
(byte[] bytes, int count) static void
printByteBits
(String msg, byte i) static void
printCharQuad
(PrintWriter pw, String msg, int i) static void
printCharQuad
(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 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 exception) 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 void
skipBytes
(InputStream is, long length) static void
skipBytes
(InputStream is, long length, String exception) static byte[]
slice
(byte[] bytes, int start, int count) static boolean
startsWith
(byte[] haystack, byte[] needle) static boolean
startsWith
(byte[] haystack, BinaryConstant needle)
-
Field Details
-
LOGGER
-
-
Constructor Details
-
BinaryFunctions
private BinaryFunctions()
-
-
Method Details
-
startsWith
public static boolean startsWith(byte[] haystack, byte[] needle) -
startsWith
-
readByte
- Throws:
IOException
-
readBytes
- Throws:
IOException
-
readBytes
public static byte[] readBytes(String name, InputStream is, int length, String exception) throws IOException - Throws:
IOException
-
readBytes
- Throws:
IOException
-
readAndVerifyBytes
public static void readAndVerifyBytes(InputStream is, byte[] expected, String exception) throws ImageReadException, IOException - Throws:
ImageReadException
IOException
-
readAndVerifyBytes
public static void readAndVerifyBytes(InputStream is, BinaryConstant expected, String exception) throws ImageReadException, IOException - Throws:
ImageReadException
IOException
-
skipBytes
- Throws:
IOException
-
remainingBytes
-
slice
public static byte[] slice(byte[] bytes, int start, int count) -
head
public static byte[] head(byte[] bytes, int count) -
compareBytes
public static boolean compareBytes(byte[] a, int aStart, byte[] b, int bStart, int length) -
read4Bytes
public static int read4Bytes(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
-
read2Bytes
public static int read2Bytes(String name, InputStream is, String exception, ByteOrder byteOrder) throws IOException - Throws:
IOException
-
printCharQuad
-
printCharQuad
-
printByteBits
-
charsToQuad
public static int charsToQuad(char c1, char c2, char c3, char c4) -
quadsToByteArray
public static byte[] quadsToByteArray(int quad) Convert a quad into a byte array.- Parameters:
quad
- quad- Returns:
- a byte array
-
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
-
findNull
public static int findNull(byte[] src) -
findNull
public static int findNull(byte[] src, int start) -
getRAFBytes
public static byte[] getRAFBytes(RandomAccessFile raf, long pos, int length, String exception) throws IOException - Throws:
IOException
-
skipBytes
- Throws:
IOException
-
copyStreamToStream
- Throws:
IOException
-
getStreamBytes
- Throws:
IOException
-