Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Buffer

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.

Hierarchy

  • Buffer

Index

Methods

appendBuffer

  • Appends the specified Buffer 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

    Returns Buffer

  • Appends the specified Buffer starting at the offset using len 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: Buffer
    • offset: number
    • len: number

    Returns Buffer

appendByte

  • appendByte(b: number): Buffer
  • Appends the specified byte 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: number

    Returns Buffer

appendBytes

  • appendBytes(bytes: number[]): Buffer
  • appendBytes(bytes: number[], offset: number, len: number): Buffer
  • Appends the specified byte[] 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: number[]

    Returns Buffer

  • Appends the specified number of bytes from byte[] 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: number[]
    • offset: number
    • len: number

    Returns Buffer

appendDouble

  • appendDouble(d: number): Buffer
  • Appends the specified double 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: number

    Returns Buffer

appendFloat

  • appendFloat(f: number): Buffer
  • Appends the specified float 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: number

    Returns Buffer

appendInt

  • appendInt(i: number): Buffer
  • Appends the specified int 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: number

    Returns Buffer

appendIntLE

  • appendIntLE(i: number): Buffer
  • Appends the specified int 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: number

    Returns Buffer

appendLong

  • appendLong(l: number): Buffer
  • Appends the specified long 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: number

    Returns Buffer

appendLongLE

  • appendLongLE(l: number): Buffer
  • Appends the specified long 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: number

    Returns Buffer

appendMedium

  • appendMedium(i: number): Buffer
  • Appends the specified 24bit int 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: number

    Returns Buffer

appendMediumLE

  • appendMediumLE(i: number): Buffer
  • Appends the specified 24bit int 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: number

    Returns Buffer

appendShort

  • appendShort(s: number): Buffer
  • Appends the specified short 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: number

    Returns Buffer

appendShortLE

  • appendShortLE(s: number): Buffer
  • Appends the specified short 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: number

    Returns Buffer

appendString

  • appendString(str: string, enc: string): Buffer
  • appendString(str: string): Buffer
  • Appends the specified String to the end of the Buffer with the encoding as specified by enc.

    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: string
    • enc: string

    Returns Buffer

  • Appends the specified String 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: string

    Returns Buffer

appendUnsignedByte

  • appendUnsignedByte(b: number): Buffer
  • Appends the specified unsigned byte 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: number

    Returns Buffer

appendUnsignedInt

  • appendUnsignedInt(i: number): Buffer
  • Appends the specified unsigned int 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: number

    Returns Buffer

appendUnsignedIntLE

  • appendUnsignedIntLE(i: number): Buffer
  • Appends the specified unsigned int 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: number

    Returns Buffer

appendUnsignedShort

  • appendUnsignedShort(s: number): Buffer
  • Appends the specified unsigned short 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: number

    Returns Buffer

appendUnsignedShortLE

  • appendUnsignedShortLE(s: number): Buffer
  • Appends the specified unsigned short 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: number

    Returns Buffer

copy

  • Returns a copy of the entire Buffer.

    Returns Buffer

getBuffer

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

    Parameters

    • start: number
    • end: number

    Returns Buffer

getByte

  • getByte(pos: number): number
  • Returns the byte at position pos in the Buffer.

    Parameters

    • pos: number

    Returns number

getByteBuf

  • getByteBuf(): any
  • Returns the Buffer as a Netty ByteBuf.

    The returned buffer is a duplicate that maintain its own indices.

    Returns any

getBytes

  • getBytes(): number[]
  • getBytes(start: number, end: number): number[]
  • getBytes(dst: number[]): Buffer
  • getBytes(dst: number[], dstIndex: number): Buffer
  • getBytes(start: number, end: number, dst: number[]): Buffer
  • getBytes(start: number, end: number, dst: number[], dstIndex: number): Buffer
  • Returns a copy of the entire Buffer as a byte[]

    Returns number[]

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

    Parameters

    • start: number
    • end: number

    Returns number[]

  • Transfers the content of the Buffer into a byte[].

    Parameters

    • dst: number[]

    Returns Buffer

  • Transfers the content of the Buffer into a byte[] at the specific destination.

    Parameters

    • dst: number[]
    • dstIndex: number

    Returns Buffer

  • Transfers the content of the Buffer starting at position start and ending at position end - 1 into a byte[].

    Parameters

    • start: number
    • end: number
    • dst: number[]

    Returns Buffer

  • Transfers the content of the Buffer starting at position start and ending at position end - 1 into a byte[] at the specific destination.

    Parameters

    • start: number
    • end: number
    • dst: number[]
    • dstIndex: number

    Returns Buffer

