use of java.util.zip.ZipInputStream in project bazel by bazelbuild.
the class ZipCombinerTest method testMergeDateHandling.
@Test
public void testMergeDateHandling() throws IOException {
MockZipEntryFilter mockFilter = new MockZipEntryFilter();
mockFilter.behavior.put("hello.txt", new ConcatenateStrategy());
mockFilter.date = new GregorianCalendar(2009, 8, 2, 0, 0, 0).getTime();
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", ZipCombiner.DOS_EPOCH, "Hello World 2!");
assertEntry(zipInput, "hello.txt", mockFilter.date, "Hello World!\nHello World!");
assertNull(zipInput.getNextEntry());
}
use of java.util.zip.ZipInputStream in project bazel by bazelbuild.
the class ZipCombinerTest method testRenameAndCopy.
// This tests verifies that if an entry has been copied, 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 testRenameAndCopy() 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"));
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, "hello2.txt", "Hello World 2!");
assertEntry(zipInput, "hello3.txt", "Hello World!");
assertNull(zipInput.getNextEntry());
}
use of java.util.zip.ZipInputStream 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.util.zip.ZipInputStream 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.util.zip.ZipInputStream 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());
}
Aggregations