Class BytesStreamOutput
- java.lang.Object
-
- java.io.OutputStream
-
- org.elasticsearch.common.io.stream.StreamOutput
-
- org.elasticsearch.common.io.stream.BytesStream
-
- org.elasticsearch.common.io.stream.BytesStreamOutput
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
- Direct Known Subclasses:
ReleasableBytesStreamOutput
public class BytesStreamOutput extends BytesStream
A @linkStreamOutput
that usesBigArrays
to acquire pages of bytes, which avoids frequent reallocation & copying of the internal data.
-
-
Constructor Summary
Constructors Modifier Constructor Description BytesStreamOutput()
Create a non recyclingBytesStreamOutput
with an initial capacity of 0.BytesStreamOutput(int expectedSize)
Create a non recyclingBytesStreamOutput
with enough initial pages acquired to satisfy the capacity given by expected size.protected
BytesStreamOutput(int expectedSize, BigArrays bigArrays)
-
Method Summary
Modifier and Type Method Description BytesReference
bytes()
void
close()
Closes this stream to further operations.void
flush()
Forces any buffered output to be written.long
position()
long
ramBytesUsed()
Returns the number of bytes used by the underlyingByteArray
void
reset()
void
seek(long position)
int
size()
Returns the current size of the buffer.void
skip(int length)
void
writeByte(byte b)
Writes a single byte.void
writeBytes(byte[] b, int offset, int length)
Writes an array of bytes.-
Methods inherited from class org.elasticsearch.common.io.stream.StreamOutput
getVersion, hasFeature, 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, writeMapOfLists, writeMapWithConsistentOrder, writeNamedWriteable, writeNamedWriteableList, writeOptionalArray, writeOptionalArray, writeOptionalBoolean, writeOptionalBytesReference, writeOptionalDouble, writeOptionalFloat, writeOptionalInstant, writeOptionalLong, writeOptionalNamedWriteable, writeOptionalStreamable, writeOptionalString, writeOptionalStringArray, writeOptionalText, writeOptionalTimeValue, writeOptionalTimeZone, writeOptionalVInt, writeOptionalWriteable, writeShort, writeStreamableList, writeString, writeStringArray, writeStringArrayNullable, writeStringCollection, writeText, writeTimeValue, writeTimeZone, writeVInt, writeVIntArray, writeVLong, writeVLongArray, writeZLong
-
-
-
-
Constructor Detail
-
BytesStreamOutput
public BytesStreamOutput()
Create a non recyclingBytesStreamOutput
with an initial capacity of 0.
-
BytesStreamOutput
public BytesStreamOutput(int expectedSize)
Create a non recyclingBytesStreamOutput
with enough initial pages acquired to satisfy the capacity given by expected size.- Parameters:
expectedSize
- the expected maximum size of the stream in bytes.
-
BytesStreamOutput
protected BytesStreamOutput(int expectedSize, BigArrays bigArrays)
-
-
Method Detail
-
position
public long position() throws java.io.IOException
- Overrides:
position
in classStreamOutput
- Throws:
java.io.IOException
-
writeByte
public void writeByte(byte b) throws java.io.IOException
Description copied from class:StreamOutput
Writes a single byte.- Specified by:
writeByte
in classStreamOutput
- Throws:
java.io.IOException
-
writeBytes
public void writeBytes(byte[] b, int offset, int length)
Description copied from class:StreamOutput
Writes an array of bytes.- Specified by:
writeBytes
in classStreamOutput
- Parameters:
b
- the bytes to writeoffset
- the offset in the byte arraylength
- the number of bytes to write
-
reset
public void reset()
- Specified by:
reset
in classStreamOutput
-
flush
public void flush() throws java.io.IOException
Description copied from class:StreamOutput
Forces any buffered output to be written.- Specified by:
flush
in interfacejava.io.Flushable
- Specified by:
flush
in classStreamOutput
- Throws:
java.io.IOException
-
seek
public void seek(long position)
- Overrides:
seek
in classStreamOutput
-
skip
public void skip(int length)
-
close
public void close()
Description copied from class:StreamOutput
Closes this stream to further operations.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in classStreamOutput
-
size
public int size()
Returns the current size of the buffer.- Returns:
- the value of the
count
field, which is the number of valid bytes in this output stream. - See Also:
ByteArrayOutputStream.count
-
bytes
public BytesReference bytes()
- Specified by:
bytes
in classBytesStream
-
ramBytesUsed
public long ramBytesUsed()
Returns the number of bytes used by the underlyingByteArray
- See Also:
Accountable.ramBytesUsed()
-
-