Interface BytesReference

All Superinterfaces:
Comparable<BytesReference>, org.elasticsearch.xcontent.ToXContent, org.elasticsearch.xcontent.ToXContentFragment
All Known Implementing Classes:
AbstractBytesReference, BytesArray, CompositeBytesReference, PagedBytesReference, ReleasableBytesReference

public interface BytesReference extends Comparable<BytesReference>, org.elasticsearch.xcontent.ToXContentFragment
A reference to bytes.
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.elasticsearch.xcontent.ToXContent

    org.elasticsearch.xcontent.ToXContent.DelegatingMapParams, org.elasticsearch.xcontent.ToXContent.MapParams, org.elasticsearch.xcontent.ToXContent.Params
  • Field Summary

    Fields inherited from interface org.elasticsearch.xcontent.ToXContent

    EMPTY_PARAMS
  • Method Summary

    Modifier and Type
    Method
    Description
    default byte[]
     
    default int
     
    bytes(org.elasticsearch.xcontent.XContentBuilder xContentBuilder)
    Convert an XContentBuilder into a BytesReference.
    fromByteArray(ByteArray byteArray, int length)
    Returns BytesReference either wrapping the provided ByteArray or in case the has a backing raw byte array one that wraps that backing array directly.
    Returns BytesReference composed of the provided ByteBuffer.
    Returns BytesReference composed of the provided ByteBuffers.
    byte
    get(int index)
    Returns the byte at the specified index.
    int
    getInt(int index)
    Returns the integer read from the 4 bytes (BE) starting at the given index.
    default boolean
     
    int
    indexOf(byte marker, int from)
    Finds the index of the first occurrence of the given marker between within the given bounds.
    org.apache.lucene.util.BytesRefIterator
    Returns a BytesRefIterator for this BytesReference.
    int
    The length.
    long
    The amount of memory used by this BytesReference
    slice(int from, int length)
    Slice the bytes from the from index up to length.
    A stream input of the bytes.
    static ByteBuffer[]
    Returns an array of byte buffers from the given BytesReference.
    static byte[]
    Returns a compact array from the given BytesReference.
    org.apache.lucene.util.BytesRef
    Converts to Lucene BytesRef.
    Interprets the referenced bytes as UTF8 bytes, returning the resulting string
    void
    Writes the bytes directly to the output stream.

    Methods inherited from interface java.lang.Comparable

    compareTo

    Methods inherited from interface org.elasticsearch.xcontent.ToXContent

    toXContent

    Methods inherited from interface org.elasticsearch.xcontent.ToXContentFragment

    isFragment
  • Method Details

    • bytes

      static BytesReference bytes(org.elasticsearch.xcontent.XContentBuilder xContentBuilder)
      Convert an XContentBuilder into a BytesReference. This method closes the builder, so no further fields may be added.
    • toBytes

      static byte[] toBytes(BytesReference reference)
      Returns a compact array from the given BytesReference. The returned array won't be copied unless necessary. If you need to modify the returned array use BytesRef.deepCopyOf(reference.toBytesRef() instead
    • toByteBuffers

      static ByteBuffer[] toByteBuffers(BytesReference reference)
      Returns an array of byte buffers from the given BytesReference.
    • fromByteBuffers

      static BytesReference fromByteBuffers(ByteBuffer[] buffers)
      Returns BytesReference composed of the provided ByteBuffers.
    • fromByteBuffer

      static BytesReference fromByteBuffer(ByteBuffer buffer)
      Returns BytesReference composed of the provided ByteBuffer.
    • fromByteArray

      static BytesReference fromByteArray(ByteArray byteArray, int length)
      Returns BytesReference either wrapping the provided ByteArray or in case the has a backing raw byte array one that wraps that backing array directly.
    • get

      byte get(int index)
      Returns the byte at the specified index. Need to be between 0 and length.
    • getInt

      int getInt(int index)
      Returns the integer read from the 4 bytes (BE) starting at the given index.
    • indexOf

      int indexOf(byte marker, int from)
      Finds the index of the first occurrence of the given marker between within the given bounds.
      Parameters:
      marker - marker byte to search
      from - lower bound for the index to check (inclusive)
      Returns:
      first index of the marker or -1 if not found
    • length

      int length()
      The length.
    • slice

      BytesReference slice(int from, int length)
      Slice the bytes from the from index up to length.
    • ramBytesUsed

      long ramBytesUsed()
      The amount of memory used by this BytesReference
    • streamInput

      StreamInput streamInput() throws IOException
      A stream input of the bytes.
      Throws:
      IOException
    • writeTo

      void writeTo(OutputStream os) throws IOException
      Writes the bytes directly to the output stream.
      Throws:
      IOException
    • utf8ToString

      String utf8ToString()
      Interprets the referenced bytes as UTF8 bytes, returning the resulting string
    • toBytesRef

      org.apache.lucene.util.BytesRef toBytesRef()
      Converts to Lucene BytesRef.
    • iterator

      org.apache.lucene.util.BytesRefIterator iterator()
      Returns a BytesRefIterator for this BytesReference. This method allows access to the internal pages of this reference without copying them. Use with care!
      See Also:
      • BytesRefIterator
    • hasArray

      default boolean hasArray()
      Returns:
      true if this instance is backed by a byte array
    • array

      default byte[] array()
      Returns:
      backing byte array for this instance
    • arrayOffset

      default int arrayOffset()
      Returns:
      offset of the first byte of this instance in the backing byte array