@Override public void writeBytes(byte[] b, int length) { writeBytes(b, 0, length); }
public void writeBytes(byte[] b) { writeBytes(b, 0, b.length); }
@Override public void writeBytes(byte[] b, int offset, int length) throws IOException { ensureOpen(); delegate.writeBytes(b, offset, length); }
@Override public void writeBytes(byte[] b, int length) throws IOException { ensureOpen(); delegate.writeBytes(b, length); }
@Override public void writeString(String v) { try { final int MAX_CHARS_PER_WINDOW = 1024; if (v.length() <= MAX_CHARS_PER_WINDOW) { final BytesRef utf8 = new BytesRef(v); writeVInt(utf8.length); writeBytes(utf8.bytes, utf8.offset, utf8.length); } else { writeVInt(UnicodeUtil.calcUTF16toUTF8Length(v, 0, v.length())); final byte [] buf = new byte [UnicodeUtil.MAX_UTF8_BYTES_PER_CHAR * MAX_CHARS_PER_WINDOW]; UTF16toUTF8(v, 0, v.length(), buf, (len) -> { writeBytes(buf, 0, len); }); } } catch (IOException e) { throw new UncheckedIOException(e); } }
private void rewriteToBlockSize(int targetBlockBits) { assert targetBlockBits <= maxBitsPerBlock; // We copy over data blocks to an output with one-larger block bit size. // We also discard references to blocks as we're copying to allow GC to // clean up partial results in case of memory pressure. ByteBuffersDataOutput cloned = new ByteBuffersDataOutput(targetBlockBits, targetBlockBits, blockAllocate, NO_REUSE); ByteBuffer block; while ((block = blocks.pollFirst()) != null) { block.flip(); cloned.writeBytes(block); if (blockReuse != NO_REUSE) { blockReuse.accept(block); } } assert blocks.isEmpty(); this.blockBits = targetBlockBits; blocks.addAll(cloned.blocks); }
public void writeBytes(byte[] b) { writeBytes(b, 0, b.length); }
@Override public void writeBytes(byte[] b, int length) { writeBytes(b, 0, length); }
@Override public void writeBytes(byte[] b, int length) throws IOException { ensureOpen(); delegate.writeBytes(b, length); }
@Override public void writeBytes(byte[] b, int offset, int length) throws IOException { ensureOpen(); delegate.writeBytes(b, offset, length); }
private void rewriteToBlockSize(int targetBlockBits) { assert targetBlockBits <= maxBitsPerBlock; // We copy over data blocks to an output with one-larger block bit size. // We also discard references to blocks as we're copying to allow GC to // clean up partial results in case of memory pressure. ByteBuffersDataOutput cloned = new ByteBuffersDataOutput(targetBlockBits, targetBlockBits, blockAllocate, NO_REUSE); ByteBuffer block; while ((block = blocks.pollFirst()) != null) { block.flip(); cloned.writeBytes(block); if (blockReuse != NO_REUSE) { blockReuse.accept(block); } } assert blocks.isEmpty(); this.blockBits = targetBlockBits; blocks.addAll(cloned.blocks); }
@Override public void writeString(String v) { try { final int MAX_CHARS_PER_WINDOW = 1024; if (v.length() <= MAX_CHARS_PER_WINDOW) { final BytesRef utf8 = new BytesRef(v); writeVInt(utf8.length); writeBytes(utf8.bytes, utf8.offset, utf8.length); } else { writeVInt(UnicodeUtil.calcUTF16toUTF8Length(v, 0, v.length())); final byte [] buf = new byte [UnicodeUtil.MAX_UTF8_BYTES_PER_CHAR * MAX_CHARS_PER_WINDOW]; UTF16toUTF8(v, 0, v.length(), buf, (len) -> { writeBytes(buf, 0, len); }); } } catch (IOException e) { throw new UncheckedIOException(e); } }