Class CmsByteBuffer

java.lang.Object
org.opencms.jlan.CmsByteBuffer

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

  • Constructor Summary

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

    Modifier and Type
    Method
    Description
    int
    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
    Returns the logical size of this buffer (which may be less than its capacity).
     
    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 Details

    • CmsByteBuffer

      public CmsByteBuffer()
      Creates a new instance.

    • CmsByteBuffer

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

      Parameters:
      capacity - the initial capacity
  • Method Details

    • 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 String toString()
      Overrides:
      toString in class Object
      See Also:
    • 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