Top Description Inners Fields Methods
org.mortbay.io

public Interface Buffer

extends Cloneable
Known Direct Subinterfaces
org.mortbay.io.nio.NIOBuffer
Known Direct Implementers
org.mortbay.io.AbstractBuffer
Imports
java.io.IOException, .InputStream, .OutputStream

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
Author
gregw
Version
1.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface

Field Summary

Modifier and TypeField and Description
public static final int
public static final boolean
public static final int
public static final int
public static final boolean

Method Summary

Modifier and TypeMethod and Description
public byte[]

Returns:

a byte[] backing this buffer or null if none exists.
array
()

Get the underlying array, if one exists.

public byte[]

Returns:

a byte[] value of the bytes from the getIndex to the putIndex.
asArray
()

public Buffer

Returns:

an immutable version of this Buffer.
asImmutableBuffer
()

public Buffer

Returns:

an immutable version of this Buffer.
asMutableBuffer
()

public Buffer

Returns:

a non volitile version of this Buffer value
asNonVolatileBuffer
()

public Buffer

Returns:

a readonly version of this Buffer.
asReadOnlyBuffer
()

public Buffer

Returns:

The root backing buffer or this if there is no backing buffer;
buffer
()

Get the unerlying buffer.

public int

Returns:

an int value
capacity
()

The capacity of the buffer.

public void
clear()

Clear the buffer.

public void
compact()

Compact the buffer by discarding bytes before the postion (or mark if set).

public boolean

Returns:

a boolean value true if case sensitive comparison on this buffer
equalsIgnoreCase
(Buffer buffer)

public byte

Returns:

The byte value from the current getIndex.
get
()

Get the byte at the current getIndex and increment it.

public int

Returns:

The number of bytes actually read.
get
(byte[]
The byte array to fill.
b
,
int
Offset in the array.
offset
,
int
The max number of bytes to read.
length
)

Get bytes from the current postion and put them into the passed byte array.

public Buffer

Returns:

a Buffer value
get
(int
an int value
length
)

public int

Returns:

an int value >=0 <= putIndex()
getIndex
()

The index within the buffer that will next be read or written.

public boolean

Returns:

true of putIndex > getIndex
hasContent
()

public boolean

Returns:

a boolean value true if the buffer is immutable and that neither the buffer contents nor the indexes may be changed.
isImmutable
()

public boolean

Returns:

a 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.
isReadOnly
()

public boolean

Returns:

a 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.
isVolatile
()

public int

Returns:

an int == putIndex()-getIndex()
length
()

The number of bytes from the getIndex to the putIndex

public void
mark()

Set the mark to the current getIndex.

public void
mark(int
an int value to add to the current getIndex to obtain the mark value.
offset
)

Set the mark relative to the current getIndex

public int

Returns:

an int index in the buffer or -1 if the mark is not set.
markIndex
()

The current index of the mark.

public byte

Returns:

The byte value from the current getIndex.
peek
()

Get the byte at the current getIndex without incrementing the getIndex.

public byte

Returns:

a byte value
peek
(int
an int value
index
)

Get the byte at a specific index in the buffer.

public Buffer

Returns:

The Buffer value from the requested getIndex.
peek
(int
an int value
index
,
int
an int value
length
)

public int

Returns:

The number of bytes actually peeked
peek
(int
an int value
index
,
byte[]
The byte array to peek into
b
,
int
The offset into the array to start peeking
offset
,
int
an int value
length
)

public int

Returns:

The number of bytes actually poked
poke
(int
an int value
index
,
Buffer
a Buffer. If the source buffer is not modified
src
)

Put the contents of the buffer at the specific index.

public void
poke(int
an int value
index
,
byte
a byte value
b
)

Put a specific byte to a specific getIndex.

public int

Returns:

The number of bytes actually poked
poke
(int
an int value
index
,
byte[]
a byte array value
b
,
int offset, int length)

Put a specific byte to a specific getIndex.

public int

Returns:

The number of bytes actually poked
put
(Buffer
The source Buffer it is not modified.
src
)

Write the bytes from the source buffer to the current getIndex.

public void
put(byte
a byte value
b
)

Put a byte to the current getIndex and increment the getIndex.

public int

Returns:

The number of bytes actually poked
put
(byte[]
a byte value
b
,
int offset, int length)

Put a byte to the current getIndex and increment the getIndex.

public int

Returns:

The number of bytes actually poked
put
(byte[]
a byte value
b
)

Put a byte to the current getIndex and increment the getIndex.

