use of java.util.zip.ZipFile 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();
}
use of java.util.zip.ZipFile in project j2objc by google.
the class ZipEntryTest method testCommentAndExtraInSameOrder.
public void testCommentAndExtraInSameOrder() throws Exception {
String comment = makeString(17, "z");
byte[] extra = makeString(11, "a").getBytes();
File f = createTemporaryZipFile();
ZipOutputStream out = createZipOutputStream(f);
// Regular (non zip64) format.
ZipEntry ze = new ZipEntry("x");
ze.setSize(0);
ze.setExtra(extra);
ze.setComment(comment);
out.putNextEntry(ze);
out.closeEntry();
// An entry without a length is assumed to be zip64.
ze = new ZipEntry("y");
ze.setExtra(extra);
ze.setComment(comment);
out.putNextEntry(ze);
out.closeEntry();
out.close();
// Read it back and make sure comments and extra are in the right order
ZipFile zipFile = new ZipFile(f);
try {
assertEquals(comment, zipFile.getEntry("x").getComment());
assertTrue(Arrays.equals(extra, zipFile.getEntry("x").getExtra()));
assertEquals(comment, zipFile.getEntry("y").getComment());
assertTrue(Arrays.equals(extra, zipFile.getEntry("y").getExtra()));
} finally {
zipFile.close();
}
}
use of java.util.zip.ZipFile in project j2objc by google.
the class ZipEntryTest method testMaxLengthExtra.
public void testMaxLengthExtra() throws Exception {
byte[] maxLengthExtra = new byte[65535];
File f = createTemporaryZipFile();
ZipOutputStream out = createZipOutputStream(f);
ZipEntry ze = new ZipEntry("x");
ze.setSize(0);
ze.setExtra(maxLengthExtra);
out.putNextEntry(ze);
out.closeEntry();
out.close();
// Read it back, and check that we see the entry.
ZipFile zipFile = new ZipFile(f);
assertEquals(maxLengthExtra.length, zipFile.getEntry("x").getExtra().length);
zipFile.close();
}
use of java.util.zip.ZipFile in project CoreNLP by stanfordnlp.
the class JarFileChooser method getFiles.
public List<String> getFiles(File jarFile) throws ZipException, IOException {
//System.out.println("Looking at " + jarFile);
List<String> files = new ArrayList<>();
ZipFile zin = new ZipFile(jarFile);
Enumeration<? extends ZipEntry> entries = zin.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
String name = entry.getName();
if (name.matches(pattern)) {
files.add(name);
}
}
Collections.sort(files);
return files;
}
use of java.util.zip.ZipFile in project spring-loaded by spring-projects.
the class SubLoader method findResource.
@Override
public URL findResource(String name) {
try {
// Look in the folders we care about
for (int i = 0; i < folders.length; i++) {
File file = new File(folders[i], name);
// System.out.println(file.exists());
if (file.exists()) {
return file.toURI().toURL();
}
}
for (int i = 0; i < jars.length; i++) {
ZipFile zipfile = new ZipFile(jars[i]);
ZipEntry zipentry = zipfile.getEntry(name);
if (zipentry != null) {
return new URL("jar:file:" + new File(jars[i]).getCanonicalPath() + "!/" + name);
}
zipfile.close();
}
return null;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
Aggregations