Package org.elasticsearch.common.bytes
Interface BytesReference
- All Superinterfaces:
java.lang.Comparable<BytesReference>
,ToXContent
,ToXContentFragment
- All Known Implementing Classes:
AbstractBytesReference
,ByteBufferReference
,BytesArray
,CompositeBytesReference
,PagedBytesReference
,ReleasableBytesReference
public interface BytesReference extends java.lang.Comparable<BytesReference>, ToXContentFragment
A reference to bytes.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.elasticsearch.common.xcontent.ToXContent
ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.Params
-
Field Summary
-
Method Summary
Modifier and Type Method Description static BytesReference
bytes(XContentBuilder xContentBuilder)
Convert anXContentBuilder
into a BytesReference.static BytesReference
fromByteBuffers(java.nio.ByteBuffer[] buffers)
Returns BytesReference composed of the provided ByteBuffers.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
indexOf(byte marker, int from)
Finds the index of the first occurrence of the given marker between within the given bounds.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 BytesReferenceBytesReference
slice(int from, int length)
Slice the bytes from thefrom
index up tolength
.StreamInput
streamInput()
A stream input of the bytes.static java.nio.ByteBuffer[]
toByteBuffers(BytesReference reference)
Returns an array of byte buffers from the given BytesReference.static byte[]
toBytes(BytesReference reference)
Returns a compact array from the given BytesReference.org.apache.lucene.util.BytesRef
toBytesRef()
Converts to Lucene BytesRef.java.lang.String
utf8ToString()
Interprets the referenced bytes as UTF8 bytes, returning the resulting stringvoid
writeTo(java.io.OutputStream os)
Writes the bytes directly to the output stream.
-
Method Details
-
bytes
Convert anXContentBuilder
into a BytesReference. This method closes the builder, so no further fields may be added. -
toBytes
Returns a compact array from the given BytesReference. The returned array won't be copied unless necessary. If you need to modify the returned array useBytesRef.deepCopyOf(reference.toBytesRef()
instead -
toByteBuffers
Returns an array of byte buffers from the given BytesReference. -
fromByteBuffers
Returns BytesReference composed of the provided ByteBuffers. -
get
byte get(int index)Returns the byte at the specified index. Need to be between 0 and length. -
getInt
int getInt(int index)Returns the integer read from the 4 bytes (BE) starting at the given index. -
indexOf
int indexOf(byte marker, int from)Finds the index of the first occurrence of the given marker between within the given bounds.- 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
int length()The length. -
slice
Slice the bytes from thefrom
index up tolength
. -
ramBytesUsed
long ramBytesUsed()The amount of memory used by this BytesReference -
streamInput
A stream input of the bytes.- Throws:
java.io.IOException
-
writeTo
void writeTo(java.io.OutputStream os) throws java.io.IOExceptionWrites the bytes directly to the output stream.- Throws:
java.io.IOException
-
utf8ToString
java.lang.String utf8ToString()Interprets the referenced bytes as UTF8 bytes, returning the resulting string -
toBytesRef
org.apache.lucene.util.BytesRef toBytesRef()Converts to Lucene BytesRef. -
iterator
org.apache.lucene.util.BytesRefIterator iterator()Returns a BytesRefIterator for this BytesReference. This method allows access to the internal pages of this reference without copying them. Use with care!- See Also:
BytesRefIterator
-