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,ToXContent,ToXContentFragment
public final class ReleasableBytesReference extends java.lang.Object implements 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
ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.Params -
Field Summary
-
Constructor Summary
Constructors Constructor Description ReleasableBytesReference(BytesReference delegate, Releasable releasable) -
Method Summary
Modifier and Type Method Description voidclose()intcompareTo(BytesReference o)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()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 BytesReferenceBytesReferenceslice(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.XContentBuildertoXContent(XContentBuilder builder, ToXContent.Params params)java.lang.Stringutf8ToString()Interprets the referenced bytes as UTF8 bytes, returning the resulting stringvoidwriteTo(java.io.OutputStream os)Writes the bytes directly to the output stream.
-
Constructor Details
-
Method Details
-
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 XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException- Specified by:
toXContentin interfaceToXContent- Throws:
java.io.IOException
-
isFragment
public boolean isFragment()- Specified by:
isFragmentin interfaceToXContent- Specified by:
isFragmentin interfaceToXContentFragment
-
equals
public boolean equals(java.lang.Object obj)- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()- Overrides:
hashCodein classjava.lang.Object
-