Class CmsByteBuffer


  • public class CmsByteBuffer
    extends java.lang.Object
    Byte buffer class which expands dynamically if bytes are written to its end.

    • Constructor Summary

      Constructors 
      Constructor Description
      CmsByteBuffer()
      Creates a new instance.
      CmsByteBuffer​(int capacity)
      Creates a new instance with a given initial capacity.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getCapacity()
      Gets the current length of the internal byte buffer, which is the number of bytes this buffer can contain before a new buffer is allocated.
      void readBytes​(byte[] dest, int srcStart, int destStart, int len)
      Transfers bytes from this buffer to a target byte array.
      int size()
      Returns the logical size of this buffer (which may be less than its capacity).
      java.lang.String toString()  
      void truncate​(int size)
      Changes the logical size of this buffer.
      void writeBytes​(byte[] src, int srcStart, int destStart, int len)
      Writes some bytes to this buffer, expanding the buffer if necessary.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • CmsByteBuffer

        public CmsByteBuffer​(int capacity)
        Creates a new instance with a given initial capacity.

        Parameters:
        capacity - the initial capacity
    • Method Detail

      • getCapacity

        public int getCapacity()
        Gets the current length of the internal byte buffer, which is the number of bytes this buffer can contain before a new buffer is allocated.

        Returns:
        the current length of the internal buffer
      • readBytes

        public void readBytes​(byte[] dest,
                              int srcStart,
                              int destStart,
                              int len)
        Transfers bytes from this buffer to a target byte array.

        Parameters:
        dest - the byte array to which the bytes should be transferred
        srcStart - the start index in this buffer
        destStart - the start index in the destination buffer
        len - the number of bytes to transfer
      • size

        public int size()
        Returns the logical size of this buffer (which may be less than its capacity).

        Returns:
        the buffer size
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
        See Also:
        Object.toString()
      • truncate

        public void truncate​(int size)
        Changes the logical size of this buffer.

        If the size is larger than the current size, the new space will be filled with 0s. Note that the internal byte buffer will not be shrunk if the size is smaller than the current size.

        Parameters:
        size - the new size
      • writeBytes

        public void writeBytes​(byte[] src,
                               int srcStart,
                               int destStart,
                               int len)
        Writes some bytes to this buffer, expanding the buffer if necessary.

        Parameters:
        src - the source from which to write the bytes
        srcStart - the start index in the source array
        destStart - the start index in this buffer
        len - the number of bytes to write