Class BinaryFunctions
- java.lang.Object
-
- org.apache.commons.imaging.common.BinaryFunctions
-
public final class BinaryFunctions extends java.lang.Object
Convenience methods for various binary and I/O operations.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.logging.Logger
LOGGER
-
Constructor Summary
Constructors Modifier Constructor Description private
BinaryFunctions()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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
copyStreamToStream(java.io.InputStream is, java.io.OutputStream os)
static int
findNull(byte[] src)
static int
findNull(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 void
printByteBits(java.lang.String msg, byte i)
static void
printCharQuad(java.io.PrintWriter pw, java.lang.String msg, int i)
static void
printCharQuad(java.lang.String msg, int i)
static byte[]
quadsToByteArray(int quad)
Convert a quad into a byte array.static int
read2Bytes(java.lang.String name, java.io.InputStream is, java.lang.String exception, java.nio.ByteOrder byteOrder)
static int
read3Bytes(java.lang.String name, java.io.InputStream is, java.lang.String exception, java.nio.ByteOrder byteOrder)
static int
read4Bytes(java.lang.String name, java.io.InputStream is, java.lang.String exception, java.nio.ByteOrder byteOrder)
static void
readAndVerifyBytes(java.io.InputStream is, byte[] expected, java.lang.String exception)
static void
readAndVerifyBytes(java.io.InputStream is, BinaryConstant expected, java.lang.String exception)
static byte
readByte(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 boolean
searchQuad(int quad, java.io.InputStream bis)
Consumes theInputStream
(without closing it) searching for a quad.static void
skipBytes(java.io.InputStream is, long length)
static void
skipBytes(java.io.InputStream is, long length, java.lang.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)
-
-
-
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:
ImageReadException
java.io.IOException
-
readAndVerifyBytes
public static void readAndVerifyBytes(java.io.InputStream is, BinaryConstant expected, java.lang.String exception) throws ImageReadException, java.io.IOException
- Throws:
ImageReadException
java.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.IOException
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:
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
-
-