public final class Slice extends Object implements Comparable<Slice>
Modifier and Type | Method and Description |
---|---|
void |
clear()
Fill the slice with zeros;
|
void |
clear(int offset,
int length) |
int |
compareTo(int offset,
int length,
Slice that,
int otherOffset,
int otherLength)
Compares a portion of this slice with a portion of the specified slice.
|
int |
compareTo(Slice that)
Compares the content of the specified buffer to the content of this
buffer.
|
boolean |
equals(int offset,
int length,
Slice that,
int otherOffset,
int otherLength)
Compares a portion of this slice with a portion of the specified slice.
|
boolean |
equals(Object o)
Compares the specified object with this slice for equality.
|
void |
fill(byte value)
Fill the slice with the specified value;
|
long |
getAddress()
Return the address offset of this Slice.
|
Object |
getBase()
Returns the base object of this Slice, or null.
|
byte |
getByte(int index)
Gets a byte at the specified absolute
index in this buffer. |
byte[] |
getBytes()
Returns a copy of this buffer as a byte array.
|
void |
getBytes(int index,
byte[] destination)
Transfers portion of data from this slice into the specified destination starting at
the specified absolute
index . |
void |
getBytes(int index,
byte[] destination,
int destinationIndex,
int length)
Transfers portion of data from this slice into the specified destination starting at
the specified absolute
index . |
byte[] |
getBytes(int index,
int length)
Returns a copy of this buffer as a byte array.
|
void |
getBytes(int index,
OutputStream out,
int length)
Transfers a portion of data from this slice into the specified stream starting at the
specified absolute
index . |
void |
getBytes(int index,
Slice destination)
Transfers portion of data from this slice into the specified destination starting at
the specified absolute
index . |
void |
getBytes(int index,
Slice destination,
int destinationIndex,
int length)
Transfers portion of data from this slice into the specified destination starting at
the specified absolute
index . |
double |
getDouble(int index)
Gets a 64-bit double at the specified absolute
index in
this buffer. |
float |
getFloat(int index)
Gets a 32-bit float at the specified absolute
index in
this buffer. |
BasicSliceInput |
getInput()
Creates a slice input backed by this slice.
|
int |
getInt(int index)
Gets a 32-bit integer at the specified absolute
index in
this buffer. |
int |
getIntUnchecked(int index) |
long |
getLong(int index)
Gets a 64-bit long integer at the specified absolute
index in
this buffer. |
SliceOutput |
getOutput()
Creates a slice output backed by this slice.
|
int |
getRetainedSize()
Approximate number of bytes retained by this slice.
|
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()
Returns the hash code of this slice.
|
int |
hashCode(int offset,
int length)
Returns the hash code of a portion of this slice.
|
int |
indexOf(Slice slice)
Returns the index of the first occurrence of the pattern with this slice.
|
int |
indexOf(Slice pattern,
int offset)
Returns the index of the first occurrence of the pattern with this slice.
|
int |
indexOfByte(int b) |
int |
length()
Length of 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)
Transfers data from the specified slice into this buffer starting at
the specified absolute
index . |
void |
setBytes(int index,
byte[] source,
int sourceIndex,
int length)
Transfers data from the specified array into this buffer starting at
the specified absolute
index . |
void |
setBytes(int index,
InputStream in,
int length)
Transfers data from the specified input stream into this slice starting at
the specified absolute
index . |
void |
setBytes(int index,
Slice source)
Transfers data from the specified slice into this buffer starting at
the specified absolute
index . |
void |
setBytes(int index,
Slice source,
int sourceIndex,
int length)
Transfers data from the specified slice into this buffer starting at
the specified absolute
index . |
void |
setDouble(int index,
double value)
Sets the specified 64-bit double at the specified absolute
index in this buffer. |
void |
setFloat(int index,
float value)
Sets the specified 32-bit float at the specified absolute
index in this buffer. |
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(int index,
int length)
Returns a slice of this buffer's sub-region.
|
ByteBuffer |
toByteBuffer() |
ByteBuffer |
toByteBuffer(int index,
int length) |
String |
toString()
Decodes the a portion of this slice into a string with the specified
character set name.
|
String |
toString(Charset charset)
Decodes the contents of this slice into a string with the specified
character set name.
|
String |
toString(int index,
int length,
Charset charset)
Decodes the a portion of this slice into a string with the specified
character set name.
|
String |
toStringAscii()
Decodes the contents of this slice into a string using the US_ASCII
character set.
|
String |
toStringAscii(int index,
int length) |
String |
toStringUtf8()
Decodes the contents of this slice into a string using the UTF-8
character set.
|
static Slice |
toUnsafeSlice(ByteBuffer byteBuffer)
Deprecated.
|
@Deprecated public static Slice toUnsafeSlice(ByteBuffer byteBuffer)
Slices.wrappedBuffer(java.nio.ByteBuffer)
public Object getBase()
Unsafe
if you wish to avoid all the safety belts e.g. bounds checks.public long getAddress()
Unsafe
if you wish to avoid all the safety belts e.g. bounds checks.public int length()
public int getRetainedSize()
public void fill(byte value)
public void clear()
public void clear(int offset, int length)
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.length()
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.length()
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.length()
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.length()
public int getIntUnchecked(int index)
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.length()
public float getFloat(int index)
index
in
this buffer.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 4
is greater than this.length()
public double getDouble(int index)
index
in
this buffer.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 8
is greater than this.length()
public void getBytes(int index, Slice destination)
index
.IndexOutOfBoundsException
- if the specified index
is less than 0
, or
if index + destination.length()
is greater than this.length()
public void getBytes(int index, Slice 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 destinationIndex
is less than 0
,
if index + length
is greater than
this.length()
, or
if destinationIndex + length
is greater than
destination.length()
public void getBytes(int index, byte[] destination)
index
.IndexOutOfBoundsException
- if the specified index
is less than 0
, or
if index + destination.length
is greater than this.length()
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 destinationIndex
is less than 0
,
if index + length
is greater than
this.length()
, or
if destinationIndex + length
is greater than
destination.length
public byte[] getBytes()
public byte[] getBytes(int index, int length)
index
- the absolute index to start atlength
- the number of bytes to returnIndexOutOfBoundsException
- if the specified index
is less then 0
,
or if the specified index + length
is greater than this.length()
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.length()
IOException
- if the specified stream threw an exception during I/Opublic 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.length()
public 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.length()
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.length()
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.length()
public void setFloat(int index, float value)
index
in this buffer.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 4
is greater than this.length()
public void setDouble(int index, double value)
index
in this buffer.IndexOutOfBoundsException
- if the specified index
is less than 0
or
index + 8
is greater than this.length()
public void setBytes(int index, Slice source)
index
.IndexOutOfBoundsException
- if the specified index
is less than 0
, or
if index + source.length()
is greater than this.length()
public void setBytes(int index, Slice source, int sourceIndex, int length)
index
.sourceIndex
- the first index of the sourcelength
- the number of bytes to transferIndexOutOfBoundsException
- if the specified index
is less than 0
,
if the specified sourceIndex
is less than 0
,
if index + length
is greater than
this.length()
, or
if sourceIndex + length
is greater than
source.length()
public void setBytes(int index, byte[] source)
index
.IndexOutOfBoundsException
- if the specified index
is less than 0
, or
if index + source.length
is greater than this.length()
public void setBytes(int index, byte[] source, int sourceIndex, int length)
index
.IndexOutOfBoundsException
- if the specified index
is less than 0
,
if the specified sourceIndex
is less than 0
,
if index + length
is greater than
this.length()
, or
if sourceIndex + length
is greater than source.length
public void setBytes(int index, InputStream in, int length) throws IOException
index
.IndexOutOfBoundsException
- if the specified index
is less than 0
, or
if index + source.length
is greater than this.length()
IOException
public Slice slice(int index, int length)
public int indexOfByte(int b)
public int indexOf(Slice slice)
public int indexOf(Slice pattern, int offset)
public int compareTo(Slice that)
compareTo
in interface Comparable<Slice>
public int compareTo(int offset, int length, Slice that, int otherOffset, int otherLength)
public boolean equals(Object o)
public int hashCode()
public int hashCode(int offset, int length)
public boolean equals(int offset, int length, Slice that, int otherOffset, int otherLength)
public BasicSliceInput getInput()
public SliceOutput getOutput()
public String toString(Charset charset)
public String toStringUtf8()
public String toStringAscii()
public String toStringAscii(int index, int length)
public String toString(int index, int length, Charset charset)
public ByteBuffer toByteBuffer()
public ByteBuffer toByteBuffer(int index, int length)
Copyright © 2012-2016. All Rights Reserved.