VCDiffCodeTableWriterImpl implements com.davidehrmann.vcdiff.VCDiffCodeTableWriter<OutputStream> { public void output(OutputStream out) throws IOException { if (instructionsAndSizes.position() == 0) { LOGGER.warn("Empty input; no delta window produced"); } else { CountingOutputStream countedOut = new CountingOutputStream(out); if (addChecksum) { countedOut.write(VCD_SOURCE | VCD_CHECKSUM); } else { countedOut.write(VCD_SOURCE); } VarInt.writeInt(countedOut, dictionarySize); VarInt.writeInt(countedOut, 0); final int length_of_the_delta_encoding = this.calculateLengthOfTheDeltaEncoding(); VarInt.writeInt(countedOut, length_of_the_delta_encoding); final int size_before_delta_encoding = (int) countedOut.getBytesWritten(); VarInt.writeInt(countedOut, targetLength); countedOut.write(0x00); VarInt.writeInt(countedOut, separateDataForAddAndRun.position()); VarInt.writeInt(countedOut, instructionsAndSizes.position()); VarInt.writeInt(countedOut, separateAddressesForCopy.position()); if (addChecksum) { VarInt.writeLong(countedOut, checksum); } countedOut.write(separateDataForAddAndRun.array(), separateDataForAddAndRun.arrayOffset(), separateDataForAddAndRun.position()); countedOut.write(instructionsAndSizes.array(), instructionsAndSizes.arrayOffset(), instructionsAndSizes.position()); countedOut.write(separateAddressesForCopy.array(), separateAddressesForCopy.arrayOffset(), separateAddressesForCopy.position()); final int size_after_delta_encoding = (int) countedOut.getBytesWritten(); if (length_of_the_delta_encoding != (size_after_delta_encoding - size_before_delta_encoding)) { throw new IllegalStateException(String.format( "Internal error: calculated length of the delta encoding (%d) does not match actual length (%d)", length_of_the_delta_encoding, size_after_delta_encoding - size_before_delta_encoding )); } separateDataForAddAndRun.clear(); instructionsAndSizes.clear(); separateAddressesForCopy.clear(); if (targetLength == 0) { LOGGER.warn("Empty target window"); } } init(dictionarySize); } VCDiffCodeTableWriterImpl(boolean interleaved);   VCDiffCodeTableWriterImpl(boolean interleaved, short nearCacheSize, short sameCacheSize, VCDiffCodeTableData codeTableData, short maxMode); void init(int dictionarySize); void add(byte[] data, int offset, int length); void addChecksum(int checksum); void copy(int offset, int size); void finishEncoding(OutputStream out); int getDeltaWindowSize(); void output(OutputStream out); void run(int size, byte b); void writeHeader(OutputStream out, EnumSet<VCDiffFormatExtension> formatExtensions); int targetLength();  }
@Test public void WriterOutputWithoutInit() throws IOException { standard_writer.output(out); assertEquals(0, out.size()); }