Package net.targetr.wtm3.io
Class ReusableBuffer
java.lang.Object
net.targetr.wtm3.io.ReusableBuffer
A reusable buffer of bytes.
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new ReusableBuffer using the default transfer buffer size.ReusableBuffer(byte[] bytes) Constructs a new ReusableBuffer wrapping the given byte array.ReusableBuffer(byte[] data, int offset, int length) Constructs a new ReusableBuffer wrapping a segment of the given byte array. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]data()Returns the underlying byte array.voidinitSize(int length) Initializes the buffer to the given size if it is larger than the current size.intlength()Returns the length of the valid data in the buffer.intoffset()Returns the offset of the data within the underlying byte array.voidwriteTo(OutputStream out) Writes the logical contents of this buffer to an output stream.
-
Constructor Details
-
ReusableBuffer
public ReusableBuffer()Constructs a new ReusableBuffer using the default transfer buffer size. -
ReusableBuffer
public ReusableBuffer(byte[] bytes) Constructs a new ReusableBuffer wrapping the given byte array.- Parameters:
bytes- the byte array to wrap
-
ReusableBuffer
public ReusableBuffer(byte[] data, int offset, int length) Constructs a new ReusableBuffer wrapping a segment of the given byte array.- Parameters:
data- the byte arrayoffset- the start offset in the byte arraylength- the number of bytes to use
-
-
Method Details
-
initSize
public void initSize(int length) Initializes the buffer to the given size if it is larger than the current size.- Parameters:
length- the required minimum length
-
offset
public int offset()Returns the offset of the data within the underlying byte array.- Returns:
- the offset
-
length
public int length()Returns the length of the valid data in the buffer.- Returns:
- the length
-
data
public byte[] data()Returns the underlying byte array.- Returns:
- the raw data array
-
writeTo
Writes the logical contents of this buffer to an output stream.- Parameters:
out- the output stream to write to- Throws:
IOException- if an error occurs writing to the stream
-