public final class Slice extends Object implements Comparable<Slice>
Constructor and Description |
---|
Slice(byte[] data) |
Slice(byte[] data,
int offset,
int length) |
Slice(int length) |
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Slice that)
Compares the content of the specified buffer to the content of this
buffer.
|
byte[] |
copyBytes() |
byte[] |
copyBytes(int index,
int length) |
Slice |
copySlice() |
Slice |
copySlice(int index,
int length)
Returns a copy of this buffer's sub-region.
|
boolean |
equals(Object o) |
byte |
getByte(int index)
Gets a byte at the specified absolute
index in this buffer. |
byte[] |
getBytes() |
void |
getBytes(int index,
byte[] destination,
int destinationIndex,
int length)
Transfers this buffer's data to the specified destination starting at
the specified absolute
index . |
void |
getBytes(int index,
ByteBuffer destination)
Transfers this buffer's data to the specified destination starting at
the specified absolute
index until the destination's position
reaches its limit. |
int |
getBytes(int index,
GatheringByteChannel out,
int length)
Transfers this buffer's data to the specified channel starting at the
specified absolute
index . |
byte[] |
getBytes(int index,
int length) |
void |
getBytes(int index,
OutputStream out,
int length)
Transfers this buffer's data to the specified stream starting at the
specified absolute
index . |
void |
getBytes(int index,
Slice dst,
int dstIndex,
int length)
Transfers this buffer's data to the specified destination starting at
the specified absolute
index . |
int |
getInt(int index)
Gets a 32-bit integer at the specified absolute
index in
this buffer. |
long |
getLong(int index)
Gets a 64-bit long integer at the specified absolute
index in
this buffer. |
byte[] |
getRawArray()
Gets the array underlying this slice.
|
int |
getRawOffset()
Gets the offset of this slice in the underlying array.
|
short |
getShort(int index)
Gets a 16-bit short integer at the specified absolute
index in
this slice. |
short |
getUnsignedByte(int index)
Gets an unsigned byte at the specified absolute
index in this
buffer. |
int |
hashCode() |
SliceInput |
input()
Creates an input stream over this slice.
|
int |
length()
Length of this slice.
|
SliceOutput |
output()
Creates an output stream over this slice.
|
void |
setByte(int index,
int value)
Sets the specified byte at the specified absolute
index in this
buffer. |
void |
setBytes(int index,
byte[] source,
int sourceIndex,
int length)
Transfers the specified source array's data to this buffer starting at
the specified absolute
index . |
void |
setBytes(int index,
ByteBuffer source)
Transfers the specified source buffer's data to this buffer starting at
the specified absolute
index until the source buffer's position
reaches its limit. |
int |
setBytes(int index,
FileChannel in,
int position,
int length) |
int |
setBytes(int index,
InputStream in,
int length)
Transfers the content of the specified source stream to this buffer
starting at the specified absolute
index . |
int |
setBytes(int index,
ScatteringByteChannel in,
int length)
Transfers the content of the specified source channel to this buffer
starting at the specified absolute
index . |
void |
setBytes(int index,
Slice src,
int srcIndex,
int length)
Transfers the specified source buffer's data to this buffer starting at
the specified absolute
index . |
void |
setInt(int index,
int value)
Sets the specified 32-bit integer at the specified absolute
index in this buffer. |
void |
setLong(int index,
long value)
Sets the specified 64-bit long integer at the specified absolute
index in this buffer. |
void |
setShort(int index,
int value)
Sets the specified 16-bit short integer at the specified absolute
index in this buffer. |
Slice |
slice()
Returns a slice of this buffer's readable bytes.
|
Slice |
slice(int index,
int length)
Returns a slice of this buffer's sub-region.
|
ByteBuffer |
toByteBuffer()
Converts this buffer's readable bytes into a NIO buffer.
|
ByteBuffer |
toByteBuffer(int index,
int length)
Converts this buffer's sub-region into a NIO buffer.
|
String |
toString() |
String |
toString(Charset charset)
Decodes this buffer's readable bytes into a string with the specified
character set name.
|
String |
toString(int index,
int length,
Charset charset)
Decodes this buffer's sub-region into a string with the specified
character set.
|
public Slice(int length)
public Slice(byte[] data)
public Slice(byte[] data, int offset, int length)
public int length()
public byte[] getRawArray()
public int getRawOffset()
public byte getByte(int index)
index
in this buffer.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 1
is greater than this.capacity
public short getUnsignedByte(int index)
index
in this
buffer.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 1
is greater than this.capacity
public short getShort(int index)
index
in
this slice.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 2
is greater than this.capacity
public int getInt(int index)
index
in
this buffer.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 4
is greater than this.capacity
public long getLong(int index)
index
in
this buffer.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 8
is greater than this.capacity
public void getBytes(int index, Slice dst, int dstIndex, int length)
index
.dstIndex
- the first index of the destinationlength
- the number of bytes to transferIndexOutOfBoundsException
- if the specified index
is less than 0
,
if the specified dstIndex
is less than 0
,
if index + length
is greater than
this.capacity
, or
if dstIndex + length
is greater than
dst.capacity
public void getBytes(int index, byte[] destination, int destinationIndex, int length)
index
.destinationIndex
- the first index of the destinationlength
- the number of bytes to transferIndexOutOfBoundsException
- if the specified index
is less than 0
,
if the specified dstIndex
is less than 0
,
if index + length
is greater than
this.capacity
, or
if dstIndex + length
is greater than
dst.length
public byte[] getBytes()
public byte[] getBytes(int index, int length)
public void getBytes(int index, ByteBuffer destination)
index
until the destination's position
reaches its limit.IndexOutOfBoundsException
- if the specified index
is less than 0
or
if index + dst.remaining()
is greater than
this.capacity
public void getBytes(int index, OutputStream out, int length) throws IOException
index
.length
- the number of bytes to transferIndexOutOfBoundsException
- if the specified index
is less than 0
or
if index + length
is greater than
this.capacity
IOException
- if the specified stream threw an exception during I/Opublic int getBytes(int index, GatheringByteChannel out, int length) throws IOException
index
.length
- the maximum number of bytes to transferIndexOutOfBoundsException
- if the specified index
is less than 0
or
if index + length
is greater than
this.capacity
IOException
- if the specified channel threw an exception during I/Opublic void setShort(int index, int value)
index
in this buffer. The 16 high-order bits of the specified
value are ignored.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 2
is greater than this.capacity
public void setInt(int index, int value)
index
in this buffer.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 4
is greater than this.capacity
public void setLong(int index, long value)
index
in this buffer.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 8
is greater than this.capacity
public void setByte(int index, int value)
index
in this
buffer. The 24 high-order bits of the specified value are ignored.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 1
is greater than this.capacity
public void setBytes(int index, Slice src, int srcIndex, int length)
index
.srcIndex
- the first index of the sourcelength
- the number of bytes to transferIndexOutOfBoundsException
- if the specified index
is less than 0
,
if the specified srcIndex
is less than 0
,
if index + length
is greater than
this.capacity
, or
if srcIndex + length
is greater than
src.capacity
public void setBytes(int index, byte[] source, int sourceIndex, int length)
index
.IndexOutOfBoundsException
- if the specified index
is less than 0
,
if the specified srcIndex
is less than 0
,
if index + length
is greater than
this.capacity
, or
if srcIndex + length
is greater than src.length
public void setBytes(int index, ByteBuffer source)
index
until the source buffer's position
reaches its limit.IndexOutOfBoundsException
- if the specified index
is less than 0
or
if index + src.remaining()
is greater than
this.capacity
public int setBytes(int index, InputStream in, int length) throws IOException
index
.length
- the number of bytes to transfer-1
if the specified channel is closed.IndexOutOfBoundsException
- if the specified index
is less than 0
or
if index + length
is greater than this.capacity
IOException
- if the specified stream threw an exception during I/Opublic int setBytes(int index, ScatteringByteChannel in, int length) throws IOException
index
.length
- the maximum number of bytes to transfer-1
if the specified channel is closed.IndexOutOfBoundsException
- if the specified index
is less than 0
or
if index + length
is greater than this.capacity
IOException
- if the specified channel threw an exception during I/Opublic int setBytes(int index, FileChannel in, int position, int length) throws IOException
IOException
public Slice copySlice()
public Slice copySlice(int index, int length)
public byte[] copyBytes()
public byte[] copyBytes(int index, int length)
public Slice slice()
public Slice slice(int index, int length)
public SliceInput input()
public SliceOutput output()
public ByteBuffer toByteBuffer()
public ByteBuffer toByteBuffer(int index, int length)
public int compareTo(Slice that)
compareTo
in interface Comparable<Slice>
public String toString(Charset charset)
public String toString(int index, int length, Charset charset)
Copyright © 2011–2019. All rights reserved.