Class BinaryFunctions
- java.lang.Object
-
- org.apache.commons.imaging.common.BinaryFunctions
-
public final class BinaryFunctions extends java.lang.ObjectConvenience methods for various binary and I/O operations.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.logging.LoggerLOGGER
-
Constructor Summary
Constructors Modifier Constructor Description privateBinaryFunctions()
-
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(java.io.InputStream is, java.io.OutputStream os)static intfindNull(byte[] src)static intfindNull(byte[] src, int start)static byte[]getRAFBytes(java.io.RandomAccessFile raf, long pos, int length, java.lang.String exception)static byte[]getStreamBytes(java.io.InputStream is)static byte[]head(byte[] bytes, int count)static voidprintByteBits(java.lang.String msg, byte i)static voidprintCharQuad(java.io.PrintWriter pw, java.lang.String msg, int i)static voidprintCharQuad(java.lang.String msg, int i)static byte[]quadsToByteArray(int quad)Convert a quad into a byte array.static intread2Bytes(java.lang.String name, java.io.InputStream is, java.lang.String exception, java.nio.ByteOrder byteOrder)static intread3Bytes(java.lang.String name, java.io.InputStream is, java.lang.String exception, java.nio.ByteOrder byteOrder)static intread4Bytes(java.lang.String name, java.io.InputStream is, java.lang.String exception, java.nio.ByteOrder byteOrder)static voidreadAndVerifyBytes(java.io.InputStream is, byte[] expected, java.lang.String exception)static voidreadAndVerifyBytes(java.io.InputStream is, BinaryConstant expected, java.lang.String exception)static bytereadByte(java.lang.String name, java.io.InputStream is, java.lang.String exception)static byte[]readBytes(java.io.InputStream is, int count)static byte[]readBytes(java.lang.String name, java.io.InputStream is, int length)static byte[]readBytes(java.lang.String name, java.io.InputStream is, int length, java.lang.String exception)static byte[]remainingBytes(java.lang.String name, byte[] bytes, int count)static booleansearchQuad(int quad, java.io.InputStream bis)Consumes theInputStream(without closing it) searching for a quad.static voidskipBytes(java.io.InputStream is, long length)static voidskipBytes(java.io.InputStream is, long length, java.lang.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(java.lang.String name, java.io.InputStream is, java.lang.String exception) throws java.io.IOException- Throws:
java.io.IOException
-
readBytes
public static byte[] readBytes(java.lang.String name, java.io.InputStream is, int length) throws java.io.IOException- Throws:
java.io.IOException
-
readBytes
public static byte[] readBytes(java.lang.String name, java.io.InputStream is, int length, java.lang.String exception) throws java.io.IOException- Throws:
java.io.IOException
-
readBytes
public static byte[] readBytes(java.io.InputStream is, int count) throws java.io.IOException- Throws:
java.io.IOException
-
readAndVerifyBytes
public static void readAndVerifyBytes(java.io.InputStream is, byte[] expected, java.lang.String exception) throws ImageReadException, java.io.IOException- Throws:
ImageReadExceptionjava.io.IOException
-
readAndVerifyBytes
public static void readAndVerifyBytes(java.io.InputStream is, BinaryConstant expected, java.lang.String exception) throws ImageReadException, java.io.IOException- Throws:
ImageReadExceptionjava.io.IOException
-
skipBytes
public static void skipBytes(java.io.InputStream is, long length, java.lang.String exception) throws java.io.IOException- Throws:
java.io.IOException
-
remainingBytes
public static byte[] remainingBytes(java.lang.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(java.lang.String name, java.io.InputStream is, java.lang.String exception, java.nio.ByteOrder byteOrder) throws java.io.IOException- Throws:
java.io.IOException
-
read3Bytes
public static int read3Bytes(java.lang.String name, java.io.InputStream is, java.lang.String exception, java.nio.ByteOrder byteOrder) throws java.io.IOException- Throws:
java.io.IOException
-
read2Bytes
public static int read2Bytes(java.lang.String name, java.io.InputStream is, java.lang.String exception, java.nio.ByteOrder byteOrder) throws java.io.IOException- Throws:
java.io.IOException
-
printCharQuad
public static void printCharQuad(java.lang.String msg, int i)
-
printCharQuad
public static void printCharQuad(java.io.PrintWriter pw, java.lang.String msg, int i)
-
printByteBits
public static void printByteBits(java.lang.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, java.io.InputStream bis) throws java.io.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:
java.io.IOException
-
findNull
public static int findNull(byte[] src)
-
findNull
public static int findNull(byte[] src, int start)
-
getRAFBytes
public static byte[] getRAFBytes(java.io.RandomAccessFile raf, long pos, int length, java.lang.String exception) throws java.io.IOException- Throws:
java.io.IOException
-
skipBytes
public static void skipBytes(java.io.InputStream is, long length) throws java.io.IOException- Throws:
java.io.IOException
-
copyStreamToStream
public static void copyStreamToStream(java.io.InputStream is, java.io.OutputStream os) throws java.io.IOException- Throws:
java.io.IOException
-
getStreamBytes
public static byte[] getStreamBytes(java.io.InputStream is) throws java.io.IOException- Throws:
java.io.IOException
-
-