Module de.carne
Package de.carne.util

Class ByteString

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<ByteString>

    public final class ByteString
    extends java.lang.Object
    implements java.io.Serializable, java.lang.Comparable<ByteString>
    Immutable byte string support.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static ByteString EMPTY
      The empty byte string.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      byte byteAt​(int index)
      Gets the this instance's byte value at the given index.
      byte[] bytes()
      Gets a copy of this instance's byte values.
      int compareTo​(ByteString o)  
      static ByteString copy​(byte... bytes)
      Constructs a new ByteString instance by copying the submitted bytes.
      static ByteString copy​(byte[] bytes, int start, int length)
      Constructs a new ByteString instance by copying the submitted bytes.
      void copyTo​(byte[] dest, int destPos)
      Copies this instances bytes to a destination buffer.
      boolean equals​(@Nullable java.lang.Object obj)  
      int hashCode()  
      int length()
      Gets the length of this instance.
      ByteString slice​(int sliceStart, int sliceLength)
      Slices a sub-section from this instance.
      java.lang.String toString()  
      static ByteString wrap​(byte... bytes)
      Constructs a new ByteString instance by wrapping the submitted bytes directly.
      static ByteString wrap​(byte[] bytes, int start, int length)
      Constructs a new ByteString instance by wrapping the submitted bytes directly.
      void write​(java.io.OutputStream out)
      Copies this instances bytes to the given OutputStream.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • EMPTY

        public static final ByteString EMPTY
        The empty byte string.
    • Method Detail

      • wrap

        public static ByteString wrap​(byte... bytes)
        Constructs a new ByteString instance by wrapping the submitted bytes directly.
        Parameters:
        bytes - the bytes to wrap.
        Returns:
        the constructed ByteString instance.
      • wrap

        public static ByteString wrap​(byte[] bytes,
                                      int start,
                                      int length)
        Constructs a new ByteString instance by wrapping the submitted bytes directly.
        Parameters:
        bytes - the bytes to wrap.
        start - the index of the first byte to wrap.
        length - the number of bytes to wrap.
        Returns:
        the constructed ByteString instance.
      • copy

        public static ByteString copy​(byte... bytes)
        Constructs a new ByteString instance by copying the submitted bytes.
        Parameters:
        bytes - the bytes to copy.
        Returns:
        the constructed ByteString instance.
      • copy

        public static ByteString copy​(byte[] bytes,
                                      int start,
                                      int length)
        Constructs a new ByteString instance by copying the submitted bytes.
        Parameters:
        bytes - the bytes to copy.
        start - the index of the first byte to copy.
        length - the number of bytes to copy.
        Returns:
        the constructed ByteString instance.
      • length

        public int length()
        Gets the length of this instance.
        Returns:
        the length of this instance.
      • bytes

        public byte[] bytes()
        Gets a copy of this instance's byte values.
        Returns:
        a copy of this instance's byte values.
      • byteAt

        public byte byteAt​(int index)
        Gets the this instance's byte value at the given index.
        Parameters:
        index - the index of the byte to get.
        Returns:
        the byte value at the given index.
      • copyTo

        public void copyTo​(byte[] dest,
                           int destPos)
        Copies this instances bytes to a destination buffer.
        Parameters:
        dest - the buffer to copy into.
        destPos - the buffer position to start copying at.
      • write

        public void write​(java.io.OutputStream out)
                   throws java.io.IOException
        Copies this instances bytes to the given OutputStream.
        Parameters:
        out - the OutputStream to write to.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • slice

        public ByteString slice​(int sliceStart,
                                int sliceLength)
        Slices a sub-section from this instance.
        Parameters:
        sliceStart - the index of the first byte to slice.
        sliceLength - the number of bytes to slice.
        Returns:
        the sliced byte string.
      • compareTo

        public int compareTo​(ByteString o)
        Specified by:
        compareTo in interface java.lang.Comparable<ByteString>
      • hashCode

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

        public boolean equals​(@Nullable java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • toString

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