use of java.io.ByteArrayOutputStream in project bazel by bazelbuild.
the class ZipCombinerTest method testCopyTwoUncompressedEntries.
@Test
public void testCopyTwoUncompressedEntries() throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
try (ZipCombiner zipCombiner = new ZipCombiner(out)) {
zipCombiner.addZip(sampleZipWithTwoUncompressedEntries());
}
ZipInputStream zipInput = new ZipInputStream(new ByteArrayInputStream(out.toByteArray()));
assertEntry(zipInput, "hello.txt", "Hello World!");
assertEntry(zipInput, "hello2.txt", "Hello World 2!");
assertNull(zipInput.getNextEntry());
}
use of java.io.ByteArrayOutputStream in project bazel by bazelbuild.
the class ZipCombinerTest method testCombine.
@Test
public void testCombine() throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
try (ZipCombiner zipCombiner = new ZipCombiner(out)) {
zipCombiner.addZip(sampleZip());
zipCombiner.addZip(sampleZip2());
}
ZipInputStream zipInput = new ZipInputStream(new ByteArrayInputStream(out.toByteArray()));
assertEntry(zipInput, "hello.txt", "Hello World!");
assertEntry(zipInput, "hello2.txt", "Hello World 2!");
assertNull(zipInput.getNextEntry());
}
use of java.io.ByteArrayOutputStream in project bazel by bazelbuild.
the class ZipCombinerTest method testCopyDateHandling.
@Test
public void testCopyDateHandling() throws IOException {
final Date date = new GregorianCalendar(2009, 8, 2, 0, 0, 0).getTime();
ZipEntryFilter mockFilter = new ZipEntryFilter() {
@Override
public void accept(String filename, StrategyCallback callback) throws IOException {
assertEquals("hello.txt", filename);
callback.copy(date);
}
};
ByteArrayOutputStream out = new ByteArrayOutputStream();
try (ZipCombiner zipCombiner = new ZipCombiner(mockFilter, out)) {
zipCombiner.addZip(sampleZip());
}
ZipInputStream zipInput = new ZipInputStream(new ByteArrayInputStream(out.toByteArray()));
assertEntry(zipInput, "hello.txt", date, "Hello World!");
assertNull(zipInput.getNextEntry());
}
use of java.io.ByteArrayOutputStream in project bazel by bazelbuild.
the class ZipCombinerTest method testZipCombinerAgainstJavaUtil.
@Test
public void testZipCombinerAgainstJavaUtil() throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
try (JarOutputStream jarOut = new JarOutputStream(out)) {
ZipEntry entry;
entry = new ZipEntry("META-INF/");
entry.setTime(ZipCombiner.DOS_EPOCH.getTime());
entry.setMethod(JarOutputStream.STORED);
entry.setSize(0);
entry.setCompressedSize(0);
entry.setCrc(0);
jarOut.putNextEntry(entry);
entry = new ZipEntry("META-INF/MANIFEST.MF");
entry.setTime(ZipCombiner.DOS_EPOCH.getTime());
entry.setMethod(JarOutputStream.DEFLATED);
jarOut.putNextEntry(entry);
jarOut.write(new byte[] { 1, 2, 3, 4 });
}
File javaFile = writeInputStreamToFile(new ByteArrayInputStream(out.toByteArray()));
out.reset();
try (ZipCombiner zipcombiner = new ZipCombiner(out)) {
zipcombiner.addDirectory("META-INF/", ZipCombiner.DOS_EPOCH, new ExtraData[] { new ExtraData((short) 0xCAFE, new byte[0]) });
zipcombiner.addFile("META-INF/MANIFEST.MF", ZipCombiner.DOS_EPOCH, new ByteArrayInputStream(new byte[] { 1, 2, 3, 4 }));
}
File zipCombinerFile = writeInputStreamToFile(new ByteArrayInputStream(out.toByteArray()));
byte[] zipCombinerRaw = out.toByteArray();
new ZipTester(zipCombinerRaw).validate();
assertZipFilesEquivalent(new ZipReader(zipCombinerFile), new ZipReader(javaFile));
}
use of java.io.ByteArrayOutputStream in project bazel by bazelbuild.
the class ZipCombinerTest method testCopyCallsFilter.
@Test
public void testCopyCallsFilter() throws IOException {
MockZipEntryFilter mockFilter = new MockZipEntryFilter();
ByteArrayOutputStream out = new ByteArrayOutputStream();
try (ZipCombiner zipCombiner = new ZipCombiner(mockFilter, out)) {
zipCombiner.addZip(sampleZip());
}
assertEquals(Arrays.asList("hello.txt"), mockFilter.calls);
}
Aggregations