getDouble

  • getDouble(pos: number): number
  • Returns the double at position pos in the Buffer.

    Parameters

    • pos: number

    Returns number

getFloat

  • getFloat(pos: number): number
  • Returns the float at position pos in the Buffer.

    Parameters

    • pos: number

    Returns number

getInt

  • getInt(pos: number): number
  • Returns the int at position pos in the Buffer.

    Parameters

    • pos: number

    Returns number

getIntLE

  • getIntLE(pos: number): number
  • Gets a 32-bit integer at the specified absolute index in this buffer with Little Endian Byte Order.

    Parameters

    • pos: number

    Returns number

getLong

  • getLong(pos: number): number
  • Returns the long at position pos in the Buffer.

    Parameters

    • pos: number

    Returns number

getLongLE

  • getLongLE(pos: number): number
  • Gets a 64-bit long integer at the specified absolute index in this buffer in Little Endian Byte Order.

    Parameters

    • pos: number

    Returns number

getMedium

  • getMedium(pos: number): number
  • Gets a 24-bit medium integer at the specified absolute index in this buffer.

    Parameters

    • pos: number

    Returns number

getMediumLE

  • getMediumLE(pos: number): number
  • Gets a 24-bit medium integer at the specified absolute index in this buffer in the Little Endian Byte Order.

    Parameters

    • pos: number

    Returns number

getShort

  • getShort(pos: number): number
  • Returns the short at position pos in the Buffer.

    Parameters

    • pos: number

    Returns number

getShortLE

  • getShortLE(pos: number): number
  • Gets a 16-bit short integer at the specified absolute index in this buffer in Little Endian Byte Order.

    Parameters

    • pos: number

    Returns number

getString

  • getString(start: number, end: number, enc: string): string
  • getString(start: number, end: number): string
  • 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

    Parameters

    • start: number
    • end: number
    • enc: string

    Returns string

  • 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

    Parameters

    • start: number
    • end: number

    Returns string

getUnsignedByte

  • getUnsignedByte(pos: number): number
  • Returns the unsigned byte at position pos in the Buffer, as a short.

    Parameters

    • pos: number

    Returns number

getUnsignedInt

  • getUnsignedInt(pos: number): number
  • Returns the unsigned int at position pos in the Buffer, as a long.

    Parameters

    • pos: number

    Returns number

getUnsignedIntLE

  • getUnsignedIntLE(pos: number): number
  • Returns the unsigned int at position pos in the Buffer, as a long in Little Endian Byte Order.

    Parameters

    • pos: number

    Returns number

getUnsignedMedium

  • getUnsignedMedium(pos: number): number
  • Gets an unsigned 24-bit medium integer at the specified absolute index in this buffer.

    Parameters

    • pos: number

    Returns number

getUnsignedMediumLE

  • getUnsignedMediumLE(pos: number): number
  • Gets an unsigned 24-bit medium integer at the specified absolute index in this buffer in Little Endian Byte Order.

    Parameters

    • pos: number

    Returns number

getUnsignedShort

  • getUnsignedShort(pos: number): number
  • Returns the unsigned short at position pos in the Buffer, as an int.

    Parameters

    • pos: number

    Returns number

getUnsignedShortLE

  • getUnsignedShortLE(pos: number): number
  • Gets an unsigned 16-bit short integer at the specified absolute index in this buffer in Little Endian Byte Order.

    Parameters

    • pos: number

    Returns number

length

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

    Returns number

setBuffer

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

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

    Parameters

    Returns Buffer

  • Sets the bytes at position pos in the Buffer to the bytes represented by the Buffer b on the given offset and len.

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

    Parameters

    • pos: number
    • b: Buffer
    • offset: number
    • len: number

    Returns Buffer

setByte

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

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

    Parameters

    • pos: number
    • b: number

    Returns Buffer

setBytes

  • setBytes(pos: number, b: any): Buffer
  • setBytes(pos: number, b: number[]): Buffer
  • setBytes(pos: number, b: number[], offset: number, len: number): Buffer
  • Sets the bytes at position pos in the Buffer to the bytes represented by the ByteBuffer b.

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

    Parameters

    • pos: number
    • b: any

    Returns Buffer

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

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

    Parameters

    • pos: number
    • b: number[]

    Returns Buffer

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

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

    Parameters

    • pos: number
    • b: number[]
    • offset: number
    • len: number

    Returns Buffer

setDouble

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

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

    Parameters

    • pos: number
    • d: number

    Returns Buffer

setFloat

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

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

    Parameters

    • pos: number
    • f: number

    Returns Buffer

setInt

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

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

    Parameters

    • pos: number
    • i: number

    Returns Buffer

