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 intcharsToQuad(char c1, char c2, char c3, char c4) static booleancompareBytes(byte[] a, int aStart, byte[] b, int bStart, int length) static voidstatic intfindNull(byte[] src) static intfindNull(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 voidprintByteBits(String msg, byte i) static voidprintCharQuad(PrintWriter pw, String msg, int i) static voidprintCharQuad(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 voidreadAndVerifyBytes(InputStream is, byte[] expected, String exception) static voidreadAndVerifyBytes(InputStream is, BinaryConstant expected, String exception) static bytereadByte(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 booleansearchQuad(int quad, InputStream bis) Consumes theInputStream(without closing it) searching for a quad.static voidskipBytes(InputStream is, long length) static voidskipBytes(InputStream is, long length, String exception) static byte[]slice(byte[] bytes, int start, int count) static booleanstartsWith(byte[] haystack, byte[] needle) static booleanstartsWith(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:
ImageReadExceptionIOException
-
readAndVerifyBytes
public static void readAndVerifyBytes(InputStream is, BinaryConstant expected, String exception) throws ImageReadException, IOException - Throws:
ImageReadExceptionIOException
-
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
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
-
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
-