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.xcontent.ToXContent
,org.elasticsearch.common.xcontent.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
-
Field Summary
Fields Modifier and Type Field Description static Releasable
NO_OP
-
Constructor Summary
Constructors Constructor Description ReleasableBytesReference(BytesReference delegate, Releasable releasable)
-
Method Summary
Modifier and Type Method Description void
close()
int
compareTo(BytesReference o)
boolean
equals(java.lang.Object 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.int
hashCode()
int
indexOf(byte marker, int from)
Finds the index of the first occurrence of the given marker between within the given bounds.boolean
isFragment()
org.apache.lucene.util.BytesRefIterator
iterator()
Returns a BytesRefIterator for this BytesReference.int
length()
The length.long
ramBytesUsed()
The amount of memory used by this BytesReferenceint
refCount()
ReleasableBytesReference
retain()
ReleasableBytesReference
retainedSlice(int from, int length)
BytesReference
slice(int from, int length)
Slice the bytes from thefrom
index up tolength
.StreamInput
streamInput()
A stream input of the bytes.org.apache.lucene.util.BytesRef
toBytesRef()
Converts to Lucene BytesRef.org.elasticsearch.common.xcontent.XContentBuilder
toXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params)
java.lang.String
utf8ToString()
Interprets the referenced bytes as UTF8 bytes, returning the resulting stringstatic ReleasableBytesReference
wrap(BytesReference reference)
void
writeTo(java.io.OutputStream os)
Writes the bytes directly to the output stream.
-
Field Details
-
Constructor Details
-
Method Details
-
wrap
-
refCount
public int refCount() -
retain
-
retainedSlice
-
close
public void close()- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in interfaceReleasable
-
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 interfaceBytesReference
-
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 interfaceBytesReference
-
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 interfaceBytesReference
- Parameters:
marker
- marker byte to searchfrom
- 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 interfaceBytesReference
-
slice
Description copied from interface:BytesReference
Slice the bytes from thefrom
index up tolength
.- Specified by:
slice
in interfaceBytesReference
-
ramBytesUsed
public long ramBytesUsed()Description copied from interface:BytesReference
The amount of memory used by this BytesReference- Specified by:
ramBytesUsed
in interfaceBytesReference
-
streamInput
Description copied from interface:BytesReference
A stream input of the bytes.- Specified by:
streamInput
in interfaceBytesReference
- Throws:
java.io.IOException
-
writeTo
public void writeTo(java.io.OutputStream os) throws java.io.IOExceptionDescription copied from interface:BytesReference
Writes the bytes directly to the output stream.- Specified by:
writeTo
in interfaceBytesReference
- Throws:
java.io.IOException
-
utf8ToString
public java.lang.String utf8ToString()Description copied from interface:BytesReference
Interprets the referenced bytes as UTF8 bytes, returning the resulting string- Specified by:
utf8ToString
in interfaceBytesReference
-
toBytesRef
public org.apache.lucene.util.BytesRef toBytesRef()Description copied from interface:BytesReference
Converts to Lucene BytesRef.- Specified by:
toBytesRef
in interfaceBytesReference
-
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 interfaceBytesReference
- See Also:
BytesRefIterator
-
compareTo
- Specified by:
compareTo
in 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:
toXContent
in interfaceorg.elasticsearch.common.xcontent.ToXContent
- Throws:
java.io.IOException
-
isFragment
public boolean isFragment()- Specified by:
isFragment
in interfaceorg.elasticsearch.common.xcontent.ToXContent
- Specified by:
isFragment
in interfaceorg.elasticsearch.common.xcontent.ToXContentFragment
-
equals
public boolean equals(java.lang.Object obj)- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()- Overrides:
hashCode
in classjava.lang.Object
-