Class Buffer
- java.lang.Object
-
- io.vertx.reactivex.core.buffer.Buffer
-
- All Implemented Interfaces:
io.vertx.core.shareddata.impl.ClusterSerializable
public class Buffer extends Object implements io.vertx.core.shareddata.impl.ClusterSerializable
Most data is shuffled around inside Vert.x using buffers.A buffer is a sequence of zero or more bytes that can read from or written to and which expands automatically as necessary to accommodate any bytes written to it. You can perhaps think of a buffer as smart byte array.
Please consult the documentation for more information on buffers.
NOTE: This class has been automatically generated from theoriginal
non RX-ified interface using Vert.x codegen.
-
-
Field Summary
Fields Modifier and Type Field Description static TypeArg<Buffer>
__TYPE_ARG
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Buffer
appendBuffer(Buffer buff)
Appends the specifiedBuffer
to the end of this Buffer.Buffer
appendBuffer(Buffer buff, int offset, int len)
Appends the specifiedBuffer
starting at theoffset
usinglen
to the end of this Buffer.Buffer
appendByte(byte b)
Appends the specifiedbyte
to the end of the Buffer.Buffer
appendBytes(byte[] bytes)
Appends the specifiedbyte[]
to the end of the Buffer.Buffer
appendBytes(byte[] bytes, int offset, int len)
Appends the specified number of bytes frombyte[]
to the end of the Buffer, starting at the given offset.Buffer
appendDouble(double d)
Appends the specifieddouble
to the end of the Buffer.Buffer
appendFloat(float f)
Appends the specifiedfloat
to the end of the Buffer.Buffer
appendInt(int i)
Appends the specifiedint
to the end of the Buffer.Buffer
appendIntLE(int i)
Appends the specifiedint
to the end of the Buffer in the Little Endian Byte Order.Buffer
appendLong(long l)
Appends the specifiedlong
to the end of the Buffer.Buffer
appendLongLE(long l)
Appends the specifiedlong
to the end of the Buffer in the Little Endian Byte Order.Buffer
appendMedium(int i)
Appends the specified 24bitint
to the end of the Buffer.Buffer
appendMediumLE(int i)
Appends the specified 24bitint
to the end of the Buffer in the Little Endian Byte Order.Buffer
appendShort(short s)
Appends the specifiedshort
to the end of the Buffer.The buffer will expand as necessary to accommodate any bytes written.Buffer
appendShortLE(short s)
Appends the specifiedshort
to the end of the Buffer in the Little Endian Byte Order.The buffer will expand as necessary to accommodate any bytes written.Buffer
appendString(String str)
Appends the specifiedString str
to the end of the Buffer with UTF-8 encoding.Buffer
appendString(String str, String enc)
Appends the specifiedString
to the end of the Buffer with the encoding as specified byenc
.Buffer
appendUnsignedByte(short b)
Appends the specified unsignedbyte
to the end of the Buffer.Buffer
appendUnsignedInt(long i)
Appends the specified unsignedint
to the end of the Buffer.Buffer
appendUnsignedIntLE(long i)
Appends the specified unsignedint
to the end of the Buffer in the Little Endian Byte Order.Buffer
appendUnsignedShort(int s)
Appends the specified unsignedshort
to the end of the Buffer.The buffer will expand as necessary to accommodate any bytes written.Buffer
appendUnsignedShortLE(int s)
Appends the specified unsignedshort
to the end of the Buffer in the Little Endian Byte Order.The buffer will expand as necessary to accommodate any bytes written.static Buffer
buffer()
Create a new, empty buffer.static Buffer
buffer(byte[] bytes)
Create a new buffer from a byte[].static Buffer
buffer(int initialSizeHint)
Create a new buffer given the initial size hint.static Buffer
buffer(io.netty.buffer.ByteBuf byteBuf)
Deprecated.static Buffer
buffer(String string)
Create a new buffer from a string.static Buffer
buffer(String string, String enc)
Create a new buffer from a string and using the specified encoding.Buffer
copy()
Returns a copy of the entire Buffer.boolean
equals(Object o)
Buffer
getBuffer(int start, int end)
Returns a copy of a sub-sequence the Buffer as aBuffer
starting at positionstart
and ending at positionend - 1
byte
getByte(int pos)
Returns thebyte
at positionpos
in the Buffer.io.netty.buffer.ByteBuf
getByteBuf()
Deprecated.byte[]
getBytes()
Returns a copy of the entire Buffer as abyte[]
Buffer
getBytes(byte[] dst)
Transfers the content of the Buffer into abyte[]
.Buffer
getBytes(byte[] dst, int dstIndex)
Transfers the content of the Buffer into abyte[]
at the specific destination.byte[]
getBytes(int start, int end)
Returns a copy of a sub-sequence the Buffer as abyte[]
starting at positionstart
and ending at positionend - 1
Buffer
getBytes(int start, int end, byte[] dst)
Transfers the content of the Buffer starting at positionstart
and ending at positionend - 1
into abyte[]
.Buffer
getBytes(int start, int end, byte[] dst, int dstIndex)
Transfers the content of the Buffer starting at positionstart
and ending at positionend - 1
into abyte[]
at the specific destination.Buffer
getDelegate()
double
getDouble(int pos)
Returns thedouble
at positionpos
in the Buffer.float
getFloat(int pos)
Returns thefloat
at positionpos
in the Buffer.int
getInt(int pos)
Returns theint
at positionpos
in the Buffer.int
getIntLE(int pos)
Gets a 32-bit integer at the specified absoluteindex
in this buffer with Little Endian Byte Order.long
getLong(int pos)
Returns thelong
at positionpos
in the Buffer.long
getLongLE(int pos)
Gets a 64-bit long integer at the specified absoluteindex
in this buffer in Little Endian Byte Order.int
getMedium(int pos)
Gets a 24-bit medium integer at the specified absoluteindex
in this buffer.int
getMediumLE(int pos)
Gets a 24-bit medium integer at the specified absoluteindex
in this buffer in the Little Endian Byte Order.short
getShort(int pos)
Returns theshort
at positionpos
in the Buffer.short
getShortLE(int pos)
Gets a 16-bit short integer at the specified absoluteindex
in this buffer in Little Endian Byte Order.String
getString(int start, int end)
Returns a copy of a sub-sequence the Buffer as aString
starting at positionstart
and ending at positionend - 1
interpreted as a String in UTF-8 encodingString
getString(int start, int end, String enc)
Returns a copy of a sub-sequence the Buffer as aString
starting at positionstart
and ending at positionend - 1
interpreted as a String in the specified encodingshort
getUnsignedByte(int pos)
Returns the unsignedbyte
at positionpos
in the Buffer, as ashort
.long
getUnsignedInt(int pos)
Returns the unsignedint
at positionpos
in the Buffer, as along
.long
getUnsignedIntLE(int pos)
Returns the unsignedint
at positionpos
in the Buffer, as along
in Little Endian Byte Order.int
getUnsignedMedium(int pos)
Gets an unsigned 24-bit medium integer at the specified absoluteindex
in this buffer.int
getUnsignedMediumLE(int pos)
Gets an unsigned 24-bit medium integer at the specified absoluteindex
in this buffer in Little Endian Byte Order.int
getUnsignedShort(int pos)
Returns the unsignedshort
at positionpos
in the Buffer, as anint
.int
getUnsignedShortLE(int pos)
Gets an unsigned 16-bit short integer at the specified absoluteindex
in this buffer in Little Endian Byte Order.int
hashCode()
int
length()
Returns the length of the buffer, measured in bytes.static Buffer
newInstance(Buffer arg)
int
readFromBuffer(int pos, Buffer buffer)
Buffer
setBuffer(int pos, Buffer b)
Sets the bytes at positionpos
in the Buffer to the bytes represented by theBuffer b
.Buffer
setBuffer(int pos, Buffer b, int offset, int len)
Sets the bytes at positionpos
in the Buffer to the bytes represented by theBuffer b
on the givenoffset
andlen
.Buffer
setByte(int pos, byte b)
Sets thebyte
at positionpos
in the Buffer to the valueb
.Buffer
setBytes(int pos, byte[] b)
Sets the bytes at positionpos
in the Buffer to the bytes represented by thebyte[] b
.Buffer
setBytes(int pos, byte[] b, int offset, int len)
Sets the given number of bytes at positionpos
in the Buffer to the bytes represented by thebyte[] b
.Buffer
setBytes(int pos, ByteBuffer b)
Sets the bytes at positionpos
in the Buffer to the bytes represented by theByteBuffer b
.Buffer
setDouble(int pos, double d)
Sets thedouble
at positionpos
in the Buffer to the valued
.Buffer
setFloat(int pos, float f)
Sets thefloat
at positionpos
in the Buffer to the valuef
.Buffer
setInt(int pos, int i)
Sets theint
at positionpos
in the Buffer to the valuei
.Buffer
setIntLE(int pos, int i)
Sets theint
at positionpos
in the Buffer to the valuei
in the Little Endian Byte Order.Buffer
setLong(int pos, long l)
Sets thelong
at positionpos
in the Buffer to the valuel
.Buffer
setLongLE(int pos, long l)
Sets thelong
at positionpos
in the Buffer to the valuel
in the Little Endian Byte Order.Buffer
setMedium(int pos, int i)
Sets the 24bitint
at positionpos
in the Buffer to the valuei
.Buffer
setMediumLE(int pos, int i)
Sets the 24bitint
at positionpos
in the Buffer to the valuei
.Buffer
setShort(int pos, short s)
Sets theshort
at positionpos
in the Buffer to the values
.Buffer
setShortLE(int pos, short s)
Sets theshort
at positionpos
in the Buffer to the values
in the Little Endian Byte Order.Buffer
setString(int pos, String str)
Sets the bytes at positionpos
in the Buffer to the value ofstr
encoded in UTF-8.Buffer
setString(int pos, String str, String enc)
Sets the bytes at positionpos
in the Buffer to the value ofstr
encoded in encodingenc
.Buffer
setUnsignedByte(int pos, short b)
Sets the unsignedbyte
at positionpos
in the Buffer to the valueb
.Buffer
setUnsignedInt(int pos, long i)
Sets the unsignedint
at positionpos
in the Buffer to the valuei
.Buffer
setUnsignedIntLE(int pos, long i)
Sets the unsignedint
at positionpos
in the Buffer to the valuei
in the Little Endian Byte Order.Buffer
setUnsignedShort(int pos, int s)
Sets the unsignedshort
at positionpos
in the Buffer to the values
.Buffer
setUnsignedShortLE(int pos, int s)
Sets the unsignedshort
at positionpos
in the Buffer to the values
in the Little Endian Byte Order.Buffer
slice()
Returns a slice of this buffer.Buffer
slice(int start, int end)
Returns a slice of this buffer.Object
toJson()
Returns a Json representation of the Buffer.JsonArray
toJsonArray()
Returns a Json array representation of the Buffer.JsonObject
toJsonObject()
Returns a Json object representation of the Buffer.String
toString()
Returns aString
representation of the Buffer with theUTF-8
encodingString
toString(String enc)
Returns aString
representation of the Buffer with the encoding specified byenc
String
toString(Charset enc)
Returns aString
representation of the Buffer with the encoding specified byenc
void
writeToBuffer(Buffer buffer)
-
-
-
Method Detail
-
writeToBuffer
public void writeToBuffer(Buffer buffer)
- Specified by:
writeToBuffer
in interfaceio.vertx.core.shareddata.impl.ClusterSerializable
-
readFromBuffer
public int readFromBuffer(int pos, Buffer buffer)
- Specified by:
readFromBuffer
in interfaceio.vertx.core.shareddata.impl.ClusterSerializable
-
getDelegate
public Buffer getDelegate()
-
buffer
public static Buffer buffer()
Create a new, empty buffer.- Returns:
- the buffer
-
buffer
public static Buffer buffer(int initialSizeHint)
Create a new buffer given the initial size hint.If you know the buffer will require a certain size, providing the hint can prevent unnecessary re-allocations as the buffer is written to and resized.
- Parameters:
initialSizeHint
- the hint, in bytes- Returns:
- the buffer
-
buffer
public static Buffer buffer(String string)
Create a new buffer from a string. The string will be UTF-8 encoded into the buffer.- Parameters:
string
- the string- Returns:
- the buffer
-
buffer
public static Buffer buffer(String string, String enc)
Create a new buffer from a string and using the specified encoding. The string will be encoded into the buffer using the specified encoding.- Parameters:
string
- the stringenc
-- Returns:
- the buffer
-
toString
public String toString()
Returns aString
representation of the Buffer with theUTF-8
encoding
-
toString
public String toString(String enc)
Returns aString
representation of the Buffer with the encoding specified byenc
- Parameters:
enc
-- Returns:
-
toJsonObject
public JsonObject toJsonObject()
Returns a Json object representation of the Buffer.- Returns:
-
toJsonArray
public JsonArray toJsonArray()
Returns a Json array representation of the Buffer.- Returns:
-
toJson
public Object toJson()
Returns a Json representation of the Buffer.- Returns:
- a JSON element which can be a , ,
String
, ...etc if the buffer contains an array, object, string, ...etc
-
getByte
public byte getByte(int pos)
Returns thebyte
at positionpos
in the Buffer.- Parameters:
pos
-- Returns:
-
getUnsignedByte
public short getUnsignedByte(int pos)
Returns the unsignedbyte
at positionpos
in the Buffer, as ashort
.- Parameters:
pos
-- Returns:
-
getInt
public int getInt(int pos)
Returns theint
at positionpos
in the Buffer.- Parameters:
pos
-- Returns:
-
getIntLE
public int getIntLE(int pos)
Gets a 32-bit integer at the specified absoluteindex
in this buffer with Little Endian Byte Order.- Parameters:
pos
-- Returns:
-
getUnsignedInt
public long getUnsignedInt(int pos)
Returns the unsignedint
at positionpos
in the Buffer, as along
.- Parameters:
pos
-- Returns:
-
getUnsignedIntLE
public long getUnsignedIntLE(int pos)
Returns the unsignedint
at positionpos
in the Buffer, as along
in Little Endian Byte Order.- Parameters:
pos
-- Returns:
-
getLong
public long getLong(int pos)
Returns thelong
at positionpos
in the Buffer.- Parameters:
pos
-- Returns:
-
getLongLE
public long getLongLE(int pos)
Gets a 64-bit long integer at the specified absoluteindex
in this buffer in Little Endian Byte Order.- Parameters:
pos
-- Returns:
-
getDouble
public double getDouble(int pos)
Returns thedouble
at positionpos
in the Buffer.- Parameters:
pos
-- Returns:
-
getFloat
public float getFloat(int pos)
Returns thefloat
at positionpos
in the Buffer.- Parameters:
pos
-- Returns:
-
getShort
public short getShort(int pos)
Returns theshort
at positionpos
in the Buffer.- Parameters:
pos
-- Returns:
-
getShortLE
public short getShortLE(int pos)
Gets a 16-bit short integer at the specified absoluteindex
in this buffer in Little Endian Byte Order.- Parameters:
pos
-- Returns:
-
getUnsignedShort
public int getUnsignedShort(int pos)
Returns the unsignedshort
at positionpos
in the Buffer, as anint
.- Parameters:
pos
-- Returns:
-
getUnsignedShortLE
public int getUnsignedShortLE(int pos)
Gets an unsigned 16-bit short integer at the specified absoluteindex
in this buffer in Little Endian Byte Order.- Parameters:
pos
-- Returns:
-
getMedium
public int getMedium(int pos)
Gets a 24-bit medium integer at the specified absoluteindex
in this buffer.- Parameters:
pos
-- Returns:
-
getMediumLE
public int getMediumLE(int pos)
Gets a 24-bit medium integer at the specified absoluteindex
in this buffer in the Little Endian Byte Order.- Parameters:
pos
-- Returns:
-
getUnsignedMedium
public int getUnsignedMedium(int pos)
Gets an unsigned 24-bit medium integer at the specified absoluteindex
in this buffer.- Parameters:
pos
-- Returns:
-
getUnsignedMediumLE
public int getUnsignedMediumLE(int pos)
Gets an unsigned 24-bit medium integer at the specified absoluteindex
in this buffer in Little Endian Byte Order.- Parameters:
pos
-- Returns:
-
getBuffer
public Buffer getBuffer(int start, int end)
Returns a copy of a sub-sequence the Buffer as aBuffer
starting at positionstart
and ending at positionend - 1
- Parameters:
start
-end
-- Returns:
-
getString
public String getString(int start, int end, String enc)
Returns a copy of a sub-sequence the Buffer as aString
starting at positionstart
and ending at positionend - 1
interpreted as a String in the specified encoding- Parameters:
start
-end
-enc
-- Returns:
-
getString
public String getString(int start, int end)
Returns a copy of a sub-sequence the Buffer as aString
starting at positionstart
and ending at positionend - 1
interpreted as a String in UTF-8 encoding- Parameters:
start
-end
-- Returns:
-
appendBuffer
public Buffer appendBuffer(Buffer buff)
Appends the specifiedBuffer
to the end of this Buffer. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
this
so multiple operations can be appended together.- Parameters:
buff
-- Returns:
-
appendBuffer
public Buffer appendBuffer(Buffer buff, int offset, int len)
Appends the specifiedBuffer
starting at theoffset
usinglen
to the end of this Buffer. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
this
so multiple operations can be appended together.- Parameters:
buff
-offset
-len
-- Returns:
-
appendByte
public Buffer appendByte(byte b)
Appends the specifiedbyte
to the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
this
so multiple operations can be appended together.- Parameters:
b
-- Returns:
-
appendUnsignedByte
public Buffer appendUnsignedByte(short b)
Appends the specified unsignedbyte
to the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
this
so multiple operations can be appended together.- Parameters:
b
-- Returns:
-
appendInt
public Buffer appendInt(int i)
Appends the specifiedint
to the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
this
so multiple operations can be appended together.- Parameters:
i
-- Returns:
-
appendIntLE
public Buffer appendIntLE(int i)
Appends the specifiedint
to the end of the Buffer in the Little Endian Byte Order. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
this
so multiple operations can be appended together.- Parameters:
i
-- Returns:
-
appendUnsignedInt
public Buffer appendUnsignedInt(long i)
Appends the specified unsignedint
to the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
this
so multiple operations can be appended together.- Parameters:
i
-- Returns:
-
appendUnsignedIntLE
public Buffer appendUnsignedIntLE(long i)
Appends the specified unsignedint
to the end of the Buffer in the Little Endian Byte Order. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
this
so multiple operations can be appended together.- Parameters:
i
-- Returns:
-
appendMedium
public Buffer appendMedium(int i)
Appends the specified 24bitint
to the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
this
so multiple operations can be appended together.- Parameters:
i
-- Returns:
-
appendMediumLE
public Buffer appendMediumLE(int i)
Appends the specified 24bitint
to the end of the Buffer in the Little Endian Byte Order. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
this
so multiple operations can be appended together.- Parameters:
i
-- Returns:
-
appendLong
public Buffer appendLong(long l)
Appends the specifiedlong
to the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
this
so multiple operations can be appended together.- Parameters:
l
-- Returns:
-
appendLongLE
public Buffer appendLongLE(long l)
Appends the specifiedlong
to the end of the Buffer in the Little Endian Byte Order. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
this
so multiple operations can be appended together.- Parameters:
l
-- Returns:
-
appendShort
public Buffer appendShort(short s)
Appends the specifiedshort
to the end of the Buffer.The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
this
so multiple operations can be appended together.- Parameters:
s
-- Returns:
-
appendShortLE
public Buffer appendShortLE(short s)
Appends the specifiedshort
to the end of the Buffer in the Little Endian Byte Order.The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
this
so multiple operations can be appended together.- Parameters:
s
-- Returns:
-
appendUnsignedShort
public Buffer appendUnsignedShort(int s)
Appends the specified unsignedshort
to the end of the Buffer.The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
this
so multiple operations can be appended together.- Parameters:
s
-- Returns:
-
appendUnsignedShortLE
public Buffer appendUnsignedShortLE(int s)
Appends the specified unsignedshort
to the end of the Buffer in the Little Endian Byte Order.The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
this
so multiple operations can be appended together.- Parameters:
s
-- Returns:
-
appendFloat
public Buffer appendFloat(float f)
Appends the specifiedfloat
to the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
this
so multiple operations can be appended together.- Parameters:
f
-- Returns:
-
appendDouble
public Buffer appendDouble(double d)
Appends the specifieddouble
to the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
this
so multiple operations can be appended together.- Parameters:
d
-- Returns:
-
appendString
public Buffer appendString(String str, String enc)
Appends the specifiedString
to the end of the Buffer with the encoding as specified byenc
.The buffer will expand as necessary to accommodate any bytes written.
Returns a reference to
this
so multiple operations can be appended together.- Parameters:
str
-enc
-- Returns:
-
appendString
public Buffer appendString(String str)
Appends the specifiedString str
to the end of the Buffer with UTF-8 encoding.The buffer will expand as necessary to accommodate any bytes written.
Returns a reference to
this
so multiple operations can be appended together- Parameters:
str
-- Returns:
-
setByte
public Buffer setByte(int pos, byte b)
Sets thebyte
at positionpos
in the Buffer to the valueb
.The buffer will expand as necessary to accommodate any value written.
- Parameters:
pos
-b
-- Returns:
-
setUnsignedByte
public Buffer setUnsignedByte(int pos, short b)
Sets the unsignedbyte
at positionpos
in the Buffer to the valueb
.The buffer will expand as necessary to accommodate any value written.
- Parameters:
pos
-b
-- Returns:
-
setInt
public Buffer setInt(int pos, int i)
Sets theint
at positionpos
in the Buffer to the valuei
.The buffer will expand as necessary to accommodate any value written.
- Parameters:
pos
-i
-- Returns:
-
setIntLE
public Buffer setIntLE(int pos, int i)
Sets theint
at positionpos
in the Buffer to the valuei
in the Little Endian Byte Order.The buffer will expand as necessary to accommodate any value written.
- Parameters:
pos
-i
-- Returns:
-
setUnsignedInt
public Buffer setUnsignedInt(int pos, long i)
Sets the unsignedint
at positionpos
in the Buffer to the valuei
.The buffer will expand as necessary to accommodate any value written.
- Parameters:
pos
-i
-- Returns:
-
setUnsignedIntLE
public Buffer setUnsignedIntLE(int pos, long i)
Sets the unsignedint
at positionpos
in the Buffer to the valuei
in the Little Endian Byte Order.The buffer will expand as necessary to accommodate any value written.
- Parameters:
pos
-i
-- Returns:
-
setMedium
public Buffer setMedium(int pos, int i)
Sets the 24bitint
at positionpos
in the Buffer to the valuei
.The buffer will expand as necessary to accommodate any value written.
- Parameters:
pos
-i
-- Returns:
-
setMediumLE
public Buffer setMediumLE(int pos, int i)
Sets the 24bitint
at positionpos
in the Buffer to the valuei
. in the Little Endian Byte OrderThe buffer will expand as necessary to accommodate any value written.
- Parameters:
pos
-i
-- Returns:
-
setLong
public Buffer setLong(int pos, long l)
Sets thelong
at positionpos
in the Buffer to the valuel
.The buffer will expand as necessary to accommodate any value written.
- Parameters:
pos
-l
-- Returns:
-
setLongLE
public Buffer setLongLE(int pos, long l)
Sets thelong
at positionpos
in the Buffer to the valuel
in the Little Endian Byte Order.The buffer will expand as necessary to accommodate any value written.
- Parameters:
pos
-l
-- Returns:
-
setDouble
public Buffer setDouble(int pos, double d)
Sets thedouble
at positionpos
in the Buffer to the valued
.The buffer will expand as necessary to accommodate any value written.
- Parameters:
pos
-d
-- Returns:
-
setFloat
public Buffer setFloat(int pos, float f)
Sets thefloat
at positionpos
in the Buffer to the valuef
.The buffer will expand as necessary to accommodate any value written.
- Parameters:
pos
-f
-- Returns:
-
setShort
public Buffer setShort(int pos, short s)
Sets theshort
at positionpos
in the Buffer to the values
.The buffer will expand as necessary to accommodate any value written.
- Parameters:
pos
-s
-- Returns:
-
setShortLE
public Buffer setShortLE(int pos, short s)
Sets theshort
at positionpos
in the Buffer to the values
in the Little Endian Byte Order.The buffer will expand as necessary to accommodate any value written.
- Parameters:
pos
-s
-- Returns:
-
setUnsignedShort
public Buffer setUnsignedShort(int pos, int s)
Sets the unsignedshort
at positionpos
in the Buffer to the values
.The buffer will expand as necessary to accommodate any value written.
- Parameters:
pos
-s
-- Returns:
-
setUnsignedShortLE
public Buffer setUnsignedShortLE(int pos, int s)
Sets the unsignedshort
at positionpos
in the Buffer to the values
in the Little Endian Byte Order.The buffer will expand as necessary to accommodate any value written.
- Parameters:
pos
-s
-- Returns:
-
setBuffer
public Buffer setBuffer(int pos, Buffer b)
Sets the bytes at positionpos
in the Buffer to the bytes represented by theBuffer b
.The buffer will expand as necessary to accommodate any value written.
- Parameters:
pos
-b
-- Returns:
-
setBuffer
public Buffer setBuffer(int pos, Buffer b, int offset, int len)
Sets the bytes at positionpos
in the Buffer to the bytes represented by theBuffer b
on the givenoffset
andlen
.The buffer will expand as necessary to accommodate any value written.
- Parameters:
pos
-b
-offset
-len
-- Returns:
-
setString
public Buffer setString(int pos, String str)
Sets the bytes at positionpos
in the Buffer to the value ofstr
encoded in UTF-8.The buffer will expand as necessary to accommodate any value written.
- Parameters:
pos
-str
-- Returns:
-
setString
public Buffer setString(int pos, String str, String enc)
Sets the bytes at positionpos
in the Buffer to the value ofstr
encoded in encodingenc
.The buffer will expand as necessary to accommodate any value written.
- Parameters:
pos
-str
-enc
-- Returns:
-
length
public int length()
Returns the length of the buffer, measured in bytes. All positions are indexed from zero.- Returns:
-
copy
public Buffer copy()
Returns a copy of the entire Buffer.- Returns:
-
slice
public Buffer slice()
Returns a slice of this buffer. Modifying the content of the returned buffer or this buffer affects each other's content while they maintain separate indexes and marks.- Returns:
-
slice
public Buffer slice(int start, int end)
Returns a slice of this buffer. Modifying the content of the returned buffer or this buffer affects each other's content while they maintain separate indexes and marks.- Parameters:
start
-end
-- Returns:
-
buffer
public static Buffer buffer(byte[] bytes)
Create a new buffer from a byte[]. The byte[] will be copied to form the buffer.- Parameters:
bytes
- the byte array- Returns:
- the buffer
-
buffer
@Deprecated public static Buffer buffer(io.netty.buffer.ByteBuf byteBuf)
Deprecated.Create a new buffer from a Netty
ByteBuf
. Note that the returned buffer is backed by given Netty ByteBuf, so changes in the returned buffer are reflected in given Netty ByteBuf, and vice-versa.For example, both buffers in the code below share their data:
Buffer src = Buffer.buffer(); Buffer clone = Buffer.buffer(src.getByteBuf());
- Parameters:
byteBuf
- the Netty ByteBuf- Returns:
- the buffer
-
toString
public String toString(Charset enc)
Returns aString
representation of the Buffer with the encoding specified byenc
- Parameters:
enc
-- Returns:
-
getBytes
public byte[] getBytes()
Returns a copy of the entire Buffer as abyte[]
- Returns:
-
getBytes
public byte[] getBytes(int start, int end)
Returns a copy of a sub-sequence the Buffer as abyte[]
starting at positionstart
and ending at positionend - 1
- Parameters:
start
-end
-- Returns:
-
getBytes
public Buffer getBytes(byte[] dst)
Transfers the content of the Buffer into abyte[]
.- Parameters:
dst
- the destination byte array- Returns:
-
getBytes
public Buffer getBytes(byte[] dst, int dstIndex)
Transfers the content of the Buffer into abyte[]
at the specific destination.- Parameters:
dst
- the destination byte arraydstIndex
-- Returns:
-
getBytes
public Buffer getBytes(int start, int end, byte[] dst)
Transfers the content of the Buffer starting at positionstart
and ending at positionend - 1
into abyte[]
.- Parameters:
start
-end
-dst
- the destination byte array- Returns:
-
getBytes
public Buffer getBytes(int start, int end, byte[] dst, int dstIndex)
Transfers the content of the Buffer starting at positionstart
and ending at positionend - 1
into abyte[]
at the specific destination.- Parameters:
start
-end
-dst
- the destination byte arraydstIndex
-- Returns:
-
appendBytes
public Buffer appendBytes(byte[] bytes)
Appends the specifiedbyte[]
to the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
this
so multiple operations can be appended together.- Parameters:
bytes
-- Returns:
-
appendBytes
public Buffer appendBytes(byte[] bytes, int offset, int len)
Appends the specified number of bytes frombyte[]
to the end of the Buffer, starting at the given offset. The buffer will expand as necessary to accommodate any bytes written.Returns a reference to
this
so multiple operations can be appended together.- Parameters:
bytes
-offset
-len
-- Returns:
-
setBytes
public Buffer setBytes(int pos, ByteBuffer b)
Sets the bytes at positionpos
in the Buffer to the bytes represented by theByteBuffer b
.The buffer will expand as necessary to accommodate any value written.
- Parameters:
pos
-b
-- Returns:
-
setBytes
public Buffer setBytes(int pos, byte[] b)
Sets the bytes at positionpos
in the Buffer to the bytes represented by thebyte[] b
.The buffer will expand as necessary to accommodate any value written.
- Parameters:
pos
-b
-- Returns:
-
setBytes
public Buffer setBytes(int pos, byte[] b, int offset, int len)
Sets the given number of bytes at positionpos
in the Buffer to the bytes represented by thebyte[] b
. The buffer will expand as necessary to accommodate any value written.- Parameters:
pos
-b
-offset
-len
-- Returns:
-
getByteBuf
@Deprecated public io.netty.buffer.ByteBuf getByteBuf()
Deprecated.Returns the Buffer as a NettyByteBuf
.The returned buffer is a duplicate that maintain its own indices.
- Returns:
-
-