@Override public BlockBuilder appendNull() { if (currentEntrySize > 0) { throw new IllegalStateException("Current entry must be closed before a null can be written"); } checkCapacity(); hasNullValue = true; // fixed width is always written regardless of null flag sliceOutput.writeZero(fixedSize); entryAdded(true); return this; }
@Override public void writeZero(int length) { slice = Slices.ensureSize(slice, size + length); super.writeZero(length); }
@Override public void writeZero(int length) { slice = Slices.ensureSize(slice, size + length); super.writeZero(length); }
@Override public BlockBuilder appendNull() { if (currentEntrySize > 0) { throw new IllegalStateException("Current entry must be closed before a null can be written"); } checkCapacity(); hasNullValue = true; // fixed width is always written regardless of null flag sliceOutput.writeZero(fixedSize); entryAdded(true); return this; }
@Override public BlockBuilder appendNull() { if (currentEntrySize > 0) { throw new IllegalStateException("Current entry must be closed before a null can be written"); } checkCapacity(); hasNullValue = true; // fixed width is always written regardless of null flag sliceOutput.writeZero(fixedSize); entryAdded(true); return this; }
private void assertEncoding(Consumer<SliceOutput> operations, int offset, byte... output) throws IOException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); try (SliceOutput sliceOutput = new OutputStreamSliceOutput(byteArrayOutputStream, 16384)) { sliceOutput.writeZero(offset); operations.accept(sliceOutput); assertEquals(sliceOutput.size(), offset + output.length); } byte[] expected = new byte[offset + output.length]; System.arraycopy(output, 0, expected, offset, output.length); assertEquals(byteArrayOutputStream.toByteArray(), expected); } }
private void assertEncoding(Consumer<SliceOutput> operations, int offset, byte... output) throws IOException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); try (SliceOutput sliceOutput = new OutputStreamSliceOutput(byteArrayOutputStream, 16384)) { sliceOutput.writeZero(offset); operations.accept(sliceOutput); assertEquals(sliceOutput.size(), offset + output.length); } byte[] expected = new byte[offset + output.length]; System.arraycopy(output, 0, expected, offset, output.length); assertEquals(byteArrayOutputStream.toByteArray(), expected); } }
@Test public void testWriteZero() throws Exception { assertEncoding(sliceOutput -> sliceOutput.writeZero(0), new byte[0]); assertEncoding(sliceOutput -> sliceOutput.writeZero(1), new byte[1]); assertEncoding(sliceOutput -> sliceOutput.writeZero(2), new byte[2]); assertEncoding(sliceOutput -> sliceOutput.writeZero(3), new byte[3]); assertEncoding(sliceOutput -> sliceOutput.writeZero(4), new byte[4]); assertEncoding(sliceOutput -> sliceOutput.writeZero(6), new byte[6]); assertEncoding(sliceOutput -> sliceOutput.writeZero(7), new byte[7]); assertEncoding(sliceOutput -> sliceOutput.writeZero(8), new byte[8]); assertEncoding(sliceOutput -> sliceOutput.writeZero(9), new byte[9]); assertEncoding(sliceOutput -> sliceOutput.writeZero(16), new byte[16]); assertEncoding(sliceOutput -> sliceOutput.writeZero(22), new byte[22]); assertEncoding(sliceOutput -> sliceOutput.writeZero(227), new byte[227]); assertEncoding(sliceOutput -> sliceOutput.writeZero(4227), new byte[4227]); assertEncoding(sliceOutput -> sliceOutput.writeZero(18349), new byte[18349]); }
@Test public void testWriteZero() throws Exception { assertEncoding(sliceOutput -> sliceOutput.writeZero(0), new byte[0]); assertEncoding(sliceOutput -> sliceOutput.writeZero(1), new byte[1]); assertEncoding(sliceOutput -> sliceOutput.writeZero(2), new byte[2]); assertEncoding(sliceOutput -> sliceOutput.writeZero(3), new byte[3]); assertEncoding(sliceOutput -> sliceOutput.writeZero(4), new byte[4]); assertEncoding(sliceOutput -> sliceOutput.writeZero(6), new byte[6]); assertEncoding(sliceOutput -> sliceOutput.writeZero(7), new byte[7]); assertEncoding(sliceOutput -> sliceOutput.writeZero(8), new byte[8]); assertEncoding(sliceOutput -> sliceOutput.writeZero(9), new byte[9]); assertEncoding(sliceOutput -> sliceOutput.writeZero(16), new byte[16]); assertEncoding(sliceOutput -> sliceOutput.writeZero(22), new byte[22]); assertEncoding(sliceOutput -> sliceOutput.writeZero(227), new byte[227]); assertEncoding(sliceOutput -> sliceOutput.writeZero(4227), new byte[4227]); assertEncoding(sliceOutput -> sliceOutput.writeZero(18349), new byte[18349]); }