Class Buffer

    • Constructor Summary

      Constructors 
      Constructor Description
      Buffer()
      Create a zero-count sequence.
      Buffer​(byte[] bytes)
      Create a Buffer using the byte array as the initial value.
      Buffer​(byte[] bytes, int offset, int length)
      Create a Buffer using the byte range as the initial value.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void append​(byte[] bytes)
      Append specified bytes to the buffer
      void append​(byte[] bytes, int offset, int length)
      Append specified bytes to the buffer.
      Object clone()  
      int compareTo​(Object other)
      Define the sort order of the Buffer.
      void copy​(byte[] bytes, int offset, int length)
      Copy the specified byte array to the Buffer.
      boolean equals​(Object other)  
      byte[] get()
      Get the data from the Buffer.
      int getCapacity()
      Get the capacity, which is the maximum count that could handled without resizing the backing storage.
      int getCount()
      Get the current count of the buffer.
      int hashCode()  
      void reset()
      Reset the buffer to 0 size
      void set​(byte[] bytes)
      Use the specified bytes array as underlying sequence.
      void setCapacity​(int newCapacity)
      Change the capacity of the backing storage.
      String toString()  
      String toString​(String charsetName)
      Convert the byte buffer to a string an specific character encoding
      void truncate()
      Change the capacity of the backing store to be the same as the current count of buffer.
    • Constructor Detail

      • Buffer

        public Buffer()
        Create a zero-count sequence.
      • Buffer

        public Buffer​(byte[] bytes)
        Create a Buffer using the byte array as the initial value.
        Parameters:
        bytes - This array becomes the backing storage for the object.
      • Buffer

        public Buffer​(byte[] bytes,
                      int offset,
                      int length)
        Create a Buffer using the byte range as the initial value.
        Parameters:
        bytes - Copy of this array becomes the backing storage for the object.
        offset - offset into byte array
        length - length of data
    • Method Detail

      • set

        public void set​(byte[] bytes)
        Use the specified bytes array as underlying sequence.
        Parameters:
        bytes - byte sequence
      • copy

        public final void copy​(byte[] bytes,
                               int offset,
                               int length)
        Copy the specified byte array to the Buffer. Replaces the current buffer.
        Parameters:
        bytes - byte array to be assigned
        offset - offset into byte array
        length - length of data
      • get

        public byte[] get()
        Get the data from the Buffer.
        Returns:
        The data is only valid between 0 and getCount() - 1.
      • getCount

        public int getCount()
        Get the current count of the buffer.
      • getCapacity

        public int getCapacity()
        Get the capacity, which is the maximum count that could handled without resizing the backing storage.
        Returns:
        The number of bytes
      • setCapacity

        public void setCapacity​(int newCapacity)
        Change the capacity of the backing storage. The data is preserved if newCapacity >= getCount().
        Parameters:
        newCapacity - The new capacity in bytes.
      • reset

        public void reset()
        Reset the buffer to 0 size
      • truncate

        public void truncate()
        Change the capacity of the backing store to be the same as the current count of buffer.
      • append

        public void append​(byte[] bytes,
                           int offset,
                           int length)
        Append specified bytes to the buffer.
        Parameters:
        bytes - byte array to be appended
        offset - offset into byte array
        length - length of data
      • append

        public void append​(byte[] bytes)
        Append specified bytes to the buffer
        Parameters:
        bytes - byte array to be appended
      • hashCode

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

        public int compareTo​(Object other)
        Define the sort order of the Buffer.
        Specified by:
        compareTo in interface Comparable
        Parameters:
        other - The other buffer
        Returns:
        Positive if this is bigger than other, 0 if they are equal, and negative if this is smaller than other.