Package org.elasticsearch.common.bytes
Class ReleasableBytesReference
java.lang.Object
org.elasticsearch.common.bytes.ReleasableBytesReference
- All Implemented Interfaces:
Closeable,AutoCloseable,Comparable<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 Object
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
FieldsFields inherited from interface org.elasticsearch.common.xcontent.ToXContent
EMPTY_PARAMS -
Constructor Summary
ConstructorsConstructorDescriptionReleasableBytesReference(BytesReference delegate, org.elasticsearch.core.AbstractRefCounted refCounted)ReleasableBytesReference(BytesReference delegate, org.elasticsearch.core.Releasable releasable) -
Method Summary
Modifier and TypeMethodDescriptionbyte[]array()intvoidclose()intbooleandecRef()static ReleasableBytesReferenceempty()booleanbyteget(int index)Returns the byte at the specified index.intgetInt(int index)Returns the integer read from the 4 bytes (BE) starting at the given index.booleanhasArray()inthashCode()voidincRef()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 BytesReferenceintrefCount()retain()retainedSlice(int from, int length)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.org.elasticsearch.common.xcontent.XContentBuildertoXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.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.
-
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
-
wrap
-
refCount
public int refCount() -
incRef
public void incRef()- Specified by:
incRefin interfaceorg.elasticsearch.core.RefCounted
-
tryIncRef
public boolean tryIncRef()- Specified by:
tryIncRefin interfaceorg.elasticsearch.core.RefCounted
-
decRef
public boolean decRef()- Specified by:
decRefin interfaceorg.elasticsearch.core.RefCounted
-
retain
-
retainedSlice
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceorg.elasticsearch.core.Releasable
-
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
-
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
Description copied from interface:BytesReferenceSlice the bytes from thefromindex up tolength.- Specified by:
slicein interfaceBytesReference
-
ramBytesUsed
public long ramBytesUsed()Description copied from interface:BytesReferenceThe amount of memory used by this BytesReference- 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. Use with care!- Specified by:
iteratorin interfaceBytesReference- See Also:
BytesRefIterator
-
compareTo
- Specified by:
compareToin interfaceComparable<BytesReference>
-
toXContent
public org.elasticsearch.common.xcontent.XContentBuilder toXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params) throws IOException- Specified by:
toXContentin interfaceorg.elasticsearch.common.xcontent.ToXContent- Throws:
IOException
-
isFragment
public boolean isFragment()- Specified by:
isFragmentin interfaceorg.elasticsearch.common.xcontent.ToXContent- Specified by:
isFragmentin interfaceorg.elasticsearch.common.xcontent.ToXContentFragment
-
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
-