use of org.apache.commons.compress.archivers.zip.ZipFile in project atlas by alibaba.
the class ZipUtils method isFolderExist.
/**
* 判断在指定的zip目录下,指定的文件夹是否存在
*
* @param zipFile
* @param pathName
* @return
*/
public static boolean isFolderExist(File zipFile, String pathName) {
ZipFile file = null;
try {
file = new ZipFile(zipFile);
Enumeration<ZipArchiveEntry> en = file.getEntries();
while (en.hasMoreElements()) {
ZipArchiveEntry entry = en.nextElement();
String name = entry.getName();
if (name.startsWith(pathName)) {
return true;
}
}
return false;
} catch (IOException e) {
} finally {
if (null != file) {
try {
file.close();
} catch (IOException e) {
}
}
}
return false;
}
use of org.apache.commons.compress.archivers.zip.ZipFile in project atlas by alibaba.
the class ZipUtils method isZipFile.
/**
* <p>
* isZipFile.
* </p>
*
* @param zipFile a {@link File} object.
* @return a boolean.
*/
public static boolean isZipFile(File zipFile) {
try {
ZipFile zf = new ZipFile(zipFile);
boolean isZip = zf.getEntries().hasMoreElements();
zf.close();
return isZip;
} catch (IOException e) {
return false;
}
}
use of org.apache.commons.compress.archivers.zip.ZipFile in project atlas by alibaba.
the class ZipUtils method listZipEntries.
public static List<String> listZipEntries(File zipFile) {
List<String> list = new ArrayList<String>();
ZipFile zip;
try {
zip = new ZipFile(zipFile);
Enumeration<ZipArchiveEntry> en = zip.getEntries();
ZipArchiveEntry ze = null;
while (en.hasMoreElements()) {
ze = en.nextElement();
String name = ze.getName();
list.add(name);
}
if (null != zip)
ZipFile.closeQuietly(zip);
} catch (IOException e) {
}
return list;
}
use of org.apache.commons.compress.archivers.zip.ZipFile in project buck by facebook.
the class ZipRuleIntegrationTest method shouldZipSources.
@Test
public void shouldZipSources() throws IOException {
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "zip-rule", tmp);
workspace.setUp();
Path zip = workspace.buildAndReturnOutput("//example:ziptastic");
// Make sure we have the right files and attributes.
try (ZipFile zipFile = new ZipFile(zip.toFile())) {
ZipArchiveEntry cake = zipFile.getEntry("cake.txt");
assertThat(cake, Matchers.notNullValue());
assertFalse(cake.isUnixSymlink());
assertFalse(cake.isDirectory());
ZipArchiveEntry beans = zipFile.getEntry("beans/");
assertThat(beans, Matchers.notNullValue());
assertFalse(beans.isUnixSymlink());
assertTrue(beans.isDirectory());
ZipArchiveEntry cheesy = zipFile.getEntry("beans/cheesy.txt");
assertThat(cheesy, Matchers.notNullValue());
assertFalse(cheesy.isUnixSymlink());
assertFalse(cheesy.isDirectory());
}
}
use of org.apache.commons.compress.archivers.zip.ZipFile in project buck by facebook.
the class ZipStepTest method willRecurseIntoSubdirectories.
@Test
public void willRecurseIntoSubdirectories() throws IOException {
Path parent = tmp.newFolder("zipstep");
Path out = parent.resolve("output.zip");
Path toZip = tmp.newFolder("zipdir");
Files.createFile(toZip.resolve("file1.txt"));
Files.createDirectories(toZip.resolve("child"));
Files.createFile(toZip.resolve("child/file2.txt"));
ZipStep step = new ZipStep(filesystem, Paths.get("zipstep/output.zip"), ImmutableSet.of(), false, ZipCompressionLevel.DEFAULT_COMPRESSION_LEVEL, Paths.get("zipdir"));
assertEquals(0, step.execute(TestExecutionContext.newInstance()).getExitCode());
// Make sure we have the right attributes.
try (ZipFile zip = new ZipFile(out.toFile())) {
ZipArchiveEntry entry = zip.getEntry("child/");
assertNotEquals(entry.getUnixMode() & MoreFiles.S_IFDIR, 0);
}
try (Zip zip = new Zip(out, false)) {
assertEquals(ImmutableSet.of("file1.txt", "child/file2.txt"), zip.getFileNames());
}
}
Aggregations