Class DataOutput
- Direct Known Subclasses:
ByteArrayDataOutput,ByteBuffersDataOutput,IndexOutput,OutputStreamDataOutput,PagedBytes.PagedBytesDataOutput
DataOutput may only be used from one thread, because it is not thread safe (it keeps
internal state like file position).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidCopy numBytes bytes from input to ourself.abstract voidwriteByte(byte b) Writes a single byte.voidwriteBytes(byte[] b, int length) Writes an array of bytes.abstract voidwriteBytes(byte[] b, int offset, int length) Writes an array of bytes.voidwriteGroupVInts(int[] values, int limit) Encode integers using group-varint.voidwriteGroupVInts(long[] values, int limit) Encode integers using group-varint.voidwriteInt(int i) Writes an int as four bytes (LE byte order).voidwriteLong(long i) Writes a long as eight bytes (LE byte order).voidwriteMapOfStrings(Map<String, String> map) Writes a String map.voidwriteSetOfStrings(Set<String> set) Writes a String set.voidwriteShort(short i) Writes a short as two bytes (LE byte order).voidWrites a string.final voidwriteVInt(int i) Writes an int in a variable-length format.final voidwriteVLong(long i) Writes an long in a variable-length format.final voidwriteZInt(int i) Write azig-zag-encodedvariable-lengthinteger.final voidwriteZLong(long i) Write azig-zag-encodedvariable-lengthlong.
-
Constructor Details
-
DataOutput
public DataOutput()
-
-
Method Details
-
writeByte
Writes a single byte.The most primitive data type is an eight-bit byte. Files are accessed as sequences of bytes. All other data types are defined as sequences of bytes, so file formats are byte-order independent.
- Throws:
IOException- See Also:
-
writeBytes
Writes an array of bytes.- Parameters:
b- the bytes to writelength- the number of bytes to write- Throws:
IOException- See Also:
-
writeBytes
Writes an array of bytes.- Parameters:
b- the bytes to writeoffset- the offset in the byte arraylength- the number of bytes to write- Throws:
IOException- See Also:
-
writeInt
Writes an int as four bytes (LE byte order).- Throws:
IOException- See Also:
-
writeShort
Writes a short as two bytes (LE byte order).- Throws:
IOException- See Also:
-
writeVInt
Writes an int in a variable-length format. Writes between one and five bytes. Smaller values take fewer bytes. Negative numbers are supported, but should be avoided.VByte is a variable-length format for positive integers is defined where the high-order bit of each byte indicates whether more bytes remain to be read. The low-order seven bits are appended as increasingly more significant bits in the resulting integer value. Thus values from zero to 127 may be stored in a single byte, values from 128 to 16,383 may be stored in two bytes, and so on.
VByte Encoding Example
variable length encoding examples Value Byte 1 Byte 2 Byte 3 0 000000001 000000012 00000010... 127 01111111128 1000000000000001129 1000000100000001130 1000001000000001... 16,383 111111110111111116,384 10000000100000000000000116,385 100000011000000000000001... This provides compression while still being efficient to decode.
- Parameters:
i- Smaller values take fewer bytes. Negative numbers are supported, but should be avoided.- Throws:
IOException- If there is an I/O error writing to the underlying medium.- See Also:
-
writeZInt
Write azig-zag-encodedvariable-lengthinteger. This is typically useful to write small signed ints and is equivalent to callingwriteVInt(BitUtil.zigZagEncode(i)).- Throws:
IOException- See Also:
-
writeLong
Writes a long as eight bytes (LE byte order).- Throws:
IOException- See Also:
-
writeVLong
Writes an long in a variable-length format. Writes between one and nine bytes. Smaller values take fewer bytes. Negative numbers are not supported.The format is described further in
writeVInt(int).- Throws:
IOException- See Also:
-
writeZLong
Write azig-zag-encodedvariable-lengthlong. Writes between one and ten bytes. This is typically useful to write small signed ints.- Throws:
IOException- See Also:
-
writeString
Writes a string.Writes strings as UTF-8 encoded bytes. First the length, in bytes, is written as a
VInt, followed by the bytes.- Throws:
IOException- See Also:
-
copyBytes
Copy numBytes bytes from input to ourself.- Throws:
IOException
-
writeMapOfStrings
Writes a String map.First the size is written as an
vInt, followed by each key-value pair written as two consecutiveStrings.- Parameters:
map- Input map.- Throws:
NullPointerException- ifmapis null.IOException
-
writeSetOfStrings
Writes a String set.First the size is written as an
vInt, followed by each value written as aString.- Parameters:
set- Input set.- Throws:
NullPointerException- ifsetis null.IOException
-
writeGroupVInts
Encode integers using group-varint. It usesVIntto encode tail values that are not enough for a group. we need a long[] because this is what postings are using, all longs are actually required to be integers.- Parameters:
values- the values to writelimit- the number of values to write.- Throws:
IOException- WARNING: This API is experimental and might change in incompatible ways in the next release.
-
writeGroupVInts
Encode integers using group-varint. It usesVIntto encode tail values that are not enough for a group.- Parameters:
values- the values to writelimit- the number of values to write.- Throws:
IOException- WARNING: This API is experimental and might change in incompatible ways in the next release.
-