@Override public void setItemCount(long itemCount) throws IOException { BlockedValue v = blockStack[stackTop]; assert v.type == Schema.Type.ARRAY || v.type == Schema.Type.MAP; assert v.itemsLeftToWrite == 0; v.itemsLeftToWrite = itemCount; assert check(); }
@Override public void setItemCount(long itemCount) throws IOException { BlockedValue v = blockStack[stackTop]; assert v.type == Schema.Type.ARRAY || v.type == Schema.Type.MAP; assert v.itemsLeftToWrite == 0; v.itemsLeftToWrite = itemCount; assert check(); }
@Override public void startItem() throws IOException { if (blockStack[stackTop].state == BlockedValue.State.OVERFLOW) { finishOverflow(); } BlockedValue t = blockStack[stackTop]; t.items++; t.lastFullItem = pos; t.itemsLeftToWrite--; assert check(); }
BlockingBinaryEncoder configure(OutputStream out, int blockBufferSize, int binaryEncoderBufferSize) { super.configure(out, binaryEncoderBufferSize); pos = 0; stackTop = 0; if (null == buf || buf.length != blockBufferSize) { buf = new byte[blockBufferSize]; } assert check(); return this; }
@Override public void writeMapStart() throws IOException { if (stackTop + 1 == blockStack.length) { expandStack(); } BlockedValue bv = blockStack[++stackTop]; bv.type = Schema.Type.MAP; bv.state = BlockedValue.State.REGULAR; bv.start = bv.lastFullItem = pos; bv.items = 0; assert check(); }
/** * 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. * @throws IOException */ private void finishOverflow() throws IOException { BlockedValue s = blockStack[stackTop]; if (s.state != BlockedValue.State.OVERFLOW) { throw new IllegalStateException("Not an overflow block"); } assert check(); // Flush any remaining data for this block super.writeFixed(buf, 0, pos); pos = 0; // Reset top of stack to be in REGULAR mode s.state = BlockedValue.State.REGULAR; s.start = s.lastFullItem = 0; s.items = 0; assert check(); }
@Override public void writeMapStart() throws IOException { if (stackTop + 1 == blockStack.length) { expandStack(); } BlockedValue bv = blockStack[++stackTop]; bv.type = Schema.Type.MAP; bv.state = BlockedValue.State.REGULAR; bv.start = bv.lastFullItem = pos; bv.items = 0; assert check(); }
@Override public void writeArrayStart() throws IOException { if (stackTop + 1 == blockStack.length) { expandStack(); } BlockedValue bv = blockStack[++stackTop]; bv.type = Schema.Type.ARRAY; bv.state = BlockedValue.State.REGULAR; bv.start = bv.lastFullItem = pos; bv.items = 0; assert check(); }
@Override public void writeArrayStart() throws IOException { if (stackTop + 1 == blockStack.length) { expandStack(); } BlockedValue bv = blockStack[++stackTop]; bv.type = Schema.Type.ARRAY; bv.state = BlockedValue.State.REGULAR; bv.start = bv.lastFullItem = pos; bv.items = 0; assert check(); }
BlockingBinaryEncoder configure(OutputStream out, int blockBufferSize, int binaryEncoderBufferSize) { super.configure(out, binaryEncoderBufferSize); pos = 0; stackTop = 0; if (null == buf || buf.length != blockBufferSize) { buf = new byte[blockBufferSize]; } assert check(); return this; }
@Override public void startItem() throws IOException { if (blockStack[stackTop].state == BlockedValue.State.OVERFLOW) { finishOverflow(); } BlockedValue t = blockStack[stackTop]; t.items++; t.lastFullItem = pos; t.itemsLeftToWrite--; assert check(); }
BlockingBinaryEncoder(OutputStream out, int blockBufferSize, int binaryEncoderBufferSize) { super(out, binaryEncoderBufferSize); this.buf = new byte[blockBufferSize]; this.pos = 0; blockStack = new BlockedValue[0]; expandStack(); BlockedValue bv = blockStack[++stackTop]; bv.type = null; bv.state = BlockedValue.State.ROOT; bv.start = bv.lastFullItem = 0; bv.items = 1; assert check(); }
BlockingBinaryEncoder(OutputStream out, int blockBufferSize, int binaryEncoderBufferSize) { super(out, binaryEncoderBufferSize); this.buf = new byte[blockBufferSize]; this.pos = 0; blockStack = new BlockedValue[0]; expandStack(); BlockedValue bv = blockStack[++stackTop]; bv.type = null; bv.state = BlockedValue.State.ROOT; bv.start = bv.lastFullItem = 0; bv.items = 1; assert check(); }
private void write(byte[] b, int off, int len) throws IOException { if (blockStack[stackTop].state == BlockedValue.State.ROOT) { super.writeFixed(b, off, len); } else { assert check(); while (buf.length < (pos + len)) { if (blockStack[stackTop].state == BlockedValue.State.REGULAR) { compact(); } else { super.writeFixed(buf, 0, pos); pos = 0; if (buf.length <= len) { super.writeFixed(b, off, len); len = 0; } } } System.arraycopy(b, off, buf, pos, len); pos += len; } assert check(); }
@Override public void writeArrayEnd() throws IOException { BlockedValue top = blockStack[stackTop]; if (top.type != Schema.Type.ARRAY) { throw new AvroTypeException("Called writeArrayEnd outside of an array."); } if (top.itemsLeftToWrite != 0) { throw new AvroTypeException("Failed to write expected number of array elements."); } endBlockedValue(); assert check(); }
@Override public void writeMapEnd() throws IOException { BlockedValue top = blockStack[stackTop]; if (top.type != Schema.Type.MAP) { throw new AvroTypeException("Called writeMapEnd outside of a map."); } if (top.itemsLeftToWrite != 0) { throw new AvroTypeException("Failed to read write expected number of array elements."); } endBlockedValue(); assert check(); }
@Override public void writeArrayEnd() throws IOException { BlockedValue top = blockStack[stackTop]; if (top.type != Schema.Type.ARRAY) { throw new AvroTypeException("Called writeArrayEnd outside of an array."); } if (top.itemsLeftToWrite != 0) { throw new AvroTypeException("Failed to write expected number of array elements."); } endBlockedValue(); assert check(); }
@Override public void writeMapEnd() throws IOException { BlockedValue top = blockStack[stackTop]; if (top.type != Schema.Type.MAP) { throw new AvroTypeException("Called writeMapEnd outside of a map."); } if (top.itemsLeftToWrite != 0) { throw new AvroTypeException("Failed to read write expected number of array elements."); } endBlockedValue(); assert check(); }
@Override public void flush() throws IOException { BlockedValue bv = blockStack[stackTop]; if (bv.state == BlockedValue.State.ROOT) { super.writeFixed(buf, 0, pos); pos = 0; } else { while (bv.state != BlockedValue.State.OVERFLOW) { compact(); } } super.flush(); assert check(); }
@Override public void flush() throws IOException { BlockedValue bv = blockStack[stackTop]; if (bv.state == BlockedValue.State.ROOT) { super.writeFixed(buf, 0, pos); pos = 0; } else { while (bv.state != BlockedValue.State.OVERFLOW) { compact(); } } super.flush(); assert check(); }