setIntLE

  • setIntLE(pos: number, i: number): Buffer
  • Sets the int at position pos in the Buffer to the value i in the Little Endian Byte Order.

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

    Parameters

    • pos: number
    • i: number

    Returns Buffer

setLong

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

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

    Parameters

    • pos: number
    • l: number

    Returns Buffer

setLongLE

  • setLongLE(pos: number, l: number): Buffer
  • Sets the long at position pos in the Buffer to the value l in the Little Endian Byte Order.

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

    Parameters

    • pos: number
    • l: number

    Returns Buffer

setMedium

  • setMedium(pos: number, i: number): Buffer
  • Sets the 24bit int at position pos in the Buffer to the value i.

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

    Parameters

    • pos: number
    • i: number

    Returns Buffer

setMediumLE

  • setMediumLE(pos: number, i: number): Buffer
  • Sets the 24bit int at position pos in the Buffer to the value i. in the Little Endian Byte Order

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

    Parameters

    • pos: number
    • i: number

    Returns Buffer

setShort

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

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

    Parameters

    • pos: number
    • s: number

    Returns Buffer

setShortLE

  • setShortLE(pos: number, s: number): Buffer
  • Sets the short at position pos in the Buffer to the value s in the Little Endian Byte Order.

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

    Parameters

    • pos: number
    • s: number

    Returns Buffer

setString

  • setString(pos: number, str: string): Buffer
  • setString(pos: number, str: string, enc: string): Buffer
  • Sets the bytes at position pos in the Buffer to the value of str encoded in UTF-8.

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

    Parameters

    • pos: number
    • str: string

    Returns Buffer

  • 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 accommodate any value written.

    Parameters

    • pos: number
    • str: string
    • enc: string

    Returns Buffer

setUnsignedByte

  • setUnsignedByte(pos: number, b: number): Buffer
  • Sets the unsigned byte at position pos in the Buffer to the value b.

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

    Parameters

    • pos: number
    • b: number

    Returns Buffer

setUnsignedInt

  • setUnsignedInt(pos: number, i: number): Buffer
  • Sets the unsigned int at position pos in the Buffer to the value i.

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

    Parameters

    • pos: number
    • i: number

    Returns Buffer

setUnsignedIntLE

  • setUnsignedIntLE(pos: number, i: number): Buffer
  • Sets the unsigned int at position pos in the Buffer to the value i in the Little Endian Byte Order.

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

    Parameters

    • pos: number
    • i: number

    Returns Buffer

setUnsignedShort

  • setUnsignedShort(pos: number, s: number): Buffer
  • Sets the unsigned short at position pos in the Buffer to the value s.

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

    Parameters

    • pos: number
    • s: number

    Returns Buffer

setUnsignedShortLE

  • setUnsignedShortLE(pos: number, s: number): Buffer
  • Sets the unsigned short at position pos in the Buffer to the value s in the Little Endian Byte Order.

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

    Parameters

    • pos: number
    • s: number

    Returns 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 Buffer

  • 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: number
    • end: number

    Returns Buffer

toJson

  • toJson(): any
  • Returns a Json representation of the Buffer.

    Returns any

toJsonArray

  • toJsonArray(): any[]
  • Returns a Json array representation of the Buffer.

    Returns any[]

toJsonObject

  • toJsonObject(): {}
  • Returns a Json object representation of the Buffer.

    Returns {}

    • [key: string]: any

toString

  • toString(): string
  • toString(enc: string): string
  • toString(enc: any): string
  • Returns a String representation of the Buffer with the UTF-8encoding

    Returns string

  • Returns a String representation of the Buffer with the encoding specified by enc

    Parameters

    • enc: string

    Returns string

  • Returns a String representation of the Buffer with the encoding specified by enc

    Parameters

    • enc: any

    Returns string

Static buffer

  • buffer(): Buffer
  • buffer(initialSizeHint: number): Buffer
  • buffer(string: string): Buffer
  • buffer(string: string, enc: string): Buffer
  • buffer(bytes: number[]): Buffer
  • buffer(byteBuf: any): Buffer
  • Create a new, empty buffer.

    Returns Buffer

  • 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: number

    Returns Buffer

  • Create a new buffer from a string. The string will be UTF-8 encoded into the buffer.

    Parameters

    • string: string

    Returns Buffer

  • 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: string
    • enc: string

    Returns Buffer

  • Create a new buffer from a byte[]. The byte[] will be copied to form the buffer.

    Parameters

    • bytes: number[]

    Returns Buffer

  • 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: any

    Returns Buffer

Generated using TypeDoc