public class MARSBuffer extends Object
MARSEvent
events.
The buffer is built atop character array which is used both for reading and writing. Partial reads and writes are
supported with state stored in the buffer between operations. All operations are not thread-safe, it is assumed that
each thread and/or data stream will use it's own instance of the buffer or provide thread-safety by other means.Constructor and Description |
---|
MARSBuffer() |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clears buffer by setting it's size to 0.
|
void |
ensureCapacity(int required_capacity)
Reallocates buffer to ensure that it has required total capacity.
|
char[] |
getBuffer()
Returns character array currently used by this buffer or null if none is allocated yet.
|
int |
getSize()
Returns number of payload characters in the buffer.
|
Collection<MARSEvent> |
readEvents()
Reads and removes all complete
MARSEvent events from the buffer. |
void |
removeChars(int n)
Removes first
n characters from the buffer. |
void |
setSize(int size)
Sets new number of payload characters in the buffer.
|
void |
writeChars(char[] chars,
int offset,
int length)
Writes specified characters to the end of the buffer.
|
void |
writeEvents(Collection<MARSEvent> events)
Writes specified
MARSEvent events to the end of the buffer. |
void |
writeString(String s)
Writes specified string to the end of the buffer.
|
public char[] getBuffer()
public int getSize()
public void setSize(int size)
IllegalArgumentException
- if specified size is outside of current buffer length.public void ensureCapacity(int required_capacity)
public void clear()
public void removeChars(int n)
n
characters from the buffer.IndexOutOfBoundsException
- if specified number is outside current size.public void writeString(String s)
public void writeChars(char[] chars, int offset, int length)
public Collection<MARSEvent> readEvents()
MARSEvent
events from the buffer.public void writeEvents(Collection<MARSEvent> events)
MARSEvent
events to the end of the buffer.Copyright © 2014 Devexperts. All Rights Reserved.