Class Bytes

java.lang.Object
org.apache.jena.atlas.lib.Bytes

public class Bytes extends Object
Byte-oriented operations. Packing and unpacking integers is in network order (Big endian - which is the preferred order in Java). See wikipedia Endianness.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final byte[]
     
    static final byte[]
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    asHex(byte b)
    Return a hex string representing the byte.
    static String
    asHex(byte[] bytes)
    Return a hex string representing the bytes, zero padded to length of byte array.
    static String
    asHex(byte[] bytes, int start, int finish, char[] hexDigits)
     
    static String
    asHexLC(byte b)
     
    static String
    asHexLC(byte[] bytes)
     
    static String
    asHexUC(byte b)
     
    static String
    asHexUC(byte[] bytes)
     
    static byte[]
    String to UTF8 bytes
    static String
    bytes2string(byte[] x)
    Return the string for some UTF-8 bytes
    static int
    compare(byte[] x1, byte[] x2)
    Compare two byte arrays which may be of different lengths
    static int
    compareByte(byte b1, byte b2)
     
    static byte[]
    copyOf(byte[] bytes)
     
    static byte[]
    copyOf(byte[] bytes, int start)
     
    static byte[]
    copyOf(byte[] bytes, int start, int length)
     
    static String
    Decode a string into a ByteBuffer
    static String
    Decode a string into a ByteBuffer
    static String
    fromUTF8bytes(byte[] bytes)
    String from UTF8 bytes
    static final int
    getInt(byte[] b)
    Get an int from a byte array (network order)
    static final int
    getInt(byte[] b, int idx)
    Get an int from a byte array (network order)
    static final long
    getLong(byte[] b)
    Get a long from a byte array (network order)
    static final long
    getLong(byte[] b, int idx)
    Get a long from a byte array (network order)
    static int
    hexCharToInt(char c)
     
    static byte[]
    intToBytes(int v)
    Put an int value into an allocated byte array.
    static byte[]
    longToBytes(long v)
    Put a long value into an allocated byte array.
    static byte[]
    packInt(int val)
    int to byte array
    static byte[]
    packLong(long val)
    long to byte array
    static final void
    setInt(int value, byte[] b)
    Put an int into a byte array
    static final void
    setInt(int x, byte[] b, int idx)
    Put an int into a byte array from a given position
    static final void
    setLong(long value, byte[] b)
    Put a long into a byte array
    static final void
    setLong(long value, byte[] b, int idx)
    Put a long into a byte array from a given position
    static byte[]
    Return the UTF-8 bytes for a string
    static int
    Encode a string into a ByteBuffer : on return position is the end of the encoding
    static int
    Encode a string into a ByteBuffer : on return position is the end of the encoding

    Methods inherited from class java.lang.Object

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

    • hexDigitsUC

      public static final byte[] hexDigitsUC
    • hexDigitsLC

      public static final byte[] hexDigitsLC
  • Method Details

    • asUTF8bytes

      public static byte[] asUTF8bytes(String s)
      String to UTF8 bytes
    • fromUTF8bytes

      public static String fromUTF8bytes(byte[] bytes)
      String from UTF8 bytes
    • compare

      public static int compare(byte[] x1, byte[] x2)
      Compare two byte arrays which may be of different lengths
    • compareByte

      public static int compareByte(byte b1, byte b2)
    • copyOf

      public static byte[] copyOf(byte[] bytes)
    • copyOf

      public static byte[] copyOf(byte[] bytes, int start)
    • copyOf

      public static byte[] copyOf(byte[] bytes, int start, int length)
    • intToBytes

      public static byte[] intToBytes(int v)
      Put an int value into an allocated byte array.
      Parameters:
      v -
      Returns:
      byte[] array
      See Also:
    • longToBytes

      public static byte[] longToBytes(long v)
      Put a long value into an allocated byte array.
      Parameters:
      v -
      Returns:
      byte[] array
      See Also:
    • getInt

      public static final int getInt(byte[] b)
      Get an int from a byte array (network order)
      Parameters:
      b - Byte Array
    • getInt

      public static final int getInt(byte[] b, int idx)
      Get an int from a byte array (network order)
      Parameters:
      b - Byte Array
      idx - Starting point of bytes
    • getLong

      public static final long getLong(byte[] b)
      Get a long from a byte array (network order)
      Parameters:
      b - Byte Array
    • getLong

      public static final long getLong(byte[] b, int idx)
      Get a long from a byte array (network order)
      Parameters:
      b - Byte Array
      idx - Starting point of bytes
    • setInt

      public static final void setInt(int value, byte[] b)
      Put an int into a byte array
      Parameters:
      value - The integer
      b - byte array
    • setInt

      public static final void setInt(int x, byte[] b, int idx)
      Put an int into a byte array from a given position
      Parameters:
      x - The integer
      b - byte array
      idx - starting point
    • setLong

      public static final void setLong(long value, byte[] b)
      Put a long into a byte array
      Parameters:
      value - The integer
      b - byte array
    • setLong

      public static final void setLong(long value, byte[] b, int idx)
      Put a long into a byte array from a given position
      Parameters:
      value - The integer
      b - byte array
      idx - starting point
    • packInt

      public static byte[] packInt(int val)
      int to byte array
    • packLong

      public static byte[] packLong(long val)
      long to byte array
    • string2bytes

      public static byte[] string2bytes(String x)
      Return the UTF-8 bytes for a string
    • bytes2string

      public static String bytes2string(byte[] x)
      Return the string for some UTF-8 bytes
    • toByteBuffer

      public static int toByteBuffer(CharSequence s, ByteBuffer bb)
      Encode a string into a ByteBuffer : on return position is the end of the encoding
    • toByteBuffer

      public static int toByteBuffer(CharSequence s, ByteBuffer bb, CharsetEncoder enc)
      Encode a string into a ByteBuffer : on return position is the end of the encoding
    • fromByteBuffer

      public static String fromByteBuffer(ByteBuffer bb)
      Decode a string into a ByteBuffer
    • fromByteBuffer

      public static String fromByteBuffer(ByteBuffer bb, CharsetDecoder dec)
      Decode a string into a ByteBuffer
    • asHex

      public static String asHex(byte[] bytes)
      Return a hex string representing the bytes, zero padded to length of byte array.
    • asHexUC

      public static String asHexUC(byte[] bytes)
    • asHexLC

      public static String asHexLC(byte[] bytes)
    • asHex

      public static String asHex(byte[] bytes, int start, int finish, char[] hexDigits)
    • asHex

      public static String asHex(byte b)
      Return a hex string representing the byte.
    • asHexUC

      public static String asHexUC(byte b)
    • asHexLC

      public static String asHexLC(byte b)
    • hexCharToInt

      public static int hexCharToInt(char c)