Package org.apache.avro.io
Class DirectBinaryEncoder
java.lang.Object
org.apache.avro.io.Encoder
org.apache.avro.io.BinaryEncoder
org.apache.avro.io.DirectBinaryEncoder
- All Implemented Interfaces:
Flushable
- Direct Known Subclasses:
BlockingDirectBinaryEncoder
An
Encoder
for Avro's binary encoding that does not buffer output.
This encoder does not buffer writes, and as a result is slower than
BufferedBinaryEncoder
. However, it is lighter-weight and useful when
the buffering in BufferedBinaryEncoder is not desired and/or the Encoder is
very short-lived.
To construct, use
EncoderFactory.directBinaryEncoder(OutputStream, BinaryEncoder)
DirectBinaryEncoder is not thread-safe- See Also:
-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
Create a writer that sends its output to the underlying streamout
. -
Method Summary
Modifier and TypeMethodDescriptionint
Returns the number of bytes currently buffered by this encoder.void
flush()
void
writeBoolean
(boolean b) Write a boolean value.void
writeDouble
(double d) Write a double.void
writeFixed
(byte[] bytes, int start, int len) Writes a fixed size binary object.void
writeFloat
(float f) Write a float.void
writeInt
(int n) Writes a 32-bit integer.void
writeLong
(long n) Write a 64-bit integer.protected void
Write a zero byte to the underlying output.Methods inherited from class org.apache.avro.io.BinaryEncoder
setItemCount, startItem, writeArrayEnd, writeArrayStart, writeBytes, writeBytes, writeEnum, writeIndex, writeMapEnd, writeMapStart, writeNull, writeString, writeString
Methods inherited from class org.apache.avro.io.Encoder
writeBytes, writeFixed, writeFixed, writeString
-
Field Details
-
out
-
-
Constructor Details
-
DirectBinaryEncoder
Create a writer that sends its output to the underlying streamout
.
-
-
Method Details
-
flush
- Throws:
IOException
-
writeBoolean
Description copied from class:Encoder
Write a boolean value.- Specified by:
writeBoolean
in classEncoder
- Throws:
IOException
-
writeInt
Description copied from class:Encoder
Writes a 32-bit integer.- Specified by:
writeInt
in classEncoder
- Throws:
IOException
-
writeLong
Description copied from class:Encoder
Write a 64-bit integer.- Specified by:
writeLong
in classEncoder
- Throws:
IOException
-
writeFloat
Description copied from class:Encoder
Write a float.- Specified by:
writeFloat
in classEncoder
- Throws:
IOException
-
writeDouble
Description copied from class:Encoder
Write a double.- Specified by:
writeDouble
in classEncoder
- Throws:
IOException
-
writeFixed
Description copied from class:Encoder
Writes a fixed size binary object.- Specified by:
writeFixed
in classEncoder
- Parameters:
bytes
- The contents to writestart
- The position within bytes where the contents start.len
- The number of bytes to write.- Throws:
IOException
-
writeZero
Description copied from class:BinaryEncoder
Write a zero byte to the underlying output.- Specified by:
writeZero
in classBinaryEncoder
- Throws:
IOException
-
bytesBuffered
public int bytesBuffered()Description copied from class:BinaryEncoder
Returns the number of bytes currently buffered by this encoder. If this Encoder does not buffer, this will always return zero. CallFlushable.flush()
to empty the buffer to the underlying output.- Specified by:
bytesBuffered
in classBinaryEncoder
-