org.apache.commons.imaging.common

## 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 and 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(InputStream is, OutputStream os)`
    `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[]` | `getStreamBytes(InputStream is)`
    `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, BinaryConstant expected, String exception)`
    `static void` | `readAndVerifyBytes(InputStream is, byte[] 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 the `InputStream` (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, BinaryConstant needle)`
    `static boolean` | `startsWith(byte[] haystack, byte[] needle)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 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:
        `ImageReadException`
        `IOException`

    - #### readAndVerifyBytes

          public static void readAndVerifyBytes(InputStream is,
                                                BinaryConstant expected,
                                                String exception)
                                         throws ImageReadException,
                                                IOException

      Throws:
        `ImageReadException`
        `IOException`

    - #### 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 IOException

      Consumes the `InputStream` (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, and `false` otherwise.

      Parameters:
        `quad` - a quad (the needle)
        `bis` - an input stream (the haystack)
      Returns:
        `true` if it found the quad, and `false` 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

          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`

Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.