use of java.util.zip.ZipEntry in project j2objc by google.
the class OldAndroidZipStreamTest method createUncompressedZip.
private static void createUncompressedZip(ByteArrayOutputStream bytesOut) throws IOException {
ZipOutputStream out = new ZipOutputStream(bytesOut);
try {
long[] crcs = { 0x205fbff3, 0x906fae57L, 0x2c235131 };
int i;
for (i = 0; i < 3; i++) {
byte[] input = makeSampleFile(i);
ZipEntry newEntry = new ZipEntry("file-" + i);
if (i != 1)
newEntry.setComment("this is file " + i);
newEntry.setMethod(ZipEntry.STORED);
newEntry.setSize(128 * 1024);
newEntry.setCrc(crcs[i]);
out.putNextEntry(newEntry);
out.write(input, 0, input.length);
out.closeEntry();
}
out.setComment("This is a lovely, but uncompressed, archive!");
} finally {
out.close();
}
}
use of java.util.zip.ZipEntry in project j2objc by google.
the class ZipInputStreamTest method unzip.
public static byte[] unzip(String name, byte[] bytes) throws IOException {
ZipInputStream in = new ZipInputStream(new ByteArrayInputStream(bytes));
ByteArrayOutputStream out = new ByteArrayOutputStream();
ZipEntry entry = in.getNextEntry();
assertEquals(name, entry.getName());
byte[] buffer = new byte[1024];
int count;
while ((count = in.read(buffer)) != -1) {
out.write(buffer, 0, count);
}
// There's only one entry in the Zip files we create.
assertNull(in.getNextEntry());
in.close();
return out.toByteArray();
}
use of java.util.zip.ZipEntry in project j2objc by google.
the class ZipInputStreamTest method testReadEmpty.
/**
* Reference implementation allows reading of empty zip using a {@link ZipInputStream}.
*/
public void testReadEmpty() throws IOException {
InputStream emptyZipIn = Support_Resources.getStream("java/util/zip/EmptyArchive.zip");
ZipInputStream in = new ZipInputStream(emptyZipIn);
try {
ZipEntry entry = in.getNextEntry();
assertNull("An empty zip has no entries", entry);
} finally {
in.close();
}
}
use of java.util.zip.ZipEntry in project j2objc by google.
the class ZipOutputStreamTest method testNullComment.
/** Regression test for null comment causing a NullPointerException during write. */
public void testNullComment() throws IOException {
ZipOutputStream out = new ZipOutputStream(new ByteArrayOutputStream());
out.setComment(null);
out.putNextEntry(new ZipEntry("name"));
out.write(new byte[1]);
out.closeEntry();
out.finish();
}
use of java.util.zip.ZipEntry in project j2objc by google.
the class ZipEntryTest method testMaxLengthName.
public void testMaxLengthName() throws Exception {
String maxLengthName = makeString(65535, "z");
File f = createTemporaryZipFile();
ZipOutputStream out = createZipOutputStream(f);
out.putNextEntry(new ZipEntry(maxLengthName));
out.closeEntry();
out.close();
// Read it back, and check that we see the entry.
ZipFile zipFile = new ZipFile(f);
assertNotNull(zipFile.getEntry(maxLengthName));
zipFile.close();
}
Aggregations