Interface Buffer
- All Known Implementing Classes:
InputStreamBuffer
public interface Buffer
Represents an abstract view for one or more primitive byte arrays and NIO buffers.
-
Method Summary
Modifier and TypeMethodDescriptionintcapacity()Returns the number of bytes (octets) this buffer can contain.getBytes(int index, byte[] dst) Transfers this buffer's data to the specified destination starting at the specified absoluteindex.booleanisDirect()Returnstrueif and only if this buffer is backed by an NIO direct buffer.Marks the current writer index in this buffer.Exposes this buffer's readable bytes as a NIOByteBuffer.nioBuffer(int index, int length) Exposes this buffer's sub-region as an NIOByteBuffer.intReturns the maximum number of NIOByteBuffers that consist this buffer.Exposes this buffer's readable bytes as NIO ByteBuffer's instances.nioBuffers(int index, int length) Exposes this buffer's readable bytes as NIO ByteBuffer's instances.intReturns the number of readable bytes.booleanGets a boolean and advances the reader index.bytereadByte()Gets a byte and advances the reader index.readBytes(byte[] destination) Transfers this buffer's data to the specified destination starting at the current reader index and advances the reader index.readBytes(byte[] destination, int dstIndex, int length) Transfers this buffer's data to the specified destination starting at the current reader index and advances the reader index.readBytes(OutputStream out, int length) Transfers this buffer's data to the specified stream starting at the current reader index and advances the index.readBytes(ByteBuffer dst) Transfers this buffer's data to the specified destination starting at the current reader index until the destination's position reaches its limit, and advances the reader index.doubleGets a 64-bit floating point number and advances the reader index.intReturns the reader index of this buffer.readerIndex(int readerIndex) Sets the reader index of this buffer.floatGets a 32-bit floating point number and advances the reader index.intreadInt()Gets a 32-bit integer at the current index and advances the reader index.longreadLong()Gets a 64-bit integer and advances the reader index.shortGets a 16-bit short integer and advances the reader index.intReturns the reference count of this object.booleanrelease()Decreases the reference count by1and deallocates this object if the reference count reaches at0.Repositions the current writer index to the marked index in this buffer.retain()Increases the reference count by1.writeBoolean(boolean value) Sets the specified boolean at the current writer index and advances the index.writeByte(int value) Sets the specified byte at the current writer index and advances the index.writeBytes(byte[] src) Transfers the specified source array's data to this buffer starting at the current writer index and advances the index.writeBytes(byte[] src, int srcIndex, int length) Transfers the specified source array's data to this buffer starting at the current writer index and advances the index.writeBytes(ByteBuffer src) Transfers the specified source byte data to this buffer starting at the current writer index and advances the index.writeDouble(double value) Sets the specified 64-bit floating point number at the current writer index and advances the index.writeFloat(float value) Sets the specified 32-bit floating point number at the current writer index and advances the index.writeInt(int value) Sets the specified 32-bit integer at the current writer index and advances the index.writeLong(long value) Sets the specified 64-bit long integer at the current writer index and advances the index.intReturns the writer index of this buffer.writerIndex(int writerIndex) Sets the writer index of this buffer.writeShort(int value) Sets the specified 16-bit short integer at the current writer index and advances the index.
-
Method Details
-
readableBytes
int readableBytes()Returns the number of readable bytes. -
readerIndex
int readerIndex()Returns the reader index of this buffer. -
readerIndex
Sets the reader index of this buffer.- Throws:
IndexOutOfBoundsException- if its out of bounds.
-
writerIndex
int writerIndex()Returns the writer index of this buffer. -
writerIndex
Sets the writer index of this buffer. -
markWriterIndex
Buffer markWriterIndex()Marks the current writer index in this buffer. -
resetWriterIndex
Buffer resetWriterIndex()Repositions the current writer index to the marked index in this buffer. -
capacity
int capacity()Returns the number of bytes (octets) this buffer can contain. -
isDirect
boolean isDirect()Returnstrueif and only if this buffer is backed by an NIO direct buffer. -
readBoolean
boolean readBoolean()Gets a boolean and advances the reader index. -
readByte
byte readByte()Gets a byte and advances the reader index. -
readShort
short readShort()Gets a 16-bit short integer and advances the reader index. -
readInt
int readInt()Gets a 32-bit integer at the current index and advances the reader index. -
readLong
long readLong()Gets a 64-bit integer and advances the reader index. -
readFloat
float readFloat()Gets a 32-bit floating point number and advances the reader index. -
readDouble
double readDouble()Gets a 64-bit floating point number and advances the reader index. -
readBytes
Transfers this buffer's data to the specified destination starting at the current reader index and advances the reader index. -
readBytes
Transfers this buffer's data to the specified destination starting at the current reader index and advances the reader index.- Parameters:
destination- The destination bufferdstIndex- the first index of the destinationlength- the number of bytes to transfer
-
readBytes
Transfers this buffer's data to the specified destination starting at the current reader index until the destination's position reaches its limit, and advances the reader index. -
readBytes
Transfers this buffer's data to the specified stream starting at the current reader index and advances the index.- Parameters:
length- the number of bytes to transfer- Throws:
IOException- if the specified stream threw an exception during I/O
-
writeBoolean
Sets the specified boolean at the current writer index and advances the index. -
writeByte
Sets the specified byte at the current writer index and advances the index. -
writeShort
Sets the specified 16-bit short integer at the current writer index and advances the index. -
writeInt
Sets the specified 32-bit integer at the current writer index and advances the index. -
writeLong
Sets the specified 64-bit long integer at the current writer index and advances the index. -
writeFloat
Sets the specified 32-bit floating point number at the current writer index and advances the index. -
writeDouble
Sets the specified 64-bit floating point number at the current writer index and advances the index. -
writeBytes
Transfers the specified source array's data to this buffer starting at the current writer index and advances the index. -
writeBytes
Transfers the specified source byte data to this buffer starting at the current writer index and advances the index. -
writeBytes
Transfers the specified source array's data to this buffer starting at the current writer index and advances the index. -
release
boolean release()Decreases the reference count by1and deallocates this object if the reference count reaches at0. -
retain
Buffer retain()Increases the reference count by1. -
referenceCount
int referenceCount()Returns the reference count of this object. -
nioBufferCount
int nioBufferCount()Returns the maximum number of NIOByteBuffers that consist this buffer. -
nioBuffers
ByteBuffer[] nioBuffers()Exposes this buffer's readable bytes as NIO ByteBuffer's instances. -
nioBuffers
Exposes this buffer's readable bytes as NIO ByteBuffer's instances. -
nioBuffer
ByteBuffer nioBuffer()Exposes this buffer's readable bytes as a NIOByteBuffer. The returned buffer either share or contains the copied content of this buffer, while changing the position and limit of the returned NIO buffer does not affect the indexes and marks of this buffer. -
nioBuffer
Exposes this buffer's sub-region as an NIOByteBuffer. -
getBytes
Transfers this buffer's data to the specified destination starting at the specified absoluteindex. This method does not modify reader or writer indexes.
-