Class Slice

java.lang.Object
io.airlift.slice.Slice
All Implemented Interfaces:
Comparable<Slice>

public final class Slice extends Object implements Comparable<Slice>
  • Method Summary

    Modifier and Type
    Method
    Description
    byte[]
    Returns the byte array wrapped by this Slice.
    int
    Returns the start index the content of this slice within the byte array wrapped by this slice.
    void
    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
    Compares the content of the specified buffer to the content of this buffer.
    Returns a copy of this buffer's sub-region.
    copy(int index, int length)
    Returns a copy of the specified region.
    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
    Compares the specified object with this slice for equality.
    void
    fill(byte value)
    Fill the slice with the specified value;
    byte
    getByte(int index)
    Gets a byte at the specified absolute index in this buffer.
    byte[]
    Returns a copy of this buffer as a byte array.
    void
    getBytes(int index, byte[] destination)
    Transfers a 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 a 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, Slice destination)
    Transfers a 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 a portion of data from this slice into the specified destination starting at the specified absolute index.
    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.
    byte
    getByteUnchecked(int index)
     
    double
    getDouble(int index)
    Gets a 64-bit double at the specified absolute index in this buffer.
    void
    getDoubles(int index, double[] destination)
    Transfers a portion of data from this slice into the specified destination starting at the specified absolute index.
    void
    getDoubles(int index, double[] destination, int destinationIndex, int length)
    Transfers a portion of data from this slice into the specified destination starting at the specified absolute index.
    double[]
    getDoubles(int index, int length)
    Returns a copy of this buffer as a double array.
    double
    getDoubleUnchecked(int index)
     
    float
    getFloat(int index)
    Gets a 32-bit float at the specified absolute index in this buffer.
    void
    getFloats(int index, float[] destination)
    Transfers a portion of data from this slice into the specified destination starting at the specified absolute index.
    void
    getFloats(int index, float[] destination, int destinationIndex, int length)
    Transfers a portion of data from this slice into the specified destination starting at the specified absolute index.
    float[]
    getFloats(int index, int length)
    Returns a copy of this buffer as a float array.
    float
    getFloatUnchecked(int index)
     
    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[]
    getInts(int index, int length)
    Returns a copy of this buffer as an int array.
    void
    getInts(int index, int[] destination)
    Transfers a portion of data from this slice into the specified destination starting at the specified absolute index.
    void
    getInts(int index, int[] destination, int destinationIndex, int length)
    Transfers a portion of data from this slice into the specified destination starting at the specified absolute index.
    int
    getIntUnchecked(int index)
     
    long
    getLong(int index)
    Gets a 64-bit long integer at the specified absolute index in this buffer.
    long[]
    getLongs(int index, int length)
    Returns a copy of this buffer as a long array.
    void
    getLongs(int index, long[] destination)
    Transfers a portion of data from this slice into the specified destination starting at the specified absolute index.
    void
    getLongs(int index, long[] destination, int destinationIndex, int length)
    Transfers a portion of data from this slice into the specified destination starting at the specified absolute index.
    long
    getLongUnchecked(int index)
     
    Creates a slice output backed by this slice.
    long
    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[]
    getShorts(int index, int length)
    Returns a copy of this buffer as a short array.
    void
    getShorts(int index, short[] destination)
    Transfers a portion of data from this slice into the specified destination starting at the specified absolute index.
    void
    getShorts(int index, short[] destination, int destinationIndex, int length)
    Transfers a portion of data from this slice into the specified destination starting at the specified absolute index.
    short
    getShortUnchecked(int index)
     
    short
    getUnsignedByte(int index)
    Gets an unsigned byte at the specified absolute index in this buffer.
    long
    getUnsignedInt(int index)
    Gets an unsigned 32-bit integer at the specified absolute index in this buffer.
    int
    getUnsignedShort(int index)
    Gets an unsigned 16-bit short integer at the specified absolute index in this slice.
    int
    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(byte b)
     
    int
    indexOfByte(int b)
     
    boolean
    A slice is considered compact if the base object is an array, and it contains the whole array.
    int
    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, 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
    setBytes(int index, InputStream in, int length)
    Transfers data from the specified input stream into this slice 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
    setDoubles(int index, double[] source)
    Transfers data from the specified slice into this buffer starting at the specified absolute index.
    void
    setDoubles(int index, double[] source, int sourceIndex, int length)
    Transfers data from the specified array into this buffer starting at the specified absolute index.
    void
    setFloat(int index, float value)
    Sets the specified 32-bit float at the specified absolute index in this buffer.
    void
    setFloats(int index, float[] source)
    Transfers data from the specified slice into this buffer starting at the specified absolute index.
    void
    setFloats(int index, float[] source, int sourceIndex, int length)
    Transfers data from the specified array into 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
    setInts(int index, int[] source)
    Transfers data from the specified slice into this buffer starting at the specified absolute index.
    void
    setInts(int index, int[] source, int sourceIndex, int length)
    Transfers data from the specified array into this buffer starting at the specified absolute index.
    void
    setLong(int index, long value)
    Sets the specified 64-bit long integer at the specified absolute index in this buffer.
    void
    setLongs(int index, long[] source)
    Transfers data from the specified slice into this buffer starting at the specified absolute index.
    void
    setLongs(int index, long[] source, int sourceIndex, int length)
    Transfers data from the specified array into this buffer starting at the specified absolute index.
    void
    setShort(int index, int value)
    Sets the specified 16-bit short integer at the specified absolute index in this buffer.
    void
    setShorts(int index, short[] source)
    Transfers data from the specified slice into this buffer starting at the specified absolute index.
    void
    setShorts(int index, short[] source, int sourceIndex, int length)
    Transfers data from the specified array into this buffer starting at the specified absolute index.
    slice(int index, int length)
    Returns a slice of this buffer's sub-region.
     
    toByteBuffer(int index, int length)
     
    Returns information about the slice offset, and length
    toString(int index, int length, Charset charset)
    Decodes the specified portion of this slice into a string with the specified character set name.
    toString(Charset charset)
    Decodes the contents of this slice into a string with the specified character set name.
    Decodes the contents of this slice into a string using the US_ASCII character set.
    toStringAscii(int index, int length)
     
    Decodes the contents of this slice into a string using the UTF-8 character set.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Method Details

    • length

      public int length()
      Length of this slice.
    • getRetainedSize

      public long getRetainedSize()
      Approximate number of bytes retained by this slice.
    • isCompact

      public boolean isCompact()
      A slice is considered compact if the base object is an array, and it contains the whole array. As a result, it cannot be a view of a bigger slice.
    • byteArray

      public byte[] byteArray()
      Returns the byte array wrapped by this Slice. Callers should also take care to use byteArrayOffset() since the contents of this Slice may not start at array index 0.
    • byteArrayOffset

      public int byteArrayOffset()
      Returns the start index the content of this slice within the byte array wrapped by this slice.
    • fill

      public void fill(byte value)
      Fill the slice with the specified value;
    • clear

      public void clear()
      Fill the slice with zeros;
    • clear

      public void clear(int offset, int length)
    • getByte

      public byte getByte(int index)
      Gets a byte at the specified absolute index in this buffer.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 1 is greater than this.length()
    • getByteUnchecked

      public byte getByteUnchecked(int index)
    • getUnsignedByte

      public short getUnsignedByte(int index)
      Gets an unsigned byte at the specified absolute index in this buffer.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 1 is greater than this.length()
    • getShort

      public short getShort(int index)
      Gets a 16-bit short integer at the specified absolute index in this slice.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 2 is greater than this.length()
    • getShortUnchecked

      public short getShortUnchecked(int index)
    • getUnsignedShort

      public int getUnsignedShort(int index)
      Gets an unsigned 16-bit short integer at the specified absolute index in this slice.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 2 is greater than this.length()
    • getInt

      public int getInt(int index)
      Gets a 32-bit integer at the specified absolute index in this buffer.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 4 is greater than this.length()
    • getIntUnchecked

      public int getIntUnchecked(int index)
    • getUnsignedInt

      public long getUnsignedInt(int index)
      Gets an unsigned 32-bit integer at the specified absolute index in this buffer.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 4 is greater than this.length()
    • getLong

      public long getLong(int index)
      Gets a 64-bit long integer at the specified absolute index in this buffer.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 8 is greater than this.length()
    • getLongUnchecked

      public long getLongUnchecked(int index)
    • getFloat

      public float getFloat(int index)
      Gets a 32-bit float at the specified absolute index in this buffer.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 4 is greater than this.length()
    • getFloatUnchecked

      public float getFloatUnchecked(int index)
    • getDouble

      public double getDouble(int index)
      Gets a 64-bit double at the specified absolute index in this buffer.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 8 is greater than this.length()
    • getDoubleUnchecked

      public double getDoubleUnchecked(int index)
    • getBytes

      public void getBytes(int index, Slice destination)
      Transfers a portion of data from this slice into the specified destination starting at the specified absolute index.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0, or if index + destination.length() is greater than this.length()
    • getBytes

      public void getBytes(int index, Slice destination, int destinationIndex, int length)
      Transfers a portion of data from this slice into the specified destination starting at the specified absolute index.
      Parameters:
      destinationIndex - the first index of the destination
      length - the number of bytes to transfer
      Throws:
      IndexOutOfBoundsException - 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()
    • getBytes

      public void getBytes(int index, byte[] destination)
      Transfers a portion of data from this slice into the specified destination starting at the specified absolute index.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0, or if index + destination.length is greater than this.length()
    • getBytes

      public void getBytes(int index, byte[] destination, int destinationIndex, int length)
      Transfers a portion of data from this slice into the specified destination starting at the specified absolute index.
      Parameters:
      destinationIndex - the first index of the destination
      length - the number of bytes to transfer
      Throws:
      IndexOutOfBoundsException - 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
    • getBytes

      public byte[] getBytes()
      Returns a copy of this buffer as a byte array.
    • getBytes

      public byte[] getBytes(int index, int length)
      Returns a copy of this buffer as a byte array.
      Parameters:
      index - the absolute index to start at
      length - the number of bytes to return
      Throws:
      IndexOutOfBoundsException - if the specified index is less then 0, or if the specified index + length is greater than this.length()
    • getBytes

      public void getBytes(int index, OutputStream out, int length) throws IOException
      Transfers a portion of data from this slice into the specified stream starting at the specified absolute index.
      Parameters:
      length - the number of bytes to transfer
      Throws:
      IndexOutOfBoundsException - 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/O
    • getShorts

      public short[] getShorts(int index, int length)
      Returns a copy of this buffer as a short array.
      Parameters:
      index - the absolute index to start at
      length - the number of shorts to return
      Throws:
      IndexOutOfBoundsException - if the specified index is less then 0, or if the specified index + length is greater than this.length()
    • getShorts

      public void getShorts(int index, short[] destination)
      Transfers a portion of data from this slice into the specified destination starting at the specified absolute index.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0, or if index + destination.length is greater than this.length()
    • getShorts

      public void getShorts(int index, short[] destination, int destinationIndex, int length)
      Transfers a portion of data from this slice into the specified destination starting at the specified absolute index.
      Parameters:
      destinationIndex - the first index of the destination
      length - the number of shorts to transfer
      Throws:
      IndexOutOfBoundsException - 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
    • getInts

      public int[] getInts(int index, int length)
      Returns a copy of this buffer as an int array.
      Parameters:
      index - the absolute index to start at
      length - the number of ints to return
      Throws:
      IndexOutOfBoundsException - if the specified index is less then 0, or if the specified index + length is greater than this.length()
    • getInts

      public void getInts(int index, int[] destination)
      Transfers a portion of data from this slice into the specified destination starting at the specified absolute index.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0, or if index + destination.length is greater than this.length()
    • getInts

      public void getInts(int index, int[] destination, int destinationIndex, int length)
      Transfers a portion of data from this slice into the specified destination starting at the specified absolute index.
      Parameters:
      destinationIndex - the first index of the destination
      length - the number of ints to transfer
      Throws:
      IndexOutOfBoundsException - 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
    • getLongs

      public long[] getLongs(int index, int length)
      Returns a copy of this buffer as a long array.
      Parameters:
      index - the absolute index to start at
      length - the number of longs to return
      Throws:
      IndexOutOfBoundsException - if the specified index is less then 0, or if the specified index + length is greater than this.length()
    • getLongs

      public void getLongs(int index, long[] destination)
      Transfers a portion of data from this slice into the specified destination starting at the specified absolute index.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0, or if index + destination.length is greater than this.length()
    • getLongs

      public void getLongs(int index, long[] destination, int destinationIndex, int length)
      Transfers a portion of data from this slice into the specified destination starting at the specified absolute index.
      Parameters:
      destinationIndex - the first index of the destination
      length - the number of longs to transfer
      Throws:
      IndexOutOfBoundsException - 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
    • getFloats

      public float[] getFloats(int index, int length)
      Returns a copy of this buffer as a float array.
      Parameters:
      index - the absolute index to start at
      length - the number of floats to return
      Throws:
      IndexOutOfBoundsException - if the specified index is less then 0, or if the specified index + length is greater than this.length()
    • getFloats

      public void getFloats(int index, float[] destination)
      Transfers a portion of data from this slice into the specified destination starting at the specified absolute index.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0, or if index + destination.length is greater than this.length()
    • getFloats

      public void getFloats(int index, float[] destination, int destinationIndex, int length)
      Transfers a portion of data from this slice into the specified destination starting at the specified absolute index.
      Parameters:
      destinationIndex - the first index of the destination
      length - the number of floats to transfer
      Throws:
      IndexOutOfBoundsException - 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
    • getDoubles

      public double[] getDoubles(int index, int length)
      Returns a copy of this buffer as a double array.
      Parameters:
      index - the absolute index to start at
      length - the number of doubles to return
      Throws:
      IndexOutOfBoundsException - if the specified index is less then 0, or if the specified index + length is greater than this.length()
    • getDoubles

      public void getDoubles(int index, double[] destination)
      Transfers a portion of data from this slice into the specified destination starting at the specified absolute index.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0, or if index + destination.length is greater than this.length()
    • getDoubles

      public void getDoubles(int index, double[] destination, int destinationIndex, int length)
      Transfers a portion of data from this slice into the specified destination starting at the specified absolute index.
      Parameters:
      destinationIndex - the first index of the destination
      length - the number of doubles to transfer
      Throws:
      IndexOutOfBoundsException - 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
    • setByte

      public void setByte(int index, int value)
      Sets the specified byte at the specified absolute index in this buffer. The 24 high-order bits of the specified value are ignored.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 1 is greater than this.length()
    • setShort

      public void setShort(int index, int value)
      Sets the specified 16-bit short integer at the specified absolute index in this buffer. The 16 high-order bits of the specified value are ignored.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 2 is greater than this.length()
    • setInt

      public void setInt(int index, int value)
      Sets the specified 32-bit integer at the specified absolute index in this buffer.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 4 is greater than this.length()
    • setLong

      public void setLong(int index, long value)
      Sets the specified 64-bit long integer at the specified absolute index in this buffer.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 8 is greater than this.length()
    • setFloat

      public void setFloat(int index, float value)
      Sets the specified 32-bit float at the specified absolute index in this buffer.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 4 is greater than this.length()
    • setDouble

      public void setDouble(int index, double value)
      Sets the specified 64-bit double at the specified absolute index in this buffer.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0 or index + 8 is greater than this.length()
    • setBytes

      public void setBytes(int index, Slice source)
      Transfers data from the specified slice into this buffer starting at the specified absolute index.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0, or if index + source.length() is greater than this.length()
    • setBytes

      public 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.
      Parameters:
      sourceIndex - the first index of the source
      length - the number of bytes to transfer
      Throws:
      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()
    • setBytes

      public void setBytes(int index, byte[] source)
      Transfers data from the specified slice into this buffer starting at the specified absolute index.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0, or if index + source.length is greater than this.length()
    • setBytes

      public 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.
      Throws:
      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
    • setBytes

      public void setBytes(int index, InputStream in, int length) throws IOException
      Transfers data from the specified input stream into this slice starting at the specified absolute index.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0, or if index + source.length is greater than this.length()
      IOException
    • setShorts

      public void setShorts(int index, short[] source)
      Transfers data from the specified slice into this buffer starting at the specified absolute index.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0, or if index + source.length is greater than this.length()
    • setShorts

      public void setShorts(int index, short[] source, int sourceIndex, int length)
      Transfers data from the specified array into this buffer starting at the specified absolute index.
      Throws:
      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
    • setInts

      public void setInts(int index, int[] source)
      Transfers data from the specified slice into this buffer starting at the specified absolute index.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0, or if index + source.length is greater than this.length()
    • setInts

      public void setInts(int index, int[] source, int sourceIndex, int length)
      Transfers data from the specified array into this buffer starting at the specified absolute index.
      Throws:
      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
    • setLongs

      public void setLongs(int index, long[] source)
      Transfers data from the specified slice into this buffer starting at the specified absolute index.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0, or if index + source.length is greater than this.length()
    • setLongs

      public void setLongs(int index, long[] source, int sourceIndex, int length)
      Transfers data from the specified array into this buffer starting at the specified absolute index.
      Throws:
      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
    • setFloats

      public void setFloats(int index, float[] source)
      Transfers data from the specified slice into this buffer starting at the specified absolute index.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0, or if index + source.length is greater than this.length()
    • setFloats

      public void setFloats(int index, float[] source, int sourceIndex, int length)
      Transfers data from the specified array into this buffer starting at the specified absolute index.
      Throws:
      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
    • setDoubles

      public void setDoubles(int index, double[] source)
      Transfers data from the specified slice into this buffer starting at the specified absolute index.
      Throws:
      IndexOutOfBoundsException - if the specified index is less than 0, or if index + source.length is greater than this.length()
    • setDoubles

      public void setDoubles(int index, double[] source, int sourceIndex, int length)
      Transfers data from the specified array into this buffer starting at the specified absolute index.
      Throws:
      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
    • slice

      public Slice slice(int index, int length)
      Returns a slice of this buffer's sub-region. Modifying the content of the returned buffer, or this buffer affects each other's content.
    • copy

      public Slice copy()
      Returns a copy of this buffer's sub-region. Modifying the content of the returned buffer does not affect this buffer, and vice versa.
    • copy

      public Slice copy(int index, int length)
      Returns a copy of the specified region. Modifying the content of the returned buffer does not affect this buffer, and vice versa.
    • indexOfByte

      public int indexOfByte(int b)
    • indexOfByte

      public int indexOfByte(byte b)
    • indexOf

      public int indexOf(Slice slice)
      Returns the index of the first occurrence of the pattern with this slice. If the pattern is not found -1 is returned. If patten is empty, zero is returned.
    • indexOf

      public int indexOf(Slice pattern, int offset)
      Returns the index of the first occurrence of the pattern with this slice. If the pattern is not found -1 is returned. If patten is empty, the offset is returned.
    • compareTo

      public int compareTo(Slice that)
      Compares the content of the specified buffer to the content of this buffer. This comparison is performed byte by byte using an unsigned comparison.
      Specified by:
      compareTo in interface Comparable<Slice>
    • compareTo

      public 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. Equality is solely based on the contents of the slice.
    • equals

      public boolean equals(Object o)
      Compares the specified object with this slice for equality. Equality is solely based on the contents of the slice.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Returns the hash code of this slice. The hash code is cached once calculated, and any future changes to the slice will not affect the hash code.
      Overrides:
      hashCode in class Object
    • hashCode

      public int hashCode(int offset, int length)
      Returns the hash code of a portion of this slice.
    • equals

      public 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. Equality is solely based on the contents of the slice.
    • getInput

      public BasicSliceInput getInput()
      Creates a slice input backed by this slice. Any changes to this slice will be immediately visible to the slice input.
    • getOutput

      public SliceOutput getOutput()
      Creates a slice output backed by this slice. Any data written to the slice output will be immediately visible in this slice.
    • toString

      public String toString(Charset charset)
      Decodes the contents of this slice into a string with the specified character set name.
    • toStringUtf8

      public String toStringUtf8()
      Decodes the contents of this slice into a string using the UTF-8 character set.
    • toStringAscii

      public String toStringAscii()
      Decodes the contents of this slice into a string using the US_ASCII character set. The low-order 7 bits of each byte are converted directly into a code point for the string.
    • toStringAscii

      public String toStringAscii(int index, int length)
    • toString

      public String toString(int index, int length, Charset charset)
      Decodes the specified portion of this slice into a string with the specified character set name.
    • toByteBuffer

      public ByteBuffer toByteBuffer()
    • toByteBuffer

      public ByteBuffer toByteBuffer(int index, int length)
    • toString

      public String toString()
      Returns information about the slice offset, and length
      Overrides:
      toString in class Object