Module org.elasticsearch.server
Class CountingStreamOutput
java.lang.Object
java.io.OutputStream
org.elasticsearch.common.io.stream.StreamOutput
org.elasticsearch.common.io.stream.CountingStreamOutput
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
A reusable @link
StreamOutput that just count how many bytes are written.-
Field Summary
Fields inherited from class org.elasticsearch.common.io.stream.StreamOutput
GENERIC_LIST_HEADER -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this stream to further operations.voidflush()Forces any buffered output to be written.longposition()voidreset()reset the written byes to 0voidwriteByte(byte b) Writes a single byte.voidwriteBytes(byte[] b, int offset, int length) Writes an array of bytes.voidwriteDouble(double v) voidwriteDoubleArray(double[] values) voidwriteFloat(float v) voidwriteFloatArray(float[] values) voidwriteGenericString(String value) Write aStringwithinStreamOutput.writeGenericValue(java.lang.Object), represented as the type code byte0followed by the string itself written as if withStreamOutput.writeString(java.lang.String).voidwriteInt(int i) Writes an int as four bytes.voidwriteIntArray(int[] values) voidwriteIntLE(int i) Writes an int as four bytes, least significant bytes first.voidwriteLong(long i) Writes a long as eight bytes.voidwriteLongArray(long[] values) voidwriteLongLE(long i) Writes a long as eight bytes.voidWrite a possibly-nullString, represented as awhich isinvalid reference
booleanfalseif the string is null, or elsetrueif it is not null, and in this latter case it is followed by the string itself written as if withStreamOutput.writeString(java.lang.String).voidwriteShort(short v) voidwriteString(String str) Write aString: its length in Unicode code units (chars) (NB not bytes) written usingStreamOutput.writeVInt(int)followed by the sequence of characters themselves encoded as UTF-8.voidwriteVInt(int v) Writes an int in a variable-length format.voidwriteZLong(long i) Writes a long in a variable-length format.Methods inherited from class org.elasticsearch.common.io.stream.StreamOutput
checkWriteable, getTransportVersion, legacyWriteWithSizePrefix, setTransportVersion, write, write, writeArray, writeArray, writeBigInteger, writeBoolean, writeByteArray, writeBytes, writeBytes, writeBytesRef, writeBytesReference, writeCollection, writeCollection, writeDoubleLE, writeEnum, writeEnumSet, writeException, writeGenericList, writeGenericMap, writeGenericNull, writeGenericValue, writeGeoPoint, writeInstant, writeMap, writeMap, writeMap, writeMapValues, writeMapValues, writeMapWithConsistentOrder, writeMissingString, writeMissingWriteable, writeNamedWriteable, writeNamedWriteableCollection, writeOptional, writeOptionalArray, writeOptionalArray, writeOptionalBoolean, writeOptionalByteArray, writeOptionalBytesReference, writeOptionalCollection, writeOptionalCollection, writeOptionalDouble, writeOptionalEnum, writeOptionalException, writeOptionalFloat, writeOptionalFloatArray, writeOptionalInstant, writeOptionalInt, writeOptionalLong, writeOptionalMap, writeOptionalNamedWriteable, writeOptionalNamedWriteableCollection, writeOptionalSecureString, writeOptionalStringArray, writeOptionalStringCollection, writeOptionalText, writeOptionalTimeValue, writeOptionalVInt, writeOptionalVLong, writeOptionalWriteable, writeOptionalZoneId, writeSecureString, writeStringArray, writeStringArrayNullable, writeStringCollection, writeText, writeTimeValue, writeVIntArray, writeVLong, writeVLongArray, writeWithSizePrefix, writeWriteable, writeZoneIdMethods inherited from class java.io.OutputStream
nullOutputStream, write
-
Constructor Details
-
CountingStreamOutput
public CountingStreamOutput()
-
-
Method Details
-
reset
public void reset()reset the written byes to 0 -
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
-
position
public long position()- Specified by:
positionin classStreamOutput- Returns:
- the current position of the stream, in bytes. Increases as data is written to the stream. If the stream is seekable then
the seek operation updates the current
position().
-
writeShort
- Overrides:
writeShortin classStreamOutput- Throws:
IOException
-
writeInt
public void writeInt(int i) Description copied from class:StreamOutputWrites an int as four bytes.- Overrides:
writeIntin classStreamOutput
-
writeIntLE
Description copied from class:StreamOutputWrites an int as four bytes, least significant bytes first.- Overrides:
writeIntLEin classStreamOutput- Throws:
IOException
-
writeIntArray
public void writeIntArray(int[] values) - Overrides:
writeIntArrayin classStreamOutput
-
writeLong
public void writeLong(long i) Description copied from class:StreamOutputWrites a long as eight bytes.- Overrides:
writeLongin classStreamOutput
-
writeLongLE
public void writeLongLE(long i) Description copied from class:StreamOutputWrites a long as eight bytes.- Overrides:
writeLongLEin classStreamOutput
-
writeLongArray
public void writeLongArray(long[] values) - Overrides:
writeLongArrayin classStreamOutput
-
writeFloat
public void writeFloat(float v) - Overrides:
writeFloatin classStreamOutput
-
writeFloatArray
public void writeFloatArray(float[] values) - Overrides:
writeFloatArrayin classStreamOutput
-
writeDouble
public void writeDouble(double v) - Overrides:
writeDoublein classStreamOutput
-
writeDoubleArray
public void writeDoubleArray(double[] values) - Overrides:
writeDoubleArrayin classStreamOutput
-
writeVInt
public void writeVInt(int v) Description copied from class:StreamOutputWrites an int in a variable-length format. Writes between one and five bytes. Smaller values take fewer bytes. Negative numbers will always use all 5 bytes and are therefore better serialized usingStreamOutput.writeInt(int)- Overrides:
writeVIntin classStreamOutput
-
writeZLong
public void writeZLong(long i) Description copied from class:StreamOutputWrites a long in a variable-length format. Writes between one and ten bytes. Values are remapped by sliding the sign bit into the lsb and then encoded as an unsigned number e.g., 0 -;> 0, -1 -;> 1, 1 -;> 2, ..., Long.MIN_VALUE -;> -1, Long.MAX_VALUE -;> -2 Numbers with small absolute value will have a small encoding If the numbers are known to be non-negative, useStreamOutput.writeVLong(long)- Overrides:
writeZLongin classStreamOutput
-
writeString
Description copied from class:StreamOutputWrite aString: its length in Unicode code units (chars) (NB not bytes) written usingStreamOutput.writeVInt(int)followed by the sequence of characters themselves encoded as UTF-8.May be performance-critical, so subclasses must specify an explicit implementation. If performance is unimportant, consider using
StreamOutputHelper.writeString(java.lang.String, java.io.OutputStream).- Specified by:
writeStringin classStreamOutput
-
writeOptionalString
Description copied from class:StreamOutputWrite a possibly-nullString, represented as awhich isinvalid reference
booleanfalseif the string is null, or elsetrueif it is not null, and in this latter case it is followed by the string itself written as if withStreamOutput.writeString(java.lang.String).May be performance-critical, so subclasses must specify an explicit implementation. If performance is unimportant, consider using
StreamOutputHelper.writeOptionalString(java.lang.String, java.io.OutputStream).- Specified by:
writeOptionalStringin classStreamOutput
-
writeGenericString
Description copied from class:StreamOutputWrite aStringwithinStreamOutput.writeGenericValue(java.lang.Object), represented as the type code byte0followed by the string itself written as if withStreamOutput.writeString(java.lang.String).May be performance-critical, so subclasses must specify an explicit implementation. If performance is unimportant, consider using
StreamOutputHelper.writeGenericString(java.lang.String, java.io.OutputStream).- Specified by:
writeGenericStringin classStreamOutput
-
flush
public void flush()Description copied from class:StreamOutputForces any buffered output to be written.- Specified by:
flushin interfaceFlushable- Specified by:
flushin classStreamOutput
-
close
public void close()Description copied from class:StreamOutputCloses this stream to further operations.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classStreamOutput
-