Class Bytes


  • @Immutable
    public final class Bytes
    extends java.lang.Object
    Immutable Wrapper around a byte array.

    Wrap a bytearray so it prevents callers from modifying its contents. It does this by making a copy upon initialization, and also makes a copy if the underlying bytes are requested.

    Since:
    1.0.0
    • Method Detail

      • copyFrom

        public static Bytes copyFrom​(byte[] data)
        Parameters:
        data - the byte array to be wrapped.
        Returns:
        an immutable wrapper around the provided bytes.
      • copyFrom

        public static Bytes copyFrom​(byte[] data,
                                     int start,
                                     int len)
        Wrap an immutable byte array over a slice of a Bytes
        Parameters:
        data - the byte array to be wrapped.
        start - the starting index of the slice
        len - the length of the slice. If start + len is larger than the size of data, the remaining data will be returned.
        Returns:
        an immutable wrapper around the bytes in the slice from start to start + len
      • toByteArray

        public byte[] toByteArray()
        Returns:
        a copy of the bytes wrapped by this object.
      • size

        public int size()
        Returns:
        the length of the bytes wrapped by this object.
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object