Class BinaryFunctions
- java.lang.Object
-
- org.apache.commons.imaging.common.BinaryFunctions
-
public final class BinaryFunctions extends Object
Convenience methods for various binary and I/O operations.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intcharsToQuad(char c1, char c2, char c3, char c4)static booleancompareBytes(byte[] a, int aStart, byte[] b, int bStart, int length)static voidcopyStreamToStream(InputStream is, OutputStream os)static intfindNull(byte[] src)static intfindNull(byte[] src, int start)static byte[]getRAFBytes(RandomAccessFile raf, long pos, int length, String exception)static byte[]getStreamBytes(InputStream is)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)
-
-
-
Method Detail
-
startsWith
public static boolean startsWith(byte[] haystack, byte[] needle)
-
startsWith
public static boolean startsWith(byte[] haystack, BinaryConstant needle)
-
readByte
public static byte readByte(String name, InputStream is, String exception) throws IOException
- Throws:
IOException
-
readBytes
public static byte[] readBytes(String name, InputStream is, int length) throws IOException
- Throws:
IOException
-
readBytes
public static byte[] readBytes(String name, InputStream is, int length, String exception) throws IOException
- Throws:
IOException
-
readBytes
public static byte[] readBytes(InputStream is, int count) throws IOException
- 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
public static void skipBytes(InputStream is, long length, String exception) throws IOException
- Throws:
IOException
-
remainingBytes
public static byte[] remainingBytes(String name, byte[] bytes, int count)
-
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
public static void printCharQuad(String msg, int i)
-
printCharQuad
public static void printCharQuad(PrintWriter pw, String msg, int i)
-
printByteBits
public static void printByteBits(String msg, byte i)
-
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
public static boolean searchQuad(int quad, InputStream bis) throws IOExceptionConsumes 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
-
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
public static void skipBytes(InputStream is, long length) throws IOException
- Throws:
IOException
-
copyStreamToStream
public static void copyStreamToStream(InputStream is, OutputStream os) throws IOException
- Throws:
IOException
-
getStreamBytes
public static byte[] getStreamBytes(InputStream is) throws IOException
- Throws:
IOException
-
-