public int

Returns:

an int value >= getIndex()
putIndex
()

The index of the first element that should not be read.

public int

Returns:

actual number of bytes read or -1 for EOF
readFrom
(InputStream
input stream
in
,
int
maximum number of bytes that may be read
max
)

Read the buffer's contents from the input stream

public void
reset()

Reset the current getIndex to the mark

public void
setGetIndex(int
an int value
newStart
)

Set the buffers start getIndex.

public void
setMarkIndex(int
an int value
newMark
)

Set a specific value for the mark.

public void
setPutIndex(int
an int value
newLimit
)

public int

Returns:

the number of bytes skipped.
skip
(int
The number of bytes to skip
n
)

Skip _content.

public Buffer

Returns:

a volitile Buffer from the postion to the putIndex.
slice
()

public Buffer

Returns:

a volitile Buffer value from the mark to the putIndex
sliceFromMark
()

public Buffer

Returns:

a valitile Buffer value from the mark of the length requested.
sliceFromMark
(int
an int value
length
)

public int

Returns:

capacity - putIndex
space
()

the space remaining in the buffer.

public String

Returns:

a String value describing the state and contents of the buffer.
toDetailString
()

public String
toString(String charset)

public void
writeTo(OutputStream out)

Write the buffer's contents to the output stream

Field Detail

IMMUTABLEback to summary
public static final int IMMUTABLE
NON_VOLATILEback to summary
public static final boolean NON_VOLATILE
READONLYback to summary
public static final int READONLY
READWRITEback to summary
public static final int READWRITE
VOLATILEback to summary
public static final boolean VOLATILE

Method Detail

arrayback to summary
public byte[] array()

Get the underlying array, if one exists.

Returns:byte[]

a byte[] backing this buffer or null if none exists.

asArrayback to summary
public byte[] asArray()
Returns:byte[]

a byte[] value of the bytes from the getIndex to the putIndex.

asImmutableBufferback to summary
public Buffer asImmutableBuffer()
Returns:Buffer

an immutable version of this Buffer.

asMutableBufferback to summary
public Buffer asMutableBuffer()
Returns:Buffer

an immutable version of this Buffer.

asNonVolatileBufferback to summary
public Buffer asNonVolatileBuffer()
Returns:Buffer

a non volitile version of this Buffer value

asReadOnlyBufferback to summary
public Buffer asReadOnlyBuffer()
Returns:Buffer

a readonly version of this Buffer.

bufferback to summary
public Buffer buffer()

Get the unerlying buffer. If this buffer wraps a backing buffer.

Returns:Buffer

The root backing buffer or this if there is no backing buffer;

capacityback to summary
public int capacity()

The capacity of the buffer. This is the maximum putIndex that may be set.

Returns:int

an int value

clearback to summary
public void clear()

Clear the buffer. getIndex=0, putIndex=0.

compactback to summary
public void compact()

Compact the buffer by discarding bytes before the postion (or mark if set). Bytes from the getIndex (or mark) to the putIndex are moved to the beginning of the buffer and the values adjusted accordingly.

equalsIgnoreCaseback to summary
public boolean equalsIgnoreCase(Buffer buffer)
Returns:boolean

a boolean value true if case sensitive comparison on this buffer

getback to summary
public byte get()

Get the byte at the current getIndex and increment it.

Returns:byte

The byte value from the current getIndex.

getback to summary
public int get(byte[] b, int offset, int length)

Get bytes from the current postion and put them into the passed byte array. The getIndex is incremented by the number of bytes copied into the array.

Parameters
b:byte[]

The byte array to fill.

offset:int

Offset in the array.

length:int

The max number of bytes to read.

Returns:int

The number of bytes actually read.

getback to summary
public Buffer get(int length)
Parameters
length:int

an int value

Returns:Buffer

a Buffer value

getIndexback to summary
public int getIndex()

The index within the buffer that will next be read or written.

Returns:int

an int value >=0 <= putIndex()

hasContentback to summary
public boolean hasContent()
Returns:boolean

true of putIndex > getIndex

isImmutableback to summary
public boolean isImmutable()
Returns:boolean

a boolean value true if the buffer is immutable and that neither the buffer contents nor the indexes may be changed.

isReadOnlyback to summary
public boolean isReadOnly()
Returns:boolean

a 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.

isVolatileback to summary
public boolean isVolatile()
Returns:boolean

a 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.

lengthback to summary
public int length()

The number of bytes from the getIndex to the putIndex

Returns:int

