Class ByteArray

  • All Implemented Interfaces:
    Serializable, Comparable<ByteArray>

    public class ByteArray
    extends Object
    implements Comparable<ByteArray>, Serializable
    Wrapper around byte[] that provides additional features such as:
    • Implements comparable interface, so comparison and sorting can be performed
    • Implements equals() and hashCode(), so it can be used as key for HashMap/Set
    • Caches the hash code of the byte[]
    See Also:
    Serialized Form
    • Constructor Detail

      • ByteArray

        public ByteArray​(byte[] bytes)
    • Method Detail

      • getBytes

        public byte[] getBytes()
      • length

        public int length()
      • toHexString

        public String toHexString()
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • compare

        public static int compare​(byte[] left,
                                  byte[] right)
        Compares two byte[] values. The comparison performed is on unsigned value for each byte. Returns:
        • 0 if both values are identical.
        • -ve integer if first value is smaller than the second.
        • +ve integer if first value is larger than the second.
        Parameters:
        left - First byte[] to compare.
        right - Second byte[] to compare.
        Returns:
        Result of comparison as stated above.
      • compare

        public static int compare​(byte[] left,
                                  int leftFromIndex,
                                  int leftToIndex,
                                  byte[] right,
                                  int rightFromIndex,
                                  int rightToIndex)
        Compares two byte[] values. The comparison performed is on unsigned value for each byte. Returns:
        • 0 if both values are identical.
        • -ve integer if first value is smaller than the second.
        • +ve integer if first value is larger than the second.
        Parameters:
        left - First byte[] to compare.
        leftFromIndex - inclusive index of first byte to compare in left
        leftToIndex - exclusive index of last byte to compare in left
        right - Second byte[] to compare.
        rightFromIndex - inclusive index of first byte to compare in right
        rightToIndex - exclusive index of last byte to compare in right
        Returns:
        Result of comparison as stated above.