Class ReleasableBytesReference

org.elasticsearch.common.bytes.ReleasableBytesReference
All Implemented Interfaces:
, , <BytesReference>, BytesReference, org.elasticsearch.common.xcontent.ToXContent, org.elasticsearch.common.xcontent.ToXContentFragment, org.elasticsearch.core.RefCounted, org.elasticsearch.core.Releasable

public final class ReleasableBytesReference extends implements org.elasticsearch.core.RefCounted, org.elasticsearch.core.Releasable, BytesReference
An extension to BytesReference that requires releasing its content. This class exists to make it explicit when a bytes reference needs to be released, and when not.
  • Nested Class Summary

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

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

    Fields
    Modifier and Type
    Field
    Description
    static org.elasticsearch.core.Releasable
     

    Fields inherited from interface org.elasticsearch.common.xcontent.ToXContent

    EMPTY_PARAMS
  • Constructor Summary

    Constructors
    Constructor
    Description
    ReleasableBytesReference​(BytesReference delegate, org.elasticsearch.core.AbstractRefCounted refCounted)
     
    ReleasableBytesReference​(BytesReference delegate, org.elasticsearch.core.Releasable releasable)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    byte[]
     
    int
     
    void
     
    int
     
    boolean
     
     
    boolean
     obj)
     
    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.
    boolean
     
    int
     
    void
     
    int
    indexOf​(byte marker, int from)
    Finds the index of the first occurrence of the given marker between within the given bounds.
    boolean
     
    org.apache.lucene.util.BytesRefIterator
    Returns a BytesRefIterator for this BytesReference.
    int
    The length.
    long
    The amount of memory used by this BytesReference
    int
     
     
    retainedSlice​(int from, int length)
     
    slice​(int from, int length)
    Slice the bytes from the from index up to length.
    A stream input of the bytes.
    org.apache.lucene.util.BytesRef
    Converts to Lucene BytesRef.
    org.elasticsearch.common.xcontent.XContentBuilder
    toXContent​(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params)
     
    boolean
     
    Interprets the referenced bytes as UTF8 bytes, returning the resulting string
    wrap​(BytesReference reference)
     
    void
     os)
    Writes the bytes directly to the output stream.

    Methods inherited from class java.lang.

    , , , , , , , ,
  • Field Details

    • NO_OP

      public static final org.elasticsearch.core.Releasable NO_OP
  • Constructor Details

    • ReleasableBytesReference

      public ReleasableBytesReference(BytesReference delegate, org.elasticsearch.core.Releasable releasable)
    • ReleasableBytesReference

      public ReleasableBytesReference(BytesReference delegate, org.elasticsearch.core.AbstractRefCounted refCounted)
  • Method Details

    • empty

      public static ReleasableBytesReference empty()
    • wrap

      public static ReleasableBytesReference wrap(BytesReference reference)
    • refCount

      public int refCount()
    • incRef

      public void incRef()
      Specified by:
      incRef in interface org.elasticsearch.core.RefCounted
    • tryIncRef

      public boolean tryIncRef()
      Specified by:
      tryIncRef in interface org.elasticsearch.core.RefCounted
    • decRef

      public boolean decRef()
      Specified by:
      decRef in interface org.elasticsearch.core.RefCounted
    • retain

      public ReleasableBytesReference retain()
    • retainedSlice

      public ReleasableBytesReference retainedSlice(int from, int length)
    • close

      public void close()
      Specified by:
       in interface 
      Specified by:
       in interface 
      Specified by:
      close in interface org.elasticsearch.core.Releasable
    • get

      public byte get(int index)
      Description copied from interface: BytesReference
      Returns the byte at the specified index. Need to be between 0 and length.
      Specified by:
      get in interface BytesReference
    • getInt

      public int getInt(int index)
      Description copied from interface: BytesReference
      Returns the integer read from the 4 bytes (BE) starting at the given index.
      Specified by:
      getInt in interface BytesReference
    • indexOf

      public int indexOf(byte marker, int from)
      Description copied from interface: BytesReference
      Finds the index of the first occurrence of the given marker between within the given bounds.
      Specified by:
      indexOf in interface BytesReference
      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

      public int length()
      Description copied from interface: BytesReference
      The length.
      Specified by:
      length in interface BytesReference
    • slice

      public BytesReference slice(int from, int length)
      Description copied from interface: BytesReference
      Slice the bytes from the from index up to length.
      Specified by:
      slice in interface BytesReference
    • ramBytesUsed

      public long ramBytesUsed()
      Description copied from interface: BytesReference
      The amount of memory used by this BytesReference
      Specified by:
      ramBytesUsed in interface BytesReference
    • streamInput

      public StreamInput streamInput() throws
      Description copied from interface: BytesReference
      A stream input of the bytes.
      Specified by:
      streamInput in interface BytesReference
      Throws:
    • writeTo

      public void writeTo( os) throws
      Description copied from interface: BytesReference
      Writes the bytes directly to the output stream.
      Specified by:
      writeTo in interface BytesReference
      Throws:
    • utf8ToString

      public  utf8ToString()
      Description copied from interface: BytesReference
      Interprets the referenced bytes as UTF8 bytes, returning the resulting string
      Specified by:
      utf8ToString in interface BytesReference
    • toBytesRef

      public org.apache.lucene.util.BytesRef toBytesRef()
      Description copied from interface: BytesReference
      Converts to Lucene BytesRef.
      Specified by:
      toBytesRef in interface BytesReference
    • iterator

      public org.apache.lucene.util.BytesRefIterator iterator()
      Description copied from interface: BytesReference
      Returns a BytesRefIterator for this BytesReference. This method allows access to the internal pages of this reference without copying them. Use with care!
      Specified by:
      iterator in interface BytesReference
      See Also:
      BytesRefIterator
    • compareTo

      public int compareTo(BytesReference o)
      Specified by:
       in interface <BytesReference>
    • toXContent

      public org.elasticsearch.common.xcontent.XContentBuilder toXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params) throws
      Specified by:
      toXContent in interface org.elasticsearch.common.xcontent.ToXContent
      Throws:
    • isFragment

      public boolean isFragment()
      Specified by:
      isFragment in interface org.elasticsearch.common.xcontent.ToXContent
      Specified by:
      isFragment in interface org.elasticsearch.common.xcontent.ToXContentFragment
    • equals

      public boolean equals( obj)
      Overrides:
       in class 
    • hashCode

      public int hashCode()
      Overrides:
       in class 
    • hasArray

      public boolean hasArray()
      Specified by:
      hasArray in interface BytesReference
      Returns:
      true if this instance is backed by a byte array
    • array

      public byte[] array()
      Specified by:
      array in interface BytesReference
      Returns:
      backing byte array for this instance
    • arrayOffset

      public int arrayOffset()
      Specified by:
      arrayOffset in interface BytesReference
      Returns:
      offset of the first byte of this instance in the backing byte array