- All Superinterfaces:
Comparable<BytesReference>,ToXContent,ToXContentFragment
- All Known Implementing Classes:
AbstractBytesReference,BytesArray,CompositeBytesReference,PagedBytesReference,ReleasableBytesReference
A reference to bytes.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.elasticsearch.xcontent.ToXContent
ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.Params -
Field Summary
Fields inherited from interface org.elasticsearch.xcontent.ToXContent
EMPTY, EMPTY_PARAMS -
Method Summary
Modifier and TypeMethodDescriptiondefault byte[]array()default intstatic BytesReferencebytes(XContentBuilder xContentBuilder) Convert anXContentBuilderinto a BytesReference.static BytesReferencefromByteArray(ByteArray byteArray, int length) Returns BytesReference either wrapping the providedByteArrayor in case the has a backing raw byte array one that wraps that backing array directly.static BytesReferencefromByteBuffer(ByteBuffer buffer) Returns BytesReference composed of the provided ByteBuffer.static BytesReferencefromByteBuffers(ByteBuffer[] buffers) Returns BytesReference composed of the provided ByteBuffers.byteget(int index) Returns the byte at the specified index.doublegetDoubleLE(int index) Returns the double read from the 8 bytes (LE) starting at the given index.intgetInt(int index) Returns the integer read from the 4 bytes (BE) starting at the given index.intgetIntLE(int index) Returns the integer read from the 4 bytes (LE) starting at the given index.longgetLongLE(int index) Returns the long read from the 8 bytes (LE) starting at the given index.default booleanhasArray()intindexOf(byte marker, int from) Finds the index of the first occurrence of the given marker between within the given bounds.org.apache.lucene.util.BytesRefIteratoriterator()Returns a BytesRefIterator for this BytesReference.intlength()The length.longThe amount of memory used by this BytesReferenceslice(int from, int length) Slice the bytes from thefromindex up tolength.A stream input of the bytes.static 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.BytesRefConverts to Lucene BytesRef.Interprets the referenced bytes as UTF8 bytes, returning the resulting stringvoidwriteTo(OutputStream os) Writes the bytes directly to the output stream.Methods inherited from interface java.lang.Comparable
compareToMethods inherited from interface org.elasticsearch.xcontent.ToXContent
toXContentMethods inherited from interface org.elasticsearch.xcontent.ToXContentFragment
isFragment
-
Method Details
-
bytes
Convert anXContentBuilderinto 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. -
fromByteBuffer
Returns BytesReference composed of the provided ByteBuffer. -
fromByteArray
Returns BytesReference either wrapping the providedByteArrayor in case the has a backing raw byte array one that wraps that backing array directly. -
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. -
getIntLE
int getIntLE(int index) Returns the integer read from the 4 bytes (LE) starting at the given index. -
getLongLE
long getLongLE(int index) Returns the long read from the 8 bytes (LE) starting at the given index. -
getDoubleLE
double getDoubleLE(int index) Returns the double read from the 8 bytes (LE) 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
-1if not found
-
length
int length()The length. -
slice
Slice the bytes from thefromindex up tolength. -
ramBytesUsed
long ramBytesUsed()The amount of memory used by this BytesReference -
streamInput
A stream input of the bytes.- Throws:
IOException
-
writeTo
Writes the bytes directly to the output stream.- Throws:
IOException
-
utf8ToString
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. It must return direct references to the pages, not copies. Use with care!- See Also:
-
hasArray
default boolean hasArray()- Returns:
trueif this instance is backed by a byte array
-
array
default byte[] array()- Returns:
- backing byte array for this instance
-
arrayOffset
default int arrayOffset()- Returns:
- offset of the first byte of this instance in the backing byte array
-