BinaryEncoder implementation that writes large arrays and maps as a
sequence of blocks. So long as individual primitive values fit in memory,
arbitrarily long arrays and maps may be written and subsequently read without
exhausting memory. Values are buffered until the specified block size would
be exceeded, minimizing block overhead.
Use EncoderFactory#blockingBinaryEncoder(OutputStream, BinaryEncoder)
to construct and configure.
BlockingBinaryEncoder buffers writes, data may not appear on the output until
flush() is called.
BlockingBinaryEncoder is not thread-safe
BinaryEncoder, EncoderFactory, Encoder
| Modifier and Type | Class and Description |
|---|---|
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private BlockingBinaryEncoder. | blockStack
The state stack. |
| private byte[] | buf
The buffer to hold the bytes before being written into the underlying stream.
|
| private byte[] | |
| private int | pos
Hides org. buf, where next byte can be written.
|
| private static final int | |
| private int |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public int | bytesBuffered()
Overrides org. |
| private boolean | |
| private void | |
| pack-priv BlockingBinaryEncoder | |
| private void | |
| private void | |
| private void | ensureBounds(int l)
Hides org. |
| private void | |
| private void | |
| public void | flush()
Overrides org. Implements java. |
| public void | setItemCount(long
The number of itemCount)
Call this method before writing a batch of items in an array or a map.
startItem() calls to follow. |
| public void | startItem()
Overrides org. |
| private void | |
| public void | writeArrayEnd()
Call this method to finish writing an array.
|
| public void | writeArrayStart()
Call this method to start writing an array.
|
| public void | writeBoolean(boolean b)
Overrides org. |
| public void | writeDouble(double d)
Overrides org. |
| public void | writeFixed(byte[]
The contents to write bytes, int The position within bytes where the contents start. start, int The number of bytes to write. len)Overrides org. |
| public void | writeFixed(ByteBuffer bytes)
Overrides org. |
| public void | |
| public void | writeIndex(int unionIndex)
Overrides org. |
| public void | writeInt(int n)
Overrides org. |
| public void | writeLong(long n)
Overrides org. |
| public void | writeMapEnd()
Overrides org. |
| public void | writeMapStart()
Call this to start a new map.
|
| protected void | writeZero()
Overrides org. |
| blockStack | back to summary |
|---|---|
| private BlockingBinaryEncoder. The state stack. | |
| buf | back to summary |
|---|---|
| private byte[] buf Hides org. The buffer to hold the bytes before being written into the underlying stream. | |
| headerBuffer | back to summary |
|---|---|
| private byte[] headerBuffer | |
| pos | back to summary |
|---|---|
| private int pos Hides org. Index into the location in | |
| STACK_STEP | back to summary |
|---|---|
| private static final int STACK_STEP | |
| stackTop | back to summary |
|---|---|
| private int stackTop | |
| BlockingBinaryEncoder | back to summary |
|---|---|
| pack-priv BlockingBinaryEncoder(OutputStream out, int blockBufferSize, int binaryEncoderBufferSize) | |
| bytesBuffered | back to summary |
|---|---|
| public int bytesBuffered() Overrides org. Doc from org. Returns the number of bytes currently buffered by this encoder. If this Encoder does not buffer, this will always return zero.
Call
| |
| check | back to summary |
|---|---|
| private boolean check() | |
| compact | back to summary |
|---|---|
| private void compact() throws IOException Only call if you're there are REGULAR-state values on the stack. | |
| configure | back to summary |
|---|---|
| pack-priv BlockingBinaryEncoder configure(OutputStream out, int blockBufferSize, int binaryEncoderBufferSize) | |
| doWriteBytes | back to summary |
|---|---|
| private void doWriteBytes(byte[] bytes, int start, int len) throws IOException | |
| endBlockedValue | back to summary |
|---|---|
| private void endBlockedValue() throws IOException | |
| ensureBounds | back to summary |
|---|---|
| private void ensureBounds(int l) throws IOException Hides org. Doc from org. Ensures that the buffer has at least num bytes free to write to between its current position and the end. This will not expand the buffer larger than its current size, for writes larger than or near to the size of the buffer, we flush the buffer and write directly to the output, bypassing the buffer. | |
| expandStack | back to summary |
|---|---|
| private void expandStack() | |
| finishOverflow | back to summary |
|---|---|
| private void finishOverflow() throws IOException Called when we've finished writing the last item in an overflow buffer. When this is finished, the top of the stack will be an empty block in the "regular" state. | |
| flush | back to summary |
|---|---|
| public void flush() throws IOException Overrides org. Implements java. Doc from java. Flushes this stream by writing any buffered output to the underlying stream.
| |
| setItemCount | back to summary |
|---|---|
| public void setItemCount(long itemCount) throws IOException Overrides org. Doc from org. Call this method before writing a batch of items in an array or a map. Then
for each item, call
| |
| startItem | back to summary |
|---|---|
| public void startItem() throws IOException Overrides org. Doc from org. Start a new item of an array or map. See
| |
| write | back to summary |
|---|---|
| private void write(byte[] b, int off, int len) throws IOException | |
| writeArrayEnd | back to summary |
|---|---|
| public void writeArrayEnd() throws IOException Overrides org. Doc from org. Call this method to finish writing an array. See
| |
| writeArrayStart | back to summary |
|---|---|
| public void writeArrayStart() throws IOException Overrides org. Doc from org. Call this method to start writing an array.
When starting to serialize an array, call
out.writeArrayStart();
out.setItemCount(list.size());
for (Record r : list) {
out.startItem();
out.writeLong(r.longField);
out.writeBoolean(r.boolField);
}
out.writeArrayEnd();
| |
| writeBoolean | back to summary |
|---|---|
| public void writeBoolean(boolean b) throws IOException Overrides org. Doc from org. Write a boolean value.
| |
| writeDouble | back to summary |
|---|---|
| public void writeDouble(double d) throws IOException Overrides org. Doc from org. Write a double.
| |
| writeFixed | back to summary |
|---|---|
| public void writeFixed(byte[] bytes, int start, int len) throws IOException Overrides org. Doc from org. Writes a fixed size binary object.
| |
| writeFixed | back to summary |
|---|---|
| public void writeFixed(ByteBuffer bytes) throws IOException Overrides org. Doc from org. Writes a fixed from a ByteBuffer.
| |
| writeFloat | back to summary |
|---|---|
| public void writeFloat(float f) throws IOException Overrides org. Doc from org. Write a float.
| |
| writeIndex | back to summary |
|---|---|
| public void writeIndex(int unionIndex) throws IOException Overrides org. Doc from org. Call this method to write the tag of a union. As an example of usage, let's say you want to write a union, whose second branch is a record consisting of an Long field and a Boolean field. Your code would look something like this: out.writeIndex(1); out.writeLong(record.longField); out.writeBoolean(record.boolField);
| |
| writeInt | back to summary |
|---|---|
| public void writeInt(int n) throws IOException Overrides org. Doc from org. Writes a 32-bit integer.
| |
| writeLong | back to summary |
|---|---|
| public void writeLong(long n) throws IOException Overrides org. Doc from org. Write a 64-bit integer.
| |
| writeMapEnd | back to summary |
|---|---|
| public void writeMapEnd() throws IOException Overrides org. Doc from org. Call this method to terminate the inner-most, currently-opened map. See
| |
| writeMapStart | back to summary |
|---|---|
| public void writeMapStart() throws IOException Overrides org. Doc from org. Call this to start a new map. See out.writeMapStart(); out.setItemCount(list.size()); for (Map.Entry
| |
| writeZero | back to summary |
|---|---|
| protected void writeZero() throws IOException Overrides org. Doc from org. Write a zero byte to the underlying output.
| |
| Modifier and Type | Class and Description |
|---|---|
| public static enum |
| Modifier and Type | Field and Description |
|---|---|
| public int | items
Number of items in this blocked value that are stored in the buffer. |
| public long | itemsLeftToWrite
Number of items left to write |
| public int | lastFullItem
The index one past the last byte for the previous item. |
| public int | start
The location in the buffer where this blocked value starts |
| public BlockingBinaryEncoder. | state
The state of this BlockedValue |
| public Schema. | type
The type of this blocked value (ARRAY or MAP). |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | check(BlockingBinaryEncoder.
Check invariants of |
| items | back to summary |
|---|---|
| public int items Number of items in this blocked value that are stored in the buffer. | |
| itemsLeftToWrite | back to summary |
|---|---|
| public long itemsLeftToWrite Number of items left to write | |
| lastFullItem | back to summary |
|---|---|
| public int lastFullItem The index one past the last byte for the previous item. If this is the first
item, this is same as | |
| start | back to summary |
|---|---|
| public int start The location in the buffer where this blocked value starts | |
| state | back to summary |
|---|---|
| public BlockingBinaryEncoder. The state of this BlockedValue | |
| type | back to summary |
|---|---|
| public Schema. The type of this blocked value (ARRAY or MAP). | |
| BlockedValue | back to summary |
|---|---|
| public BlockedValue() Create a ROOT instance. | |
| check | back to summary |
|---|---|
| public boolean check(BlockingBinaryEncoder. Check invariants of | |
| Modifier and Type | Field and Description |
|---|---|
| public static final BlockingBinaryEncoder. | OVERFLOW
Represents a blocked-value whose current block is in the overflow state. |
| public static final BlockingBinaryEncoder. | REGULAR
Represents the "regular" case, i.e., a blocked-value whose current block is fully contained in the buffer. |
| public static final BlockingBinaryEncoder. | ROOT
The bottom element of our stack represents being _outside_ of a blocked value. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static BlockingBinaryEncoder. | |
| public static BlockingBinaryEncoder. |
| OVERFLOW | back to summary |
|---|---|
| public static final BlockingBinaryEncoder. Represents a blocked-value whose current block is in the overflow state. In
this case, | |
| REGULAR | back to summary |
|---|---|
| public static final BlockingBinaryEncoder. Represents the "regular" case, i.e., a blocked-value whose current block is
fully contained in the buffer. In this case, | |
| ROOT | back to summary |
|---|---|
| public static final BlockingBinaryEncoder. The bottom element of our stack represents being _outside_ of a blocked value. | |
| State | back to summary |
|---|---|
| private State() | |
| valueOf | back to summary |
|---|---|
| public static BlockingBinaryEncoder. | |
| values | back to summary |
|---|---|
| public static BlockingBinaryEncoder. | |