Module org.elasticsearch.compute
Class BreakingBytesRefBuilder
java.lang.Object
org.elasticsearch.compute.operator.BreakingBytesRefBuilder
- All Implemented Interfaces:
Closeable,AutoCloseable,org.apache.lucene.util.Accountable,org.elasticsearch.core.Releasable
public class BreakingBytesRefBuilder
extends Object
implements org.apache.lucene.util.Accountable, org.elasticsearch.core.Releasable
Builder for bytes arrays that checks its size against a
CircuitBreaker.-
Field Summary
Fields inherited from interface org.apache.lucene.util.Accountable
NULL_ACCOUNTABLE -
Constructor Summary
ConstructorsConstructorDescriptionBreakingBytesRefBuilder(CircuitBreaker breaker, String label) Build.BreakingBytesRefBuilder(CircuitBreaker breaker, String label, int initialCapacity) Build. -
Method Summary
Modifier and TypeMethodDescriptionvoidappend(byte b) Append a byte.voidappend(byte[] b, int off, int len) Append bytes.voidappend(org.apache.lucene.util.BytesRef bytes) Append bytes.byte[]bytes()Return the underlying bytes being built for direct manipulation.org.apache.lucene.util.BytesRefReturns a view of the data added as aBytesRef.voidclear()Reset the builder to an empty bytes array.voidclose()voidcopyBytes(org.apache.lucene.util.BytesRef newBytes) Set the content of the builder to the given bytes.voidgrow(int capacity) Make sure that the underlying bytes has a capacity of at leastcapacity.intlength()The number of bytes in this buffer.longvoidsetLength(int length) Set the number of bytes in this buffer.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.lucene.util.Accountable
getChildResources
-
Constructor Details
-
BreakingBytesRefBuilder
Build.- Parameters:
breaker- theCircuitBreakerto check on resizelabel- the label reported by the breaker when it breaks
-
BreakingBytesRefBuilder
Build.- Parameters:
breaker- theCircuitBreakerto check on resizelabel- the label reported by the breaker when it breaksinitialCapacity- the number of bytes initially allocated
-
-
Method Details
-
grow
public void grow(int capacity) Make sure that the underlying bytes has a capacity of at leastcapacity. -
bytes
public byte[] bytes()Return the underlying bytes being built for direct manipulation. Callers will typically use this in combination withgrow(int),length()andsetLength(int)like this:<pre> bytesRefBuilder.grow(bytesRefBuilder.length() + Long.BYTES); LONG.set(bytesRefBuilder.bytes(), bytesRefBuilder.length(), value); bytesRefBuilder.setLength(bytesRefBuilder.length() + Long.BYTES); </pre> -
length
public int length()The number of bytes in this buffer. It is not> the capacity of the buffer. -
setLength
public void setLength(int length) Set the number of bytes in this buffer. Does not deallocate the underlying buffer, only the length once built. -
append
public void append(byte b) Append a byte. -
append
public void append(byte[] b, int off, int len) Append bytes. -
append
public void append(org.apache.lucene.util.BytesRef bytes) Append bytes. -
copyBytes
public void copyBytes(org.apache.lucene.util.BytesRef newBytes) Set the content of the builder to the given bytes. -
clear
public void clear()Reset the builder to an empty bytes array. Doesn't deallocate any memory. -
bytesRefView
public org.apache.lucene.util.BytesRef bytesRefView()Returns a view of the data added as aBytesRef. Importantly, this does not copy the bytes and any further modification to theBreakingBytesRefBuilderwill modify the returnedBytesRef. The caller must copy the bytes if they wish to keep them. -
ramBytesUsed
public long ramBytesUsed()- Specified by:
ramBytesUsedin interfaceorg.apache.lucene.util.Accountable
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceorg.elasticsearch.core.Releasable
-