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:
Closeable
,Flushable
,AutoCloseable
- Direct Known Subclasses:
ReleasableBytesStreamOutput
A @link
StreamOutput
that uses BigArrays
to acquire pages of
bytes, which avoids frequent reallocation & copying of the internal data.-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionCreate 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 TypeMethodDescriptionbytes()
void
close()
Closes this stream to further operations.Likebytes()
but copies the bytes to a freshly allocated buffer.protected void
ensureCapacity
(long offset) void
flush()
Forces any buffered output to be written.long
position()
long
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
checkWriteable, getVersion, 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, writeOptionalVInt, writeOptionalVLong, writeOptionalWriteable, writeOptionalZoneId, writeSecureString, writeShort, writeString, writeStringArray, writeStringArrayNullable, writeStringCollection, writeText, writeTimeValue, writeVInt, writeVIntArray, writeVLong, writeVLongArray, writeZLong, writeZoneId
Methods inherited from class java.io.OutputStream
nullOutputStream, write
-
Field Details
-
bigArrays
-
bytes
-
count
protected int count
-
-
Constructor Details
-
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
-
-
Method Details
-
position
public long position()- Overrides:
position
in classStreamOutput
-
writeByte
public void writeByte(byte b) Description copied from class:StreamOutput
Writes a single byte.- Specified by:
writeByte
in classStreamOutput
-
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()Description copied from class:StreamOutput
Forces any buffered output to be written.- Specified by:
flush
in interfaceFlushable
- Specified by:
flush
in classStreamOutput
-
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 interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- 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:
-
bytes
- Specified by:
bytes
in classBytesStream
-
copyBytes
Likebytes()
but copies the bytes to a freshly allocated buffer.- Returns:
- copy of the bytes in this instances
-
ramBytesUsed
public long ramBytesUsed()Returns the number of bytes used by the underlyingByteArray
- See Also:
-
Accountable.ramBytesUsed()
-
ensureCapacity
protected void ensureCapacity(long offset)
-