Package org.opencms.jlan
Class CmsByteBuffer
java.lang.Object
org.opencms.jlan.CmsByteBuffer
Byte buffer class which expands dynamically if bytes are written to its end.
-
Constructor Summary
ConstructorDescriptionCreates a new instance.CmsByteBuffer
(int capacity) Creates a new instance with a given initial capacity. -
Method Summary
Modifier and TypeMethodDescriptionint
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).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.
-
Constructor Details
-
CmsByteBuffer
public CmsByteBuffer()Creates a new instance. -
CmsByteBuffer
Creates a new instance with a given initial capacity.- Parameters:
capacity
- the initial capacity
-
-
Method Details
-
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
Transfers bytes from this buffer to a target byte array.- Parameters:
dest
- the byte array to which the bytes should be transferredsrcStart
- the start index in this bufferdestStart
- the start index in the destination bufferlen
- the number of bytes to transfer
-
size
Returns the logical size of this buffer (which may be less than its capacity).- Returns:
- the buffer size
-
toString
-
truncate
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
Writes some bytes to this buffer, expanding the buffer if necessary.- Parameters:
src
- the source from which to write the bytessrcStart
- the start index in the source arraydestStart
- the start index in this bufferlen
- the number of bytes to write
-