use of java.util.zip.ZipInputStream in project robovm by robovm.
the class ZipFileTest method testInflatingStreamsRequiringZipRefill.
public void testInflatingStreamsRequiringZipRefill() throws IOException {
int originalSize = 1024 * 1024;
byte[] readBuffer = new byte[8192];
ZipInputStream in = new ZipInputStream(new FileInputStream(createZipFile(1, originalSize)));
while (in.getNextEntry() != null) {
while (in.read(readBuffer, 0, readBuffer.length) != -1) {
}
}
in.close();
}
use of java.util.zip.ZipInputStream in project robovm by robovm.
the class OldZipInputStreamTest method setUp.
@Override
protected void setUp() throws IOException {
InputStream is = Support_Resources.getStream("hyts_ZipFile.zip");
if (is == null) {
System.out.println("file hyts_ZipFile.zip can not be found");
}
zis = new ZipInputStream(is);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ZipOutputStream zos = new ZipOutputStream(bos);
ZipEntry entry = new ZipEntry("myFile");
zos.putNextEntry(entry);
zos.write(dataBytes);
zos.closeEntry();
zos.close();
}
use of java.util.zip.ZipInputStream in project robovm by robovm.
the class OldZipInputStreamTest method test_closeEntry.
public void test_closeEntry() throws Exception {
zis.getNextEntry();
zis.closeEntry();
zis.getNextEntry();
zis.close();
try {
zis.closeEntry();
fail("IOException expected");
} catch (IOException ee) {
// expected
}
File resources = Support_Resources.createTempFolder();
Support_Resources.copyFile(resources, null, "Broken_manifest.jar");
FileInputStream fis = new FileInputStream(new File(resources, "Broken_manifest.jar"));
ZipInputStream zis1 = new ZipInputStream(fis);
try {
for (int i = 0; i < 6; i++) {
zis1.getNextEntry();
zis1.closeEntry();
}
fail("ZipException expected");
} catch (ZipException ee) {
// expected
}
}
use of java.util.zip.ZipInputStream in project bazel by bazelbuild.
the class SignedJarBuilder method writeZip.
/**
* Copies the content of a Jar/Zip archive into the receiver archive.
* <p/>An optional {@link IZipEntryFilter} allows to selectively choose which files
* to copy over.
* @param input the {@link InputStream} for the Jar/Zip to copy.
* @param filter the filter or <code>null</code>
* @throws IOException
* @throws ZipAbortException if the {@link IZipEntryFilter} filter indicated that the write
* must be aborted.
*/
public void writeZip(InputStream input, IZipEntryFilter filter) throws IOException, ZipAbortException {
ZipInputStream zis = new ZipInputStream(input);
try {
// loop on the entries of the intermediary package and put them in the final package.
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
String name = entry.getName();
// do not take directories
if (entry.isDirectory()) {
continue;
}
// if we have a filter, we check the entry against it
if (filter != null && !filter.checkEntry(name)) {
continue;
}
JarEntry newEntry;
// Preserve the STORED method of the input entry.
if (entry.getMethod() == JarEntry.STORED) {
newEntry = new JarEntry(entry);
} else {
// Create a new entry so that the compressed len is recomputed.
newEntry = new JarEntry(name);
}
writeEntry(zis, newEntry);
zis.closeEntry();
}
} finally {
zis.close();
}
}
use of java.util.zip.ZipInputStream in project bazel by bazelbuild.
the class ZipCombinerTest method testAddFileAndDuplicateZipEntry.
@Test
public void testAddFileAndDuplicateZipEntry() throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
try (ZipCombiner zipCombiner = new ZipCombiner(out)) {
zipCombiner.addFile("hello.txt", ZipCombiner.DOS_EPOCH, asStream("Hello World!"));
zipCombiner.addZip(sampleZip());
}
ZipInputStream zipInput = new ZipInputStream(new ByteArrayInputStream(out.toByteArray()));
assertEntry(zipInput, "hello.txt", "Hello World!");
assertNull(zipInput.getNextEntry());
}
Aggregations