|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Byte Buffer interface. This is a byte buffer that is designed to work like a FIFO for bytes. Puts and Gets operate on different pointers into the buffer and the valid _content of the buffer is always between the getIndex and the putIndex. This buffer interface is designed to be similar, but not dependant on the java.nio buffers, which may be used to back an implementation of this Buffer. The main difference is that NIO buffer after a put have their valid _content before the position and a flip is required to access that data. For this buffer it is always true that: markValue <= getIndex <= putIndex <= capacity
Nested Class Summary | |
static interface |
Buffer.CaseInsensitve
|
Field Summary | |
static int |
IMMUTABLE
|
static boolean |
NON_VOLATILE
|
static int |
READONLY
|
static int |
READWRITE
|
static boolean |
VOLATILE
|
Method Summary | |
byte[] |
array()
Get the underlying array, if one exists. |
byte[] |
asArray()
|
Buffer |
asImmutableBuffer()
|
Buffer |
asMutableBuffer()
|
Buffer |
asNonVolatileBuffer()
|
Buffer |
asReadOnlyBuffer()
|
Buffer |
buffer()
Get the unerlying buffer. |
int |
capacity()
The capacity of the buffer. |
void |
clear()
Clear the buffer. |
void |
compact()
Compact the buffer by discarding bytes before the postion (or mark if set). |
boolean |
equalsIgnoreCase(Buffer buffer)
|
byte |
get()
Get the byte at the current getIndex and increment it. |
int |
get(byte[] b,
int offset,
int length)
Get bytes from the current postion and put them into the passed byte array. |
Buffer |
get(int length)
|
int |
getIndex()
The index within the buffer that will next be read or written. |
boolean |
hasContent()
|
boolean |
isImmutable()
|
boolean |
isReadOnly()
|
boolean |
isVolatile()
|
int |
length()
The number of bytes from the getIndex to the putIndex |
void |
mark()
Set the mark to the current getIndex. |
void |
mark(int offset)
Set the mark relative to the current getIndex |
int |
markIndex()
The current index of the mark. |
byte |
peek()
Get the byte at the current getIndex without incrementing the getIndex. |
byte |
peek(int index)
Get the byte at a specific index in the buffer. |
int |
peek(int index,
byte[] b,
int offset,
int length)
|
Buffer |
peek(int index,
int length)
|
int |
poke(int index,
Buffer src)
Put the contents of the buffer at the specific index. |
void |
poke(int index,
byte b)
Put a specific byte to a specific getIndex. |
int |
poke(int index,
byte[] b,
int offset,
int length)
Put a specific byte to a specific getIndex. |
int |
put(Buffer src)
Write the bytes from the source buffer to the current getIndex. |
void |
put(byte b)
Put a byte to the current getIndex and increment the getIndex. |
int |
put(byte[] b)
Put a byte to the current getIndex and increment the getIndex. |
int |
put(byte[] b,
int offset,
int length)
Put a byte to the current getIndex and increment the getIndex. |
int |
putIndex()
The index of the first element that should not be read. |
int |
readFrom(InputStream in,
int max)
Read the buffer's contents from the input stream |
void |
reset()
Reset the current getIndex to the mark |
void |
setGetIndex(int newStart)
Set the buffers start getIndex. |
void |
setMarkIndex(int newMark)
Set a specific value for the mark. |
void |
setPutIndex(int newLimit)
|
int |
skip(int n)
Skip _content. |
Buffer |
slice()
|
Buffer |
sliceFromMark()
|
Buffer |
sliceFromMark(int length)
|
int |
space()
the space remaining in the buffer. |
String |
toDetailString()
|
void |
writeTo(OutputStream out)
Write the buffer's contents to the output stream |
Field Detail |
public static final int IMMUTABLE
public static final int READONLY
public static final int READWRITE
public static final boolean VOLATILE
public static final boolean NON_VOLATILE
Method Detail |
public byte[] array()
byte[]
backing this buffer or null if none exists.public byte[] asArray()
byte[]
value of the bytes from the getIndex to the putIndex.public Buffer buffer()
public Buffer asNonVolatileBuffer()
Buffer
valuepublic Buffer asReadOnlyBuffer()
Buffer
.public Buffer asImmutableBuffer()
Buffer
.public Buffer asMutableBuffer()
Buffer
.public int capacity()
int
valuepublic int space()
public void clear()
public void compact()
public byte get()
byte
value from the current getIndex.public int get(byte[] b, int offset, int length)
b
- The byte array to fill.offset
- Offset in the array.length
- The max number of bytes to read.
public Buffer get(int length)
length
- an int
value
Buffer
valuepublic int getIndex()
int
value >=0 <= putIndex()public boolean hasContent()
public boolean equalsIgnoreCase(Buffer buffer)
boolean
value true if case sensitive comparison on this bufferpublic boolean isImmutable()
boolean
value true if the buffer is immutable and that neither
the buffer contents nor the indexes may be changed.public boolean isReadOnly()
boolean
value true if the buffer is readonly. The buffer indexes may
be modified, but the buffer contents may not. For example a View onto an immutable Buffer will be
read only.public boolean isVolatile()
boolean
value true if the buffer contents may change
via alternate paths than this buffer. If the contents of this buffer are to be used outside of the
current context, then a copy must be made.public int length()
int
== putIndex()-getIndex()public void mark()
public void mark(int offset)
offset
- an int
value to add to the current getIndex to obtain the mark value.public int markIndex()
int
index in the buffer or -1 if the mark is not set.public byte peek()
byte
value from the current getIndex.public byte peek(int index)
index
- an int
value
byte
valuepublic Buffer peek(int index, int length)
index
- an int
valuelength
- an int
value
Buffer
value from the requested getIndex.public int peek(int index, byte[] b, int offset, int length)
index
- an int
valueb
- The byte array to peek intooffset
- The offset into the array to start peekinglength
- an int
value
public int poke(int index, Buffer src)
index
- an int
valuesrc
- a Buffer
. If the source buffer is not modified
public void poke(int index, byte b)
index
- an int
valueb
- a byte
valuepublic int poke(int index, byte[] b, int offset, int length)
index
- an int
valueb
- a byte array
value
public int put(Buffer src)
src
- The source Buffer
it is not modified.
public void put(byte b)
b
- a byte
valuepublic int put(byte[] b, int offset, int length)
b
- a byte
value
public int put(byte[] b)
b
- a byte
value
public int putIndex()
int
value >= getIndex()public void reset()
public void setGetIndex(int newStart)
newStart
- an int
valuepublic void setMarkIndex(int newMark)
newMark
- an int
valuepublic void setPutIndex(int newLimit)
newLimit
- an int
valuepublic int skip(int n)
n
- The number of bytes to skip
public Buffer slice()
Buffer
from the postion to the putIndex.public Buffer sliceFromMark()
Buffer
value from the mark to the putIndexpublic Buffer sliceFromMark(int length)
length
- an int
value
Buffer
value from the mark of the length requested.public String toDetailString()
String
value describing the state and contents of the buffer.public void writeTo(OutputStream out) throws IOException
out
-
IOException
public int readFrom(InputStream in, int max) throws IOException
in
- input streammax
- maximum number of bytes that may be read
IOException
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |