Groovy Documentation

org.vertx.groovy.core.buffer
[Groovy] Class Buffer

java.lang.Object
  org.vertx.java.core.buffer.Buffer
      org.vertx.groovy.core.buffer.Buffer

class Buffer
extends Buffer

A Buffer represents a sequence of zero or more bytes that can be written to or read from, and which expands as necessary to accomodate any bytes written to it.

There are two ways to write data to a Buffer: The first method involves methods that take the form setXXX. These methods write data into the buffer starting at the specified position. The position does not have to be inside data that has already been written to the buffer; the buffer will automatically expand to encompass the position plus any data that needs to be written. All positions are measured in bytes and start with zero.

The second method involves methods that take the form appendXXX; these methods append data at the end of the buffer.

Methods exist to both set and append all primitive types, java.lang.String, java.nio.ByteBuffer and other instances of Buffer.

Data can be read from a buffer by invoking methods which take the form getXXX. These methods take a parameter representing the position in the Buffer from where to read data.

Methods putAt and getAt are defined allowing you to use index notation to get/set bytes at a specific position in the buffer.

Methods leftShift are defined to mean append allowing you to use the familiar Groovy << operator on buffers.

Authors:
Tim Fox


Constructor Summary
Buffer()

Create an empty buffer

Buffer(int initialSizeHint)

Creates a new empty Buffer that is expected to have a size of initialSizeHint after data has been written to it.

Buffer(byte[] bytes)

Create a new Buffer that contains the contents of a byte[]

Buffer(java.lang.String str, java.lang.String enc)

Create a new Buffer that contains the contents of a String str encoded according to the encoding enc

Buffer(java.lang.String str)

Create a new Buffer that contains the contents of String str encoded with UTF-8 encoding

 
Method Summary
Buffer appendBuffer(Buffer buff)

Appends the specified Buffer to the end of this Buffer.

Buffer appendByte(byte b)

Appends the specified byte to the end of the Buffer.

Buffer appendBytes(byte[] bytes)

Appends the specified byte[] to the end of the Buffer.

Buffer appendDouble(double d)

Appends the specified double to the end of the Buffer.

Buffer appendFloat(float f)

Appends the specified float to the end of the Buffer.

Buffer appendInt(int i)

Appends the specified int to the end of the Buffer.

Buffer appendLong(long l)

Appends the specified long to the end of the Buffer.

Buffer appendShort(short s)

Appends the specified short to the end of the Buffer.The buffer will expand as necessary to accomodate any bytes written.

Buffer appendString(java.lang.String str, java.lang.String enc)

Appends the specified String to the end of the Buffer with the encoding as specified by enc.

Buffer appendString(java.lang.String str)

Appends the specified String str to the end of the Buffer with UTF-8 encoding.

Buffer copy()

Returns a copy of the entire Buffer.

byte getAt(int pos)

Same as getByte(int)

Buffer getBuffer(int start, int end)

Returns a copy of a sub-sequence the Buffer as a Buffer starting at position start and ending at position end - 1

byte getByte(int pos)

Returns the byte at position pos in the Buffer.

byte[] getBytes()

Returns a copy of the entire Buffer as a byte[]

byte[] getBytes(int start, int end)

Returns a copy of a sub-sequence the Buffer as a byte[] starting at position start and ending at position end - 1

double getDouble(int pos)

Returns the double at position pos in the Buffer.

float getFloat(int pos)

Returns the float at position pos in the Buffer.

int getInt(int pos)

Returns the int at position pos in the Buffer.

int getLength()

Synonym for length

long getLong(int pos)

Returns the long at position pos in the Buffer.

short getShort(int pos)

Returns the short at position pos in the Buffer.

java.lang.String getString(int start, int end, java.lang.String enc)

Returns a copy of a sub-sequence the Buffer as a String starting at position start and ending at position end - 1 interpreted as a String in the specified encoding

java.lang.String getString(int start, int end)

Returns a copy of a sub-sequence the Buffer as a String starting at position start and ending at position end - 1 interpreted as a String in UTF-8 encoding