an int == putIndex()-getIndex()

markback to summary
public void mark()

Set the mark to the current getIndex.

markback to summary
public void mark(int offset)

Set the mark relative to the current getIndex

Parameters
offset:int

an int value to add to the current getIndex to obtain the mark value.

markIndexback to summary
public int markIndex()

The current index of the mark.

Returns:int

an int index in the buffer or -1 if the mark is not set.

peekback to summary
public byte peek()

Get the byte at the current getIndex without incrementing the getIndex.

Returns:byte

The byte value from the current getIndex.

peekback to summary
public byte peek(int index)

Get the byte at a specific index in the buffer.

Parameters
index:int

an int value

Returns:byte

a byte value

peekback to summary
public Buffer peek(int index, int length)
Parameters
index:int

an int value

length:int

an int value

Returns:Buffer

The Buffer value from the requested getIndex.

peekback to summary
public int peek(int index, byte[] b, int offset, int length)
Parameters
index:int

an int value

b:byte[]

The byte array to peek into

offset:int

The offset into the array to start peeking

length:int

an int value

Returns:int

The number of bytes actually peeked

pokeback to summary
public int poke(int index, Buffer src)

Put the contents of the buffer at the specific index.

Parameters
index:int

an int value

src:Buffer

a Buffer. If the source buffer is not modified

Returns:int

The number of bytes actually poked

pokeback to summary
public void poke(int index, byte b)

Put a specific byte to a specific getIndex.

Parameters
index:int

an int value

b:byte

a byte value

pokeback to summary
public int poke(int index, byte[] b, int offset, int length)

Put a specific byte to a specific getIndex.

Parameters
index:int

an int value

b:byte[]

a byte array value

Returns:int

The number of bytes actually poked

putback to summary
public int put(Buffer src)

Write the bytes from the source buffer to the current getIndex.

Parameters
src:Buffer

The source Buffer it is not modified.

Returns:int

The number of bytes actually poked

putback to summary
public void put(byte b)

Put a byte to the current getIndex and increment the getIndex.

Parameters
b:byte

a byte value

putback to summary
public int put(byte[] b, int offset, int length)

Put a byte to the current getIndex and increment the getIndex.

Parameters
b:byte[]

a byte value

Returns:int

The number of bytes actually poked

putback to summary
public int put(byte[] b)

Put a byte to the current getIndex and increment the getIndex.

Parameters
b:byte[]

a byte value

Returns:int

The number of bytes actually poked

putIndexback to summary
public int putIndex()

The index of the first element that should not be read.

Returns:int

an int value >= getIndex()

readFromback to summary
public int readFrom(InputStream in, int max) throws IOException

Read the buffer's contents from the input stream

Parameters
in:InputStream

input stream

max:int

maximum number of bytes that may be read

Returns:int

actual number of bytes read or -1 for EOF

resetback to summary
public void reset()

Reset the current getIndex to the mark

setGetIndexback to summary
public void setGetIndex(int newStart)

Set the buffers start getIndex.

Parameters
newStart:int

an int value

setMarkIndexback to summary
public void setMarkIndex(int newMark)

Set a specific value for the mark.

Parameters
newMark:int

an int value

setPutIndexback to summary
public void setPutIndex(int newLimit)
Parameters
newLimit:int

an int value

skipback to summary
public int skip(int n)

Skip _content. The getIndex is updated by min(remaining(), n)

Parameters
n:int

The number of bytes to skip

Returns:int

the number of bytes skipped.

sliceback to summary
public Buffer slice()
Returns:Buffer

a volitile Buffer from the postion to the putIndex.

sliceFromMarkback to summary
public Buffer sliceFromMark()
Returns:Buffer

a volitile Buffer value from the mark to the putIndex

sliceFromMarkback to summary
public Buffer sliceFromMark(int length)
Parameters
length:int

an int value

Returns:Buffer

a valitile Buffer value from the mark of the length requested.

spaceback to summary
public int space()

the space remaining in the buffer.

Returns:int

capacity - putIndex

toDetailStringback to summary
public String toDetailString()
Returns:String

a String value describing the state and contents of the buffer.

toStringback to summary
public String toString(String charset)
writeToback to summary
public void writeTo(OutputStream out) throws IOException

Write the buffer's contents to the output stream

org.mortbay.io back to summary

public Interface Buffer.CaseInsensitve

Known Direct Implementers
org.mortbay.io.ByteArrayBuffer.CaseInsensitive, org.mortbay.io.View.CaseInsensitive