Package org.elasticsearch.common.bytes
Class BytesReference
- java.lang.Object
-
- org.elasticsearch.common.bytes.BytesReference
-
- All Implemented Interfaces:
Comparable<BytesReference>,ToXContent,ToXContentFragment
- Direct Known Subclasses:
ByteBufferReference,BytesArray,CompositeBytesReference,PagedBytesReference
public abstract class BytesReference extends Object implements 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
-
Fields inherited from interface org.elasticsearch.common.xcontent.ToXContent
EMPTY_PARAMS
-
-
Constructor Summary
Constructors Constructor Description BytesReference()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static BytesReferencebytes(XContentBuilder xContentBuilder)Convert anXContentBuilderinto a BytesReference.intcompareTo(BytesReference other)booleanequals(Object other)static BytesReferencefromByteBuffers(ByteBuffer[] buffers)Returns BytesReference composed of the provided ByteBuffers.abstract 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.BytesRefIteratoriterator()Returns a BytesRefIterator for this BytesReference.abstract intlength()The length.abstract longramBytesUsed()The amount of memory used by this BytesReferenceabstract BytesReferenceslice(int from, int length)Slice the bytes from thefromindex up tolength.StreamInputstreamInput()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.abstract BytesReftoBytesRef()Converts to Lucene BytesRef.XContentBuildertoXContent(XContentBuilder builder, ToXContent.Params params)Stringutf8ToString()Interprets the referenced bytes as UTF8 bytes, returning the resulting stringvoidwriteTo(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
-
Methods inherited from interface org.elasticsearch.common.xcontent.ToXContentFragment
isFragment
-
-
-
-
Method Detail
-
bytes
public static BytesReference bytes(XContentBuilder xContentBuilder)
Convert anXContentBuilderinto a BytesReference. This method closes the builder, so no further fields may be added.
-
get
public abstract byte get(int index)
Returns the byte at the specified index. Need to be between 0 and length.
-
getInt
public int getInt(int index)
Returns the integer read from the 4 bytes (BE) starting at the given index.
-
indexOf
public 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
public abstract int length()
The length.
-
slice
public abstract BytesReference slice(int from, int length)
Slice the bytes from thefromindex up tolength.
-
ramBytesUsed
public abstract long ramBytesUsed()
The amount of memory used by this BytesReference
-
streamInput
public StreamInput streamInput() throws IOException
A stream input of the bytes.- Throws:
IOException
-
writeTo
public void writeTo(OutputStream os) throws IOException
Writes the bytes directly to the output stream.- Throws:
IOException
-
utf8ToString
public String utf8ToString()
Interprets the referenced bytes as UTF8 bytes, returning the resulting string
-
toBytesRef
public abstract BytesRef toBytesRef()
Converts to Lucene BytesRef.
-
iterator
public 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
-
toBytes
public static byte[] toBytes(BytesReference reference)
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
public static ByteBuffer[] toByteBuffers(BytesReference reference)
Returns an array of byte buffers from the given BytesReference.
-
fromByteBuffers
public static BytesReference fromByteBuffers(ByteBuffer[] buffers)
Returns BytesReference composed of the provided ByteBuffers.
-
compareTo
public int compareTo(BytesReference other)
- Specified by:
compareToin interfaceComparable<BytesReference>
-
toXContent
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException
- Specified by:
toXContentin interfaceToXContent- Throws:
IOException
-
-