use of java.util.zip.ZipOutputStream in project robovm by robovm.
the class ZipFileTest method test_getComment_unset.
public void test_getComment_unset() throws Exception {
File file = createTemporaryZipFile();
ZipOutputStream out = createZipOutputStream(file);
ZipEntry ze = new ZipEntry("test entry");
ze.setComment("per-entry comment");
out.putNextEntry(ze);
out.close();
ZipFile zipFile = new ZipFile(file);
assertEquals(null, zipFile.getComment());
}
use of java.util.zip.ZipOutputStream in project robovm by robovm.
the class ZipFileTest method testDuplicateEntries.
/**
* Make sure we don't fail silently for duplicate entries.
* b/8219321
*/
public void testDuplicateEntries() throws Exception {
String name1 = "test_file_name1";
String name2 = "test_file_name2";
// Create the good zip file.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ZipOutputStream out = new ZipOutputStream(baos);
out.putNextEntry(new ZipEntry(name2));
out.closeEntry();
out.putNextEntry(new ZipEntry(name1));
out.closeEntry();
out.close();
// Rewrite one of the filenames.
byte[] buffer = baos.toByteArray();
replaceBytes(buffer, name2.getBytes(), name1.getBytes());
// Write the result to a file.
File badZip = createTemporaryZipFile();
writeBytes(badZip, buffer);
// Check that we refuse to load the modified file.
try {
ZipFile bad = new ZipFile(badZip);
fail();
} catch (ZipException expected) {
}
}
use of java.util.zip.ZipOutputStream in project robovm by robovm.
the class ZipFileTest method testCrc.
public void testCrc() throws IOException {
ZipEntry ze = new ZipEntry("test");
ze.setMethod(ZipEntry.STORED);
ze.setSize(4);
// setCrc takes a long, not an int, so -1 isn't a valid CRC32 (because it's 64 bits).
try {
ze.setCrc(-1);
} catch (IllegalArgumentException expected) {
}
// You can set the CRC32 to 0xffffffff if you're slightly more careful though...
ze.setCrc(0xffffffffL);
assertEquals(0xffffffffL, ze.getCrc());
// And it actually works, even though we use -1L to mean "no CRC set"...
ZipOutputStream out = createZipOutputStream(createTemporaryZipFile());
out.putNextEntry(ze);
out.write(-1);
out.write(-1);
out.write(-1);
out.write(-1);
out.closeEntry();
out.close();
}
use of java.util.zip.ZipOutputStream 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.ZipOutputStream in project bazel by bazelbuild.
the class ZipFactory method toByteArray.
public byte[] toByteArray() {
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ZipOutputStream zipper = new ZipOutputStream(out);
for (Entry entry : entries) {
ZipEntry zipEntry = new ZipEntry(entry.name);
if (entry.compressed) {
zipEntry.setMethod(ZipEntry.DEFLATED);
} else {
zipEntry.setMethod(ZipEntry.STORED);
zipEntry.setSize(entry.content.length);
zipEntry.setCrc(calculateCrc32(entry.content));
}
zipEntry.setTime(ZipCombiner.DOS_EPOCH.getTime());
zipper.putNextEntry(zipEntry);
zipper.write(entry.content);
zipper.closeEntry();
}
zipper.close();
return out.toByteArray();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Aggregations