@Test public void testWriteAll_Multiple() throws IOException { UnitTestZipEntry entryA = UnitTestZipArchive.makeUnitTestZipEntry("/bar", 3, "dragon lance", null); UnitTestZipEntry entryB = UnitTestZipArchive.makeUnitTestZipEntry("/baz", 8, "kender & hoopak", null); ByteArrayOutputStream expected = new ByteArrayOutputStream(); byte[] expectedBytes1 = new byte[] {1, 2, 3, 4, 5}; expected.write(expectedBytes1); stream.pipe(new ByteArrayInputStream(expectedBytes1), Mode.COPY); stream.pipe( new ByteArrayInputStream(entryA.getCompressedBinaryContent()), Mode.UNCOMPRESS_NOWRAP); expected.write(entryA.getUncompressedBinaryContent()); byte[] expectedBytes3 = new byte[] {6, 7, 8, 9, 0}; stream.pipe(new ByteArrayInputStream(expectedBytes3), Mode.COPY); expected.write(expectedBytes3); stream.pipe( new ByteArrayInputStream(entryB.getCompressedBinaryContent()), Mode.UNCOMPRESS_NOWRAP); expected.write(entryB.getUncompressedBinaryContent()); byte[] expectedBytes5 = new byte[] {127, 127, 127, 127, 127, 127}; stream.pipe(new ByteArrayInputStream(expectedBytes5), Mode.COPY); expected.write(expectedBytes5); Assert.assertArrayEquals(expected.toByteArray(), outBuffer.toByteArray()); }
public long pipe(InputStream in, Mode mode) throws IOException { long bytesWrittenBefore = out.getNumBytesWritten(); if (mode == Mode.COPY) { int numRead = 0; while ((numRead = in.read(copyBuffer)) >= 0) { out.write(copyBuffer, 0, numRead); } } else { uncompressor.setNowrap(mode == Mode.UNCOMPRESS_NOWRAP); uncompressor.uncompress(in, out); } out.flush(); return out.getNumBytesWritten() - bytesWrittenBefore; }
PartiallyUncompressingPipe implements Closeable { public long pipe(InputStream in, Mode mode) throws IOException { long bytesWrittenBefore = out.getNumBytesWritten(); if (mode == Mode.COPY) { int numRead = 0; while ((numRead = in.read(copyBuffer)) >= 0) { out.write(copyBuffer, 0, numRead); } } else { uncompressor.setNowrap(mode == Mode.UNCOMPRESS_NOWRAP); uncompressor.uncompress(in, out); } out.flush(); return out.getNumBytesWritten() - bytesWrittenBefore; } }
PartiallyUncompressingPipe implements Closeable { public long pipe(InputStream in, Mode mode) throws IOException { long bytesWrittenBefore = out.getNumBytesWritten(); if (mode == Mode.COPY) { int numRead = 0; while ((numRead = in.read(copyBuffer)) >= 0) { out.write(copyBuffer, 0, numRead); } } else { uncompressor.setNowrap(mode == Mode.UNCOMPRESS_NOWRAP); uncompressor.uncompress(in, out); } out.flush(); return out.getNumBytesWritten() - bytesWrittenBefore; } PartiallyUncompressingPipe(OutputStream out, int copyBufferSize); }
PartiallyUncompressingPipe implements Closeable { public long pipe(InputStream in, Mode mode) throws IOException { long bytesWrittenBefore = out.getNumBytesWritten(); if (mode == Mode.COPY) { int numRead = 0; while ((numRead = in.read(copyBuffer)) >= 0) { out.write(copyBuffer, 0, numRead); } } else { uncompressor.setNowrap(mode == Mode.UNCOMPRESS_NOWRAP); uncompressor.uncompress(in, out); } out.flush(); return out.getNumBytesWritten() - bytesWrittenBefore; } PartiallyUncompressingPipe(OutputStream out, int copyBufferSize); long pipe(InputStream in, Mode mode); long getNumBytesWritten(); @Override void close(); }
PartiallyUncompressingPipe implements Closeable { public long pipe(InputStream in, Mode mode) throws IOException { long bytesWrittenBefore = out.getNumBytesWritten(); if (mode == Mode.COPY) { int numRead = 0; while ((numRead = in.read(copyBuffer)) >= 0) { out.write(copyBuffer, 0, numRead); } } else { uncompressor.setNowrap(mode == Mode.UNCOMPRESS_NOWRAP); uncompressor.uncompress(in, out); } out.flush(); return out.getNumBytesWritten() - bytesWrittenBefore; } PartiallyUncompressingPipe(OutputStream out, int copyBufferSize); long pipe(InputStream in, Mode mode); long getNumBytesWritten(); @Override void close();  }