private void endBlockedValue() throws IOException { for (; ;) { assert check(); BlockedValue t = blockStack[stackTop]; assert t.state != BlockedValue.State.ROOT; if (t.state == BlockedValue.State.OVERFLOW) { finishOverflow(); System.arraycopy(headerBuffer, 0, buf, m, headerSize); } else { compact(); continue; ensureBounds(1); buf[pos++] = 0; // Sentinel for last block in a blocked value assert check(); if (blockStack[stackTop].state == BlockedValue.State.ROOT) { flush();
@Override public void writeFixed(byte[] bytes, int start, int len) throws IOException { doWriteBytes(bytes, start, len); }
@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 startItem() throws IOException { if (blockStack[stackTop].state == BlockedValue.State.OVERFLOW) { finishOverflow(); } BlockedValue t = blockStack[stackTop]; t.items++; t.lastFullItem = pos; t.itemsLeftToWrite--; 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(); }
private void doWriteBytes(byte[] bytes, int start, int len) throws IOException { if (len < buf.length) { ensureBounds(len); System.arraycopy(bytes, start, buf, pos, len); pos += len; } else { ensureBounds(buf.length); assert blockStack[stackTop].state == BlockedValue.State.ROOT || blockStack[stackTop].state == BlockedValue.State.OVERFLOW; write(bytes, start, len); } }
private void endBlockedValue() throws IOException { for (; ;) { assert check(); BlockedValue t = blockStack[stackTop]; assert t.state != BlockedValue.State.ROOT; if (t.state == BlockedValue.State.OVERFLOW) { finishOverflow(); blockStack[stackTop - 1].state encodeLong(-t.items, out); encodeLong(byteCount, out); } else { encodeLong(-t.items, encoderBuffer); encodeLong(byteCount, encoderBuffer); final int headerSize = encoderBuffer.length(); if (buf.length >= pos + headerSize) { } else { encoderBuffer.reset(); compact(); continue; if (buf.length < (pos + 1)) ensure(1); buf[pos++] = 0; // Sentinel for last block in a blocked value assert check(); if (blockStack[stackTop].state == BlockedValue.State.ROOT) { flush();
@Override public void writeBytes(byte[] bytes, int start, int len) throws IOException { if (pos + 5 > buf.length) { ensure(5); } pos = encodeLong(len, buf, pos); doWriteBytes(bytes, start, len); 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(); }
private void doWriteBytes(byte[] bytes, int start, int len) throws IOException { if (len < buf.length) { ensure(len); System.arraycopy(bytes, start, buf, pos, len); pos += len; } else { ensure(buf.length); assert blockStack[stackTop].state == BlockedValue.State.ROOT || blockStack[stackTop].state == BlockedValue.State.OVERFLOW; write(bytes, start, len); } assert check(); }
@Override public void writeLong(long n) throws IOException { if (pos + 10 > buf.length) { ensure(10); } pos = encodeLong(n, buf, pos); assert check(); }
@Override public void writeFixed(byte[] bytes, int start, int len) throws IOException { doWriteBytes(bytes, start, len); assert check(); }
@Override public void writeDouble(double d) throws IOException { if (pos + 8 > buf.length) { ensure(8); } pos = encodeDouble(d, buf, pos); assert check(); }
private void ensureBounds(int l) throws IOException { while (buf.length < (pos + l)) { if (blockStack[stackTop].state == BlockedValue.State.REGULAR) { compact(); } else { super.writeFixed(buf, 0, pos); pos = 0; } } }
@Override public void writeBytes(ByteBuffer bytes) throws IOException { writeBytes(bytes.array(), bytes.position(), bytes.remaining()); assert check(); }
: this.binaryBufferSize; if (null == reuse || !reuse.getClass().equals(BlockingBinaryEncoder.class)) { return new BlockingBinaryEncoder(out, blockSize, bufferSize); } else { return ((BlockingBinaryEncoder) reuse).configure(out, blockSize, bufferSize);
@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(); }