use of java.io.ByteArrayOutputStream in project bazel by bazelbuild.
the class ZipCombinerTest method testUncompressedForceDeflate.
@Test
public void testUncompressedForceDeflate() throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
try (ZipCombiner zipCombiner = new ZipCombiner(OutputMode.FORCE_DEFLATE, out)) {
zipCombiner.addZip(sampleZipWithOneUncompressedEntry());
}
FakeZipFile expectedResult = new FakeZipFile().addEntry("hello.txt", "Hello World!", true);
expectedResult.assertSame(out.toByteArray());
}
use of java.io.ByteArrayOutputStream in project bazel by bazelbuild.
the class ZipCombinerTest method testRenameAndSkip.
// This tests verifies that if an entry has been skipped, then
// further entries of the same name are skipped (filter not invoked),
// and entries renamed to the same name are skipped (after calling filter).
@Test
public void testRenameAndSkip() throws IOException {
MockZipEntryFilter mockFilter = new MockZipEntryFilter();
mockFilter.behavior.put("hello.txt", COPY_PLACEHOLDER);
mockFilter.behavior.put("hello2.txt", SKIP_PLACEHOLDER);
mockFilter.renameMap.putAll("hello.txt", Arrays.asList("hello1.txt", "hello2.txt", "hello3.txt"));
ByteArrayOutputStream out = new ByteArrayOutputStream();
try (ZipCombiner zipCombiner = new ZipCombiner(mockFilter, out)) {
zipCombiner.addZip(sampleZipWithTwoEntries());
zipCombiner.addZip(sampleZipWithTwoEntries());
zipCombiner.addZip(sampleZipWithTwoEntries());
}
assertThat(mockFilter.calls).containsExactly("hello.txt", "hello2.txt", "hello.txt", "hello.txt").inOrder();
ZipInputStream zipInput = new ZipInputStream(new ByteArrayInputStream(out.toByteArray()));
assertEntry(zipInput, "hello1.txt", "Hello World!");
assertEntry(zipInput, "hello3.txt", "Hello World!");
assertNull(zipInput.getNextEntry());
}
use of java.io.ByteArrayOutputStream in project bazel by bazelbuild.
the class ZipCombinerTest method testRenameWithUncompressedFiles.
// This test verifies that renaming works when input and output
// disagree on compression method. This is the simple case, where
// content is read and rewritten, and no header repair is needed.
@Test
public void testRenameWithUncompressedFiles() throws IOException {
MockZipEntryFilter mockFilter = new MockZipEntryFilter();
mockFilter.behavior.put("hello.txt", COPY_PLACEHOLDER);
mockFilter.behavior.put("hello2.txt", COPY_PLACEHOLDER);
mockFilter.renameMap.putAll("hello.txt", Arrays.asList("hello1.txt", "hello2.txt", "hello3.txt"));
mockFilter.renameMap.put("hello2.txt", "hello2.txt");
ByteArrayOutputStream out = new ByteArrayOutputStream();
try (ZipCombiner zipCombiner = new ZipCombiner(mockFilter, out)) {
zipCombiner.addZip(sampleZipWithTwoUncompressedEntries());
zipCombiner.addZip(sampleZipWithTwoUncompressedEntries());
zipCombiner.addZip(sampleZipWithTwoUncompressedEntries());
}
assertThat(mockFilter.calls).containsExactly("hello.txt", "hello2.txt", "hello.txt", "hello2.txt", "hello.txt", "hello2.txt").inOrder();
ZipInputStream zipInput = new ZipInputStream(new ByteArrayInputStream(out.toByteArray()));
assertEntry(zipInput, "hello1.txt", "Hello World!");
assertEntry(zipInput, "hello2.txt", "Hello World 2!");
assertEntry(zipInput, "hello3.txt", "Hello World!");
assertNull(zipInput.getNextEntry());
}
use of java.io.ByteArrayOutputStream in project bazel by bazelbuild.
the class ZipCombinerTest method testMergeStrategyWithUncompressedFilesAndSlowCopy.
@Test
public void testMergeStrategyWithUncompressedFilesAndSlowCopy() throws IOException {
MockZipEntryFilter mockFilter = new MockZipEntryFilter();
mockFilter.behavior.put("hello.txt", new SlowConcatenateStrategy());
mockFilter.behavior.put("hello2.txt", SKIP_PLACEHOLDER);
ByteArrayOutputStream out = new ByteArrayOutputStream();
try (ZipCombiner zipCombiner = new ZipCombiner(mockFilter, out)) {
zipCombiner.addZip(sampleZipWithTwoUncompressedEntries());
zipCombiner.addZip(sampleZipWithTwoUncompressedEntries());
}
assertEquals(Arrays.asList("hello.txt", "hello2.txt"), mockFilter.calls);
ZipInputStream zipInput = new ZipInputStream(new ByteArrayInputStream(out.toByteArray()));
assertEntry(zipInput, "hello.txt", "Hello World!Hello World!");
assertNull(zipInput.getNextEntry());
}
use of java.io.ByteArrayOutputStream in project bazel by bazelbuild.
the class ZipCombinerTest method testMergeStrategyWithSlowCopy.
@Test
public void testMergeStrategyWithSlowCopy() throws IOException {
MockZipEntryFilter mockFilter = new MockZipEntryFilter();
mockFilter.behavior.put("hello.txt", new SlowConcatenateStrategy());
ByteArrayOutputStream out = new ByteArrayOutputStream();
try (ZipCombiner zipCombiner = new ZipCombiner(mockFilter, out)) {
zipCombiner.addZip(sampleZip());
zipCombiner.addZip(sampleZipWithTwoEntries());
}
assertEquals(Arrays.asList("hello.txt", "hello2.txt"), mockFilter.calls);
ZipInputStream zipInput = new ZipInputStream(new ByteArrayInputStream(out.toByteArray()));
assertEntry(zipInput, "hello2.txt", "Hello World 2!");
assertEntry(zipInput, "hello.txt", "Hello World!Hello World!");
assertNull(zipInput.getNextEntry());
}
Aggregations