Module org.elasticsearch.server
Package org.elasticsearch.common.bytes
Class ReleasableBytesReference
java.lang.Object
org.elasticsearch.common.bytes.ReleasableBytesReference
- All Implemented Interfaces:
Closeable,AutoCloseable,Comparable<BytesReference>,BytesReference,RefCounted,Releasable,ToXContent,ToXContentFragment
public final class ReleasableBytesReference
extends Object
implements RefCounted, 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.xcontent.ToXContent
ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.Params -
Field Summary
Fields inherited from interface org.elasticsearch.core.RefCounted
ALWAYS_REFERENCEDFields inherited from interface org.elasticsearch.xcontent.ToXContent
EMPTY_PARAMS -
Constructor Summary
ConstructorsConstructorDescriptionReleasableBytesReference(BytesReference delegate, RefCounted refCounted) ReleasableBytesReference(BytesReference delegate, Releasable releasable) -
Method Summary
Modifier and TypeMethodDescriptionbyte[]array()intvoidclose()intbooleandecRef()static ReleasableBytesReferenceempty()booleanbyteget(int index) Returns the byte at the specified index.doublegetDoubleLE(int index) Returns the double read from the 8 bytes (LE) starting at the given index.intgetInt(int index) Returns the integer read from the 4 bytes (BE) starting at the given index.intgetIntLE(int index) Returns the integer read from the 4 bytes (LE) starting at the given index.longgetLongLE(int index) Returns the long read from the 8 bytes (LE) starting at the given index.booleanhasArray()inthashCode()booleanvoidincRef()intindexOf(byte marker, int from) Finds the index of the first occurrence of the given marker between within the given bounds.booleanorg.apache.lucene.util.BytesRefIteratoriterator()Returns a BytesRefIterator for this BytesReference.intlength()The length.longThe amount of memory used by this BytesReference.retain()retainedSlice(int from, int length) Same asslice(int, int)except that the slice is not guaranteed to share the same underlying reference count as this instance.slice(int from, int length) Slice the bytes from thefromindex up tolength.A stream input of the bytes.org.apache.lucene.util.BytesRefConverts to Lucene BytesRef.toXContent(XContentBuilder builder, ToXContent.Params params) booleanInterprets the referenced bytes as UTF8 bytes, returning the resulting stringstatic ReleasableBytesReferencewrap(BytesReference reference) voidwriteTo(OutputStream os) Writes the bytes directly to the output stream.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.elasticsearch.core.RefCounted
mustIncRef
-
Constructor Details
-
ReleasableBytesReference
-
ReleasableBytesReference
-
-
Method Details
-
empty
-
wrap
-
incRef
public void incRef()- Specified by:
incRefin interfaceRefCounted
-
tryIncRef
public boolean tryIncRef()- Specified by:
tryIncRefin interfaceRefCounted
-
decRef
public boolean decRef()- Specified by:
decRefin interfaceRefCounted
-
hasReferences
public boolean hasReferences()- Specified by:
hasReferencesin interfaceRefCounted
-
retain
-
retainedSlice
Same asslice(int, int)except that the slice is not guaranteed to share the same underlying reference count as this instance. This method is equivalent to calling.slice(from, length).retain()but might be more efficient through the avoidance of retaining unnecessary buffers. -
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceReleasable
-
get
public byte get(int index) Description copied from interface:BytesReferenceReturns the byte at the specified index. Need to be between 0 and length.- Specified by:
getin interfaceBytesReference
-
getInt
public int getInt(int index) Description copied from interface:BytesReferenceReturns the integer read from the 4 bytes (BE) starting at the given index.- Specified by:
getIntin interfaceBytesReference
-
getIntLE
public int getIntLE(int index) Description copied from interface:BytesReferenceReturns the integer read from the 4 bytes (LE) starting at the given index.- Specified by:
getIntLEin interfaceBytesReference
-
getLongLE
public long getLongLE(int index) Description copied from interface:BytesReferenceReturns the long read from the 8 bytes (LE) starting at the given index.- Specified by:
getLongLEin interfaceBytesReference
-
getDoubleLE
public double getDoubleLE(int index) Description copied from interface:BytesReferenceReturns the double read from the 8 bytes (LE) starting at the given index.- Specified by:
getDoubleLEin interfaceBytesReference
-
indexOf
public int indexOf(byte marker, int from) Description copied from interface:BytesReferenceFinds the index of the first occurrence of the given marker between within the given bounds.- Specified by:
indexOfin interfaceBytesReference- Parameters:
marker- marker byte to searchfrom- lower bound for the index to check (inclusive)- Returns:
- first index of the marker or
-1if not found
-
length
public int length()Description copied from interface:BytesReferenceThe length.- Specified by:
lengthin interfaceBytesReference
-
slice
Slice the bytes from thefromindex up tolength. The returned bytes reference will share the reference count of this instance and as such any ref-counting operations on the return are shared with this instance and vice versa. UsingretainedSlice(int, int)might be more efficient in situations where the return of this method is subsequently retained by increasing its ref-count.- Specified by:
slicein interfaceBytesReference
-
ramBytesUsed
public long ramBytesUsed()Description copied from interface:BytesReferenceThe amount of memory used by this BytesReference.Note that this is not always the same as length and can vary by implementation.
- Specified by:
ramBytesUsedin interfaceBytesReference
-
streamInput
Description copied from interface:BytesReferenceA stream input of the bytes.- Specified by:
streamInputin interfaceBytesReference- Throws:
IOException
-
writeTo
Description copied from interface:BytesReferenceWrites the bytes directly to the output stream.- Specified by:
writeToin interfaceBytesReference- Throws:
IOException
-
utf8ToString
Description copied from interface:BytesReferenceInterprets the referenced bytes as UTF8 bytes, returning the resulting string- Specified by:
utf8ToStringin interfaceBytesReference
-
toBytesRef
public org.apache.lucene.util.BytesRef toBytesRef()Description copied from interface:BytesReferenceConverts to Lucene BytesRef.- Specified by:
toBytesRefin interfaceBytesReference
-
iterator
public org.apache.lucene.util.BytesRefIterator iterator()Description copied from interface:BytesReferenceReturns a BytesRefIterator for this BytesReference. This method allows access to the internal pages of this reference without copying them. It must return direct references to the pages, not copies. Use with care!- Specified by:
iteratorin interfaceBytesReference- See Also:
-
compareTo
- Specified by:
compareToin interfaceComparable<BytesReference>
-
toXContent
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException - Specified by:
toXContentin interfaceToXContent- Throws:
IOException
-
isFragment
public boolean isFragment()- Specified by:
isFragmentin interfaceToXContent- Specified by:
isFragmentin interfaceToXContentFragment
-
equals
-
hashCode
public int hashCode() -
hasArray
public boolean hasArray()- Specified by:
hasArrayin interfaceBytesReference- Returns:
trueif this instance is backed by a byte array
-
array
public byte[] array()- Specified by:
arrayin interfaceBytesReference- Returns:
- backing byte array for this instance
-
arrayOffset
public int arrayOffset()- Specified by:
arrayOffsetin interfaceBytesReference- Returns:
- offset of the first byte of this instance in the backing byte array
-