int hashCode()

Buffer leftShift(Buffer buff)

Same as appendBuffer(Buffer)

Buffer leftShift(byte[] bytes)

Same as appendBytes(byte[])

Buffer leftShift(byte b)

Same as appendByte(byte)

Buffer leftShift(int i)

Same as appendInt(int)

Buffer leftShift(long l)

Same as appendLong(long)

Buffer leftShift(short s)

Same as appendShort(short)

Buffer leftShift(float f)

Same as appendFloat(float)

Buffer leftShift(double d)

Same as appendDouble(double)

Buffer leftShift(java.lang.String s)

Same as appendString(String)

int length()

Returns the length of the buffer, measured in bytes.

void putAt(int pos, byte b)

Same as setByte(int, byte)

void putAt(int pos, int i)

Same as setInt(int, int)

void putAt(int pos, long l)

Same as setLong(int, long)

void putAt(int pos, double d)

Same as setDouble(int, double)

void putAt(int pos, float f)

Same as setFloat(int, float)

void putAt(int pos, short s)

Same as setShort(int, short)

void putAt(int pos, Buffer b)

Same as setBuffer(int, Buffer)

void putAt(int pos, java.nio.ByteBuffer b)

Same as setBytes(int, ByteBuffer)

void putAt(int pos, byte[] b)

Same as setBytes(int, byte[])

void putAt(int pos, java.lang.String str)

Same as setString(int, String)

Buffer setBuffer(int pos, Buffer b)

Sets the bytes at position pos in the Buffer to the bytes represented by the Buffer b.

Buffer setByte(int pos, byte b)

Sets the byte at position pos in the Buffer to the value b.

Buffer setBytes(int pos, java.nio.ByteBuffer b)

Sets the bytes at position pos in the Buffer to the bytes represented by the ByteBuffer b.

Buffer setBytes(int pos, byte[] b)

Sets the bytes at position pos in the Buffer to the bytes represented by the byte[] b.

Buffer setDouble(int pos, double d)

Sets the double at position pos in the Buffer to the value d.

Buffer setFloat(int pos, float f)

Sets the float at position pos in the Buffer to the value f.

Buffer setInt(int pos, int i)

Sets the int at position pos in the Buffer to the value i.

Buffer setLong(int pos, long l)

Sets the long at position pos in the Buffer to the value l.

Buffer setShort(int pos, short s)

Sets the short at position pos in the Buffer to the value s.

Buffer setString(int pos, java.lang.String str)

Sets the bytes at position pos in the Buffer to the value of str endoded in UTF-8.

Buffer setString(int pos, java.lang.String str, java.lang.String enc)

Sets the bytes at position pos in the Buffer to the value of str encoded in encoding enc.

JBuffer toJavaBuffer()

Returns the underlying Java buffer

java.lang.String toString()

Returns a String represention of the Buffer with the encoding specified by enc

 

Constructor Detail

Buffer

Buffer()
Create an empty buffer


Buffer

Buffer(int initialSizeHint)
Creates a new empty Buffer that is expected to have a size of initialSizeHint after data has been written to it.

Please note that length of the Buffer immediately after creation will be zero.

The initialSizeHint is merely a hint to the system for how much memory to initially allocate to the buffer to prevent excessive automatic re-allocations as data is written to it.


Buffer

Buffer(byte[] bytes)
Create a new Buffer that contains the contents of a byte[]


Buffer

Buffer(java.lang.String str, java.lang.String enc)
Create a new Buffer that contains the contents of a String str encoded according to the encoding enc


Buffer

Buffer(java.lang.String str)
Create a new Buffer that contains the contents of String str encoded with UTF-8 encoding


 
Method Detail

appendBuffer

Buffer appendBuffer(Buffer buff)
Appends the specified Buffer to the end of this Buffer. The buffer will expand as necessary to accomodate any bytes written.

Returns a reference to this so multiple operations can be appended together.


appendByte

