@Test public void putStream() throws IOException { BaseByteArrayWriter byteArrayWriter = new BaseByteArrayWriter(dataWriter, posWriter, lenWriter, true, lastPosWriter, lastPosReader); OutputStream output = byteArrayWriter.putStream(0); output.write(new byte[]{1, 2, 3}); output.close(); verifyZeroInteractions(lastPosWriter, lastPosReader); verify(posWriter).put(0, 0); verify(lenWriter).put(0, 3); verify(dataWriter).put(0, (byte) 1); verify(dataWriter).put(1, (byte) 2); verify(dataWriter).put(2, (byte) 3); assertEquals(3L, (long) Whitebox.getInternalState(byteArrayWriter, "curPos")); output = byteArrayWriter.putStream(1); output.close(); verify(posWriter).put(1, 3); verify(lenWriter).put(1, 0); verifyNoMoreInteractions(dataWriter); assertEquals(3L, (long) Whitebox.getInternalState(byteArrayWriter, "curPos")); when(lastPosReader.isReadable()).thenReturn(true); when(lastPosReader.get(0)).thenReturn(3L); byteArrayWriter = new BaseByteArrayWriter(dataWriter, posWriter, lenWriter, false, lastPosWriter, lastPosReader); assertEquals(3L, (long) Whitebox.getInternalState(byteArrayWriter, "curPos")); }
@Override public OutputStream putStream(final long pos) { posWriter.put(pos, curPos); return new OutputStream() { long cursor = curPos; @Override public void write(int b) { dataWriter.put(cursor, (byte) b); cursor++; } @Override public void close() { try { lenWriter.put(pos, (int) (cursor - curPos)); } finally { curPos = cursor; } } }; }
BaseByteArrayWriter implements ByteArrayWriter { @Override public OutputStream putStream(final long pos) { posWriter.put(pos, curPos); return new OutputStream() { long cursor = curPos; @Override public void write(int b) { dataWriter.put(cursor, (byte) b); cursor++; } @Override public void close() { try { lenWriter.put(pos, (int) (cursor - curPos)); } finally { curPos = cursor; } } }; } }
BaseByteArrayWriter implements ByteArrayWriter { @Override public OutputStream putStream(final long pos) { posWriter.put(pos, curPos); return new OutputStream() { long cursor = curPos; @Override public void write(int b) { dataWriter.put(cursor, (byte) b); cursor++; } @Override public void close() { try { lenWriter.put(pos, (int) (cursor - curPos)); } finally { curPos = cursor; } } }; } BaseByteArrayWriter(ByteWriter dataWriter, LongWriter posWriter, IntWriter lenWriter, boolean isOverwrite, @Nullable LongWriter lastPosWriter, @Nullable LongReader lastPosReader); }
BaseByteArrayWriter implements ByteArrayWriter { @Override public OutputStream putStream(final long pos) { posWriter.put(pos, curPos); return new OutputStream() { long cursor = curPos; @Override public void write(int b) { dataWriter.put(cursor, (byte) b); cursor++; } @Override public void close() { try { lenWriter.put(pos, (int) (cursor - curPos)); } finally { curPos = cursor; } } }; } BaseByteArrayWriter(ByteWriter dataWriter, LongWriter posWriter, IntWriter lenWriter, boolean isOverwrite, @Nullable LongWriter lastPosWriter, @Nullable LongReader lastPosReader); @Override void put(long pos, byte[] val); @Override OutputStream putStream(final long pos); @Override void resetContentPosition(); @Override void release(); }
BaseByteArrayWriter implements ByteArrayWriter { @Override public OutputStream putStream(final long pos) { posWriter.put(pos, curPos); return new OutputStream() { long cursor = curPos; @Override public void write(int b) { dataWriter.put(cursor, (byte) b); cursor++; } @Override public void close() { try { lenWriter.put(pos, (int) (cursor - curPos)); } finally { curPos = cursor; } } }; } BaseByteArrayWriter(ByteWriter dataWriter, LongWriter posWriter, IntWriter lenWriter, boolean isOverwrite, @Nullable LongWriter lastPosWriter, @Nullable LongReader lastPosReader); @Override void put(long pos, byte[] val); @Override OutputStream putStream(final long pos); @Override void resetContentPosition(); @Override void release();  }