return new BufferedBinaryEncoder(out, this.binaryBufferSize); } else { return ((BufferedBinaryEncoder)reuse).configure(out, this.binaryBufferSize);
@Override public int bytesBuffered() { return pos + super.bytesBuffered(); }
@Override public void writeFixed(byte[] bytes, int start, int len) throws IOException { if (len > bulkLimit) { //too big, write direct flushBuffer(); sink.innerWrite(bytes, start, len); return; } ensureBounds(len); System.arraycopy(bytes, start, buf, pos, len); pos += len; }
@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(); }
private void writeByte(int b) throws IOException { if (pos == buf.length) { flushBuffer(); } buf[pos++] = (byte) (b & 0xFF); }
@Override public void writeInt(int n) throws IOException { ensureBounds(5); pos += BinaryData.encodeInt(n, buf, pos); }
super.writeFixed(buf, 0, s.start); super.writeInt(-(s.items - 1)); super.writeInt(s.lastFullItem - s.start); super.writeFixed(buf, s.start, s.lastFullItem - s.start); s.start = s.lastFullItem; s.items = 1; super.writeInt(1); blockStack[i + 1] : null); int end = (n == null ? pos : n.start); super.writeFixed(buf, s.lastFullItem, end - s.lastFullItem);
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; } } }
BufferedBinaryEncoder(OutputStream out, int bufferSize) { configure(out, bufferSize); }
@Override protected void writeZero() throws IOException { writeByte(0); }
private void writeByte(int b) throws IOException { if (pos == buf.length) { flushBuffer(); } buf[pos++] = (byte) (b & 0xFF); }
@Override public void writeLong(long n) throws IOException { ensureBounds(10); pos += BinaryData.encodeLong(n, buf, pos); }
@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(); }
super.writeFixed(buf, 0, s.start); super.writeInt(-(s.items - 1)); super.writeInt(s.lastFullItem - s.start); super.writeFixed(buf, s.start, s.lastFullItem - s.start); s.start = s.lastFullItem; s.items = 1; super.writeInt(1); blockStack[i + 1] : null); int end = (n == null ? pos : n.start); super.writeFixed(buf, s.lastFullItem, end - s.lastFullItem);
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; } } }
BufferedBinaryEncoder(OutputStream out, int bufferSize) { configure(out, bufferSize); }
@Override protected void writeZero() throws IOException { writeByte(0); }
/** 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. * @param num * @throws IOException */ private void ensureBounds(int num) throws IOException { int remaining = buf.length - pos; if (remaining < num) { flushBuffer(); } }