Package org.elasticsearch.common.bytes
Class ReleasableBytesReference
java.lang.Object
org.elasticsearch.common.bytes.ReleasableBytesReference
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.lang.Comparable<BytesReference>,BytesReference,Releasable,org.elasticsearch.common.util.concurrent.RefCounted,org.elasticsearch.common.xcontent.ToXContent,org.elasticsearch.common.xcontent.ToXContentFragment
public final class ReleasableBytesReference extends java.lang.Object implements org.elasticsearch.common.util.concurrent.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.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 ReleasableNO_OPFields inherited from interface org.elasticsearch.common.xcontent.ToXContent
EMPTY_PARAMS -
Constructor Summary
Constructors Constructor Description ReleasableBytesReference(BytesReference delegate, Releasable releasable) -
Method Summary
Modifier and Type Method Description voidclose()intcompareTo(BytesReference o)booleandecRef()booleanequals(java.lang.Object obj)byteget(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.inthashCode()voidincRef()intindexOf(byte marker, int from)Finds the index of the first occurrence of the given marker between within the given bounds.booleanisFragment()org.apache.lucene.util.BytesRefIteratoriterator()Returns a BytesRefIterator for this BytesReference.intlength()The length.longramBytesUsed()The amount of memory used by this BytesReferenceintrefCount()ReleasableBytesReferenceretain()ReleasableBytesReferenceretainedSlice(int from, int length)BytesReferenceslice(int from, int length)Slice the bytes from thefromindex up tolength.StreamInputstreamInput()A stream input of the bytes.org.apache.lucene.util.BytesReftoBytesRef()Converts to Lucene BytesRef.org.elasticsearch.common.xcontent.XContentBuildertoXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params)booleantryIncRef()java.lang.Stringutf8ToString()Interprets the referenced bytes as UTF8 bytes, returning the resulting stringstatic ReleasableBytesReferencewrap(BytesReference reference)voidwriteTo(java.io.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, wait
-
Field Details
-
NO_OP
-
-
Constructor Details
-
ReleasableBytesReference
-
-
Method Details
-
wrap
-
refCount
public int refCount() -
incRef
public void incRef()- Specified by:
incRefin interfaceorg.elasticsearch.common.util.concurrent.RefCounted
-
tryIncRef
public boolean tryIncRef()- Specified by:
tryIncRefin interfaceorg.elasticsearch.common.util.concurrent.RefCounted
-
decRef
public boolean decRef()- Specified by:
decRefin interfaceorg.elasticsearch.common.util.concurrent.RefCounted
-
retain
-
retainedSlice
-
close
public void close()- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- 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
-
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:
java.io.IOException
-
writeTo
public void writeTo(java.io.OutputStream os) throws java.io.IOExceptionDescription copied from interface:BytesReferenceWrites the bytes directly to the output stream.- Specified by:
writeToin interfaceBytesReference- Throws:
java.io.IOException
-
utf8ToString
public java.lang.String 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 interfacejava.lang.Comparable<BytesReference>
-
toXContent
public org.elasticsearch.common.xcontent.XContentBuilder toXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params) throws java.io.IOException- Specified by:
toXContentin interfaceorg.elasticsearch.common.xcontent.ToXContent- Throws:
java.io.IOException
-
isFragment
public boolean isFragment()- Specified by:
isFragmentin interfaceorg.elasticsearch.common.xcontent.ToXContent- Specified by:
isFragmentin interfaceorg.elasticsearch.common.xcontent.ToXContentFragment
-
equals
public boolean equals(java.lang.Object obj)- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()- Overrides:
hashCodein classjava.lang.Object
-