java.lang.Object
com.adobe.internal.pdftoolkit.core.util.ByteOps

public final class ByteOps extends Object
This class provides many utility methods over bytes.
  • Method Summary

    Modifier and Type
    Method
    Description
    static final int
    copy(byte[] src, int srcOff, byte[] dst, int dstOff, int len)
    Copies source to destion array.
    static int
    endsWithPartial(byte[] src, int srcOff, byte[] suffix, int sufOff)
    Returns the index at which this suffix exists in the src array.
    static final int
    equalArrays(byte[] src, int srcOff, byte[] dst, int dstOff, int len)
    Checks the equality of two byte arrays.
    static byte
    getHex(byte b)
    Converts the specified hexidecimal character to a byte value.
    static byte[]
    getHex(byte[] src)
    Returns hex representation of src.
    static byte[]
    getHex(byte[] src, int size)
    Hex encodes the data in src to a new byte array that is of length size.
    static ASName
    getHexName(byte[] in)
    Converts the contents of a byte[] to a hex name (lowercase).
    static ASName
    getHexName(byte[] in, boolean uppercase)
    Converts the contents of a byte[] to a hex name.
    static String
    getHexString(byte[] in)
    Converts the contents of a byte[] to a hex string.
    static String
    getHexString(byte[] in, int size)
    Converts the contents of a byte[] to a hex string.
    static String
    getHexString2(byte[] in)
    Converts the contents of a byte[] to a hex string.
    static final byte
    Returns the numerical value for a byte that is used to represent a character.
    static String
    getUnicode(byte[] unicodeBytes)
    In presumption that the input byte array contains Unicode characters converts them to Java String.
    static boolean
    isASCII(byte[] bytes)
     
    static final boolean
    isDigit(byte b)
    Determines whether the specified byte represents a decimal digit.
    static final boolean
    isHexDigit(byte b)
    Determines whether the specified byte represents a hex digit.
    static final boolean
    Determines whether the specified byte represents a leading octal digit.
    static final boolean
    isLiteral(byte b)
    Determines whether the specified byte represents a literal PDF character.
    static final boolean
    isOctalDigit(byte b)
    Determines whether the specified byte represents an octal digit.
    static final boolean
    isRegular(byte b)
    Determines whether the specified byte represents a regular PDF character.
    static final boolean
    isWhitespace(byte b)
    Determines whether the specified byte represents a PDF whitespace character.
    static final boolean
    isWhitespace(char c)
    Determines whether the specified character represents a PDF whitespace character.
    static int
    readField(byte[] s, int pos)
    Reads two characters that are assumed to be digits and combines them into a decimal value.
    static final byte[]
    splitInt2Bytes(int src, int count)
    Converts the integer passed here to byte array.
    static final byte[]
    toByte(short word0)
     
    static final byte[]
    xorArray(byte[] array, byte with)
    Computes the XOR of the individual bytes of arrays passed here and returns it.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • isWhitespace

      public static final boolean isWhitespace(byte b)
      Determines whether the specified byte represents a PDF whitespace character. Whitespace characters are defined in section 3.1.1 of the PDF Reference Manual version 1.4.
      Parameters:
      b - Character to test
      Returns:
      true if the character is whitespace.
    • isWhitespace

      public static final boolean isWhitespace(char c)
      Determines whether the specified character represents a PDF whitespace character. Whitespace characters are defined in section 3.1.1 of the PDF Reference Manual version 1.4.
      Parameters:
      c - Character to test
      Returns:
      true if the character is whitespace.
    • isASCII

      public static boolean isASCII(byte[] bytes)
    • xorArray

      public static final byte[] xorArray(byte[] array, byte with)
      Computes the XOR of the individual bytes of arrays passed here and returns it.
    • endsWithPartial

      public static int endsWithPartial(byte[] src, int srcOff, byte[] suffix, int sufOff)
      Returns the index at which this suffix exists in the src array.
    • equalArrays

      public static final int equalArrays(byte[] src, int srcOff, byte[] dst, int dstOff, int len)
      Checks the equality of two byte arrays.
    • copy

      public static final int copy(byte[] src, int srcOff, byte[] dst, int dstOff, int len)
      Copies source to destion array.
    • splitInt2Bytes

      public static final byte[] splitInt2Bytes(int src, int count)
      Converts the integer passed here to byte array.
    • isRegular

      public static final boolean isRegular(byte b)
      Determines whether the specified byte represents a regular PDF character. Regular characters are defined in section 3.1.1 of the PDF Reference Manual version 1.4.
      Parameters:
      b - Character to test
      Returns:
      true if the character is regular.
    • isLiteral

      public static final boolean isLiteral(byte b)
      Determines whether the specified byte represents a literal PDF character. String literal characters are defined in section 3.2.3 of the PDF Reference Manual version 1.4.
      Parameters:
      b - Character to test
      Returns:
      true if the character is a literal.
    • isDigit

      public static final boolean isDigit(byte b)
      Determines whether the specified byte represents a decimal digit.
      Parameters:
      b - Character to test
      Returns:
      true if the character represents a decimal digit.
    • isHexDigit

      public static final boolean isHexDigit(byte b)
      Determines whether the specified byte represents a hex digit.
      Parameters:
      b - Character to test
      Returns:
      true if the character represents a hex digit.
    • isOctalDigit

      public static final boolean isOctalDigit(byte b)
      Determines whether the specified byte represents an octal digit.
      Parameters:
      b - Character to test
      Returns:
      true if the character represents an octal digit.
    • isLeadingOctalDigit

      public static final boolean isLeadingOctalDigit(byte b)
      Determines whether the specified byte represents a leading octal digit. A leading octal digit is one that leads a 3 digit octal sequence that will fit within a single byte. That means that the octal digit must be between 0 and 3 inclusive.
      Parameters:
      b - Character to test
      Returns:
      true if the character represents an octal digit.
    • getNumericalValue

      public static final byte getNumericalValue(byte b)
      Returns the numerical value for a byte that is used to represent a character. So, if a byte contains the value 0x30 (or the "character" '0') that would return a value of 0. This will work for decimal, octal, and hexadecimal values.
      Parameters:
      b - Character to test
      Returns:
      true if the character represents an octal digit.
    • readField

      public static int readField(byte[] s, int pos) throws PDFParseException
      Reads two characters that are assumed to be digits and combines them into a decimal value.
      Parameters:
      s - Byte array containing two characters to convert to a a numeric value
      pos - Position in the array where the characters start
      Returns:
      Value of the two characters combined and treated as decimal digits (e.g. "12" is returned as the value 12).
      Throws:
      PDFParseException - If two characters could not be read from the byte array or the characters did not correspond to decimal digits.
    • getHex

      public static byte[] getHex(byte[] src)
      Returns hex representation of src.
    • getHex

      public static byte[] getHex(byte[] src, int size)
      Hex encodes the data in src to a new byte array that is of length size. If the hex encoded data is less than size, then the buffer is padded with zeroes. The size parameter must be equal to or greater than 2 * src.length or an ArrayIndexOutOfBoundsException will occur. The size parameter should also be even since hex encoded data always has an even length.
    • getHexString

      public static String getHexString(byte[] in)
      Converts the contents of a byte[] to a hex string.
    • getHexName

      public static ASName getHexName(byte[] in) throws UnsupportedEncodingException
      Converts the contents of a byte[] to a hex name (lowercase).
      Parameters:
      in -
      Returns:
      ASName
      Throws:
      UnsupportedEncodingException
    • getHexName

      public static ASName getHexName(byte[] in, boolean uppercase)
      Converts the contents of a byte[] to a hex name.
      Parameters:
      in - the bytes used to make the hex name
      uppercase - true if the hex should utilize upper-case alpha characters; false if the alpha characters should be lower-case
      Returns:
      ASName
    • getHexString

      public static String getHexString(byte[] in, int size) throws UnsupportedEncodingException
      Converts the contents of a byte[] to a hex string. The size parameter must be equal to or greater than 2 * src.length or an ArrayIndexOutOfBoundsException will occur. The size parameter should also be even since hex encoded data always has an even length.
      Throws:
      UnsupportedEncodingException
    • getHexString2

      public static String getHexString2(byte[] in)
      Converts the contents of a byte[] to a hex string.
    • getHex

      public static byte getHex(byte b) throws PDFParseException
      Converts the specified hexidecimal character to a byte value. For example, the hex character 'A' is converted to the value 10.
      Parameters:
      b - Hex character to convert
      Returns:
      Byte value corresponding to the specified hex character.
      Throws:
      PDFParseException
    • getUnicode

      public static String getUnicode(byte[] unicodeBytes)
      In presumption that the input byte array contains Unicode characters converts them to Java String. If the input byte array is null, empty or contains non-Unicode characters returns null.
      Parameters:
      unicodeBytes -
      Returns:
      String representation of the Unicode characters in a byte array
    • toByte

      public static final byte[] toByte(short word0)