Buffer appendByte(byte b)
Appends the specified byte to the end of the Buffer. The buffer will expand as necessary to accomodate any bytes written.

Returns a reference to this so multiple operations can be appended together.


appendBytes

Buffer appendBytes(byte[] bytes)
Appends the specified byte[] to the end of the Buffer. The buffer will expand as necessary to accomodate any bytes written.

Returns a reference to this so multiple operations can be appended together.


appendDouble

Buffer appendDouble(double d)
Appends the specified double to the end of the Buffer. The buffer will expand as necessary to accomodate any bytes written.

Returns a reference to this so multiple operations can be appended together.


appendFloat

Buffer appendFloat(float f)
Appends the specified float to the end of the Buffer. The buffer will expand as necessary to accomodate any bytes written.

Returns a reference to this so multiple operations can be appended together.


appendInt

Buffer appendInt(int i)
Appends the specified int to the end of the Buffer. The buffer will expand as necessary to accomodate any bytes written.

Returns a reference to this so multiple operations can be appended together.


appendLong

Buffer appendLong(long l)
Appends the specified long to the end of the Buffer. The buffer will expand as necessary to accomodate any bytes written.

Returns a reference to this so multiple operations can be appended together.


appendShort

Buffer appendShort(short s)
Appends the specified short to the end of the Buffer.The buffer will expand as necessary to accomodate any bytes written.

Returns a reference to this so multiple operations can be appended together.


appendString

Buffer appendString(java.lang.String str, java.lang.String enc)
Appends the specified String to the end of the Buffer with the encoding as specified by enc.

The buffer will expand as necessary to accomodate any bytes written.

Returns a reference to this so multiple operations can be appended together.


appendString

Buffer appendString(java.lang.String str)
Appends the specified String str to the end of the Buffer with UTF-8 encoding.

The buffer will expand as necessary to accomodate any bytes written.

Returns a reference to this so multiple operations can be appended together


copy

Buffer copy()
Returns a copy of the entire Buffer.


getAt

byte getAt(int pos)
Same as getByte(int)


getBuffer

Buffer getBuffer(int start, int end)
Returns a copy of a sub-sequence the Buffer as a Buffer starting at position start and ending at position end - 1


getByte

byte getByte(int pos)
Returns the byte at position pos in the Buffer.
throws:
IndexOutOfBoundsException if the specified pos is less than 0 or pos + 1 is greater than the length of the Buffer.


getBytes

byte[] getBytes()
Returns a copy of the entire Buffer as a byte[]


getBytes

byte[] getBytes(int start, int end)
Returns a copy of a sub-sequence the Buffer as a byte[] starting at position start and ending at position end - 1


getDouble

double getDouble(int pos)
Returns the double at position pos in the Buffer.
throws:
IndexOutOfBoundsException if the specified pos is less than 0 or pos + 8 is greater than the length of the Buffer.


getFloat

float getFloat(int pos)
Returns the float at position pos in the Buffer.
throws:
IndexOutOfBoundsException if the specified pos is less than 0 or pos + 4 is greater than the length of the Buffer.


getInt

int getInt(int pos)
Returns the int at position pos in the Buffer.
throws:
IndexOutOfBoundsException if the specified pos is less than 0 or pos + 4 is greater than the length of the Buffer.


getLength

int getLength()
Synonym for length


getLong

long getLong(int pos)
Returns the long at position pos in the Buffer.
throws:
IndexOutOfBoundsException if the specified pos is less than 0 or pos + 8 is greater than the length of the Buffer.


getShort

short getShort(int pos)
Returns the short at position pos in the Buffer.
throws:
IndexOutOfBoundsException if the specified pos is less than 0 or pos + 2 is greater than the length of the Buffer.


getString

java.lang.String getString(int start, int end, java.lang.String enc)
Returns a copy of a sub-sequence the Buffer as a String starting at position start and ending at position end - 1 interpreted as a String in the specified encoding


getString

