Package org.elasticsearch.common.bytes
Class RecyclingBytesStreamOutput
java.lang.Object
java.io.OutputStream
org.elasticsearch.common.io.stream.StreamOutput
org.elasticsearch.common.io.stream.BytesStream
org.elasticsearch.common.bytes.RecyclingBytesStreamOutput
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
public class RecyclingBytesStreamOutput extends BytesStream
An in-memory
StreamOutput which first fills the given byte[] and then allocates more space from the given
BigArrays if needed. The idea is that you can use this for passing data to an API that requires a single byte[] (or a
BytesRef) which you'd prefer to re-use if possible, avoiding excessive allocations, but which may not
always be large enough.-
Constructor Summary
Constructors Constructor Description RecyclingBytesStreamOutput(byte[] buffer, BigArrays bigArrays) -
Method Summary
Modifier and Type Method Description BytesReferencebytes()voidclose()Closes this stream to further operations.voidflush()Forces any buffered output to be written.voidreset()org.apache.lucene.util.BytesReftoBytesRef()Return the written bytes in aBytesRef, avoiding allocating a newbyte[]if the original buffer was already large enough.voidwriteByte(byte b)Writes a single byte.voidwriteBytes(byte[] b, int offset, int length)Writes an array of bytes.Methods inherited from class org.elasticsearch.common.io.stream.StreamOutput
checkWriteable, getFeatures, getVersion, hasFeature, position, seek, setFeatures, setVersion, write, write, writeArray, writeArray, writeBoolean, writeByteArray, writeBytes, writeBytes, writeBytesRef, writeBytesReference, writeCollection, writeCollection, writeDouble, writeDoubleArray, writeEnum, writeEnumSet, writeException, writeFloat, writeFloatArray, writeGenericValue, writeGeoPoint, writeInstant, writeInt, writeIntArray, writeList, writeLong, writeLongArray, writeMap, writeMap, writeMap, writeMap, writeMapOfLists, writeMapWithConsistentOrder, writeNamedWriteable, writeNamedWriteableList, writeOptionalArray, writeOptionalArray, writeOptionalBoolean, writeOptionalBytesReference, writeOptionalDouble, writeOptionalEnum, writeOptionalFloat, writeOptionalInstant, writeOptionalInt, writeOptionalLong, writeOptionalNamedWriteable, writeOptionalSecureString, writeOptionalString, writeOptionalStringArray, writeOptionalStringCollection, writeOptionalText, writeOptionalTimeValue, writeOptionalTimeZone, writeOptionalVInt, writeOptionalVLong, writeOptionalWriteable, writeOptionalZoneId, writeSecureString, writeShort, writeString, writeStringArray, writeStringArrayNullable, writeStringCollection, writeText, writeTimeValue, writeTimeZone, writeVInt, writeVIntArray, writeVLong, writeVLongArray, writeZLong, writeZoneIdMethods inherited from class java.io.OutputStream
nullOutputStream, writeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
RecyclingBytesStreamOutput
-
-
Method Details
-
writeByte
public void writeByte(byte b)Description copied from class:StreamOutputWrites a single byte.- Specified by:
writeBytein classStreamOutput
-
writeBytes
public void writeBytes(byte[] b, int offset, int length)Description copied from class:StreamOutputWrites an array of bytes.- Specified by:
writeBytesin classStreamOutput- Parameters:
b- the bytes to writeoffset- the offset in the byte arraylength- the number of bytes to write
-
flush
public void flush()Description copied from class:StreamOutputForces any buffered output to be written.- Specified by:
flushin interfacejava.io.Flushable- Specified by:
flushin classStreamOutput
-
close
public void close() throws java.io.IOExceptionDescription copied from class:StreamOutputCloses this stream to further operations.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein classStreamOutput- Throws:
java.io.IOException
-
reset
public void reset() throws java.io.IOException- Specified by:
resetin classStreamOutput- Throws:
java.io.IOException
-
toBytesRef
public org.apache.lucene.util.BytesRef toBytesRef()Return the written bytes in aBytesRef, avoiding allocating a newbyte[]if the original buffer was already large enough. If we allocate a new (larger) buffer here then callers should typically re-use it for subsequent streams. -
bytes
- Specified by:
bytesin classBytesStream
-