Package io.protostuff
Class LinkedBuffer
java.lang.Object
io.protostuff.LinkedBuffer
A buffer that wraps a byte array and has a reference to the next buffer for dynamic increase.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) final byte[]
static final int
The default buffer size for aLinkedBuffer
.static final int
The minimum buffer size for aLinkedBuffer
.(package private) LinkedBuffer
(package private) int
(package private) final int
-
Constructor Summary
ConstructorsConstructorDescriptionLinkedBuffer
(byte[] buffer, int offset) Uses the buffer starting at the specifiedoffset
LinkedBuffer
(byte[] buffer, int start, int offset) LinkedBuffer
(byte[] buffer, int start, int offset, LinkedBuffer appendTarget) LinkedBuffer
(byte[] buffer, int offset, LinkedBuffer appendTarget) Uses the buffer starting at the specifiedoffset
and appends to the provided bufferappendTarget
.LinkedBuffer
(int size) Creates a buffer with the specifiedsize
.LinkedBuffer
(int size, LinkedBuffer appendTarget) Creates a buffer with the specifiedsize
and appends to the provided bufferappendTarget
.LinkedBuffer
(LinkedBuffer viewSource, LinkedBuffer appendTarget) Creates a view from the bufferviewSource
and appends the view to the provided bufferappendTarget
. -
Method Summary
Modifier and TypeMethodDescriptionstatic LinkedBuffer
allocate()
Allocates a new buffer with default size.static LinkedBuffer
allocate
(int size) Allocates a new buffer with the specified size.static LinkedBuffer
allocate
(int size, LinkedBuffer previous) Allocates a new buffer with the specified size and appends it to the previous buffer.clear()
The offset will be reset to its starting position.static LinkedBuffer
use
(byte[] buffer) Uses the existing byte array as the internal buffer.static LinkedBuffer
use
(byte[] buffer, int start) Uses the existing byte array as the internal buffer.static LinkedBuffer
wrap
(byte[] array, int offset, int length) Wraps the byte array buffer as a read-only buffer.static int
writeTo
(DataOutput out, LinkedBuffer node) Writes the contents of theLinkedBuffer
into theDataOutput
.static int
writeTo
(OutputStream out, LinkedBuffer node) Writes the contents of theLinkedBuffer
into theOutputStream
.
-
Field Details
-
MIN_BUFFER_SIZE
public static final int MIN_BUFFER_SIZEThe minimum buffer size for aLinkedBuffer
.- See Also:
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZEThe default buffer size for aLinkedBuffer
.- See Also:
-
buffer
final byte[] buffer -
start
final int start -
offset
int offset -
next
LinkedBuffer next
-
-
Constructor Details
-
LinkedBuffer
LinkedBuffer(int size) Creates a buffer with the specifiedsize
. -
LinkedBuffer
LinkedBuffer(int size, LinkedBuffer appendTarget) Creates a buffer with the specifiedsize
and appends to the provided bufferappendTarget
. -
LinkedBuffer
LinkedBuffer(byte[] buffer, int offset) Uses the buffer starting at the specifiedoffset
-
LinkedBuffer
LinkedBuffer(byte[] buffer, int start, int offset) -
LinkedBuffer
LinkedBuffer(byte[] buffer, int offset, LinkedBuffer appendTarget) Uses the buffer starting at the specifiedoffset
and appends to the provided bufferappendTarget
. -
LinkedBuffer
LinkedBuffer(byte[] buffer, int start, int offset, LinkedBuffer appendTarget) -
LinkedBuffer
LinkedBuffer(LinkedBuffer viewSource, LinkedBuffer appendTarget) Creates a view from the bufferviewSource
and appends the view to the provided bufferappendTarget
.
-
-
Method Details
-
allocate
Allocates a new buffer with default size. -
allocate
Allocates a new buffer with the specified size. -
allocate
Allocates a new buffer with the specified size and appends it to the previous buffer. -
wrap
Wraps the byte array buffer as a read-only buffer. -
use
Uses the existing byte array as the internal buffer. -
use
Uses the existing byte array as the internal buffer. -
writeTo
Writes the contents of theLinkedBuffer
into theOutputStream
.- Returns:
- the total content size of the buffer.
- Throws:
IOException
-
writeTo
Writes the contents of theLinkedBuffer
into theDataOutput
.- Returns:
- the total content size of the buffer.
- Throws:
IOException
-
clear
The offset will be reset to its starting position. The buffer next to this will be dereferenced.
-