java.lang.String getString(int start, int end)
Returns a copy of a sub-sequence the Buffer as a String starting at position start and ending at position end - 1 interpreted as a String in UTF-8 encoding


hashCode

int hashCode()


leftShift

Buffer leftShift(Buffer buff)
Same as appendBuffer(Buffer)


leftShift

Buffer leftShift(byte[] bytes)
Same as appendBytes(byte[])


leftShift

Buffer leftShift(byte b)
Same as appendByte(byte)


leftShift

Buffer leftShift(int i)
Same as appendInt(int)


leftShift

Buffer leftShift(long l)
Same as appendLong(long)


leftShift

Buffer leftShift(short s)
Same as appendShort(short)


leftShift

Buffer leftShift(float f)
Same as appendFloat(float)


leftShift

Buffer leftShift(double d)
Same as appendDouble(double)


leftShift

Buffer leftShift(java.lang.String s)
Same as appendString(String)


length

int length()
Returns the length of the buffer, measured in bytes. All positions are indexed from zero.


putAt

void putAt(int pos, byte b)
Same as setByte(int, byte)


putAt

void putAt(int pos, int i)
Same as setInt(int, int)


putAt

void putAt(int pos, long l)
Same as setLong(int, long)


putAt

void putAt(int pos, double d)
Same as setDouble(int, double)


putAt

void putAt(int pos, float f)
Same as setFloat(int, float)


putAt

void putAt(int pos, short s)
Same as setShort(int, short)


putAt

void putAt(int pos, Buffer b)
Same as setBuffer(int, Buffer)


putAt

void putAt(int pos, java.nio.ByteBuffer b)
Same as setBytes(int, ByteBuffer)


putAt

void putAt(int pos, byte[] b)
Same as setBytes(int, byte[])


putAt

void putAt(int pos, java.lang.String str)
Same as setString(int, String)


setBuffer

Buffer setBuffer(int pos, Buffer b)
Sets the bytes at position pos in the Buffer to the bytes represented by the Buffer b.

The buffer will expand as necessary to accomodate any value written.


setByte

Buffer setByte(int pos, byte b)
Sets the byte at position pos in the Buffer to the value b.

The buffer will expand as necessary to accomodate any value written.


setBytes

Buffer setBytes(int pos, java.nio.ByteBuffer b)
Sets the bytes at position pos in the Buffer to the bytes represented by the ByteBuffer b.

The buffer will expand as necessary to accomodate any value written.


setBytes

Buffer setBytes(int pos, byte[] b)
Sets the bytes at position pos in the Buffer to the bytes represented by the byte[] b.

The buffer will expand as necessary to accomodate any value written.


setDouble

Buffer setDouble(int pos, double d)
Sets the double at position pos in the Buffer to the value d.

The buffer will expand as necessary to accomodate any value written.


setFloat

Buffer setFloat(int pos, float f)
Sets the float at position pos in the Buffer to the value f.

The buffer will expand as necessary to accomodate any value written.


setInt

Buffer setInt(int pos, int i)
Sets the int at position pos in the Buffer to the value i.

The buffer will expand as necessary to accomodate any value written.


setLong

Buffer setLong(int pos, long l)
Sets the long at position pos in the Buffer to the value l.

The buffer will expand as necessary to accomodate any value written.


setShort

Buffer setShort(int pos, short s)
Sets the short at position pos in the Buffer to the value s.

The buffer will expand as necessary to accomodate any value written.


setString

Buffer setString(int pos, java.lang.String str)
Sets the bytes at position pos in the Buffer to the value of str endoded in UTF-8.

The buffer will expand as necessary to accomodate any value written.


setString

Buffer setString(int pos, java.lang.String str, java.lang.String enc)
Sets the bytes at position pos in the Buffer to the value of str encoded in encoding enc.

The buffer will expand as necessary to accomodate any value written.


toJavaBuffer

JBuffer toJavaBuffer()
Returns the underlying Java buffer


toString

java.lang.String toString()
Returns a String represention of the Buffer with the encoding specified by enc


 

Groovy Documentation