本文整理了Java中java.util.zip.ZipEntry.isDirectory()
方法的一些代码示例,展示了ZipEntry.isDirectory()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipEntry.isDirectory()
方法的具体详情如下:
包路径:java.util.zip.ZipEntry
类名称:ZipEntry
方法名:isDirectory
[英]Determine whether or not this ZipEntry is a directory.
[中]确定这个ZipEntry是否是一个目录。
代码示例来源:origin: Activiti/Activiti
@Override
public Predicate<ZipEntry> filter(ZipEntry entry) {
return zipEntry -> !zipEntry.isDirectory() && zipEntry.getName().contains(PROCESSES);
}
代码示例来源:origin: stackoverflow.com
public static void unzip(File zipfile, File directory) throws IOException {
ZipFile zfile = new ZipFile(zipfile);
Enumeration<? extends ZipEntry> entries = zfile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
File file = new File(directory, entry.getName());
if (entry.isDirectory()) {
file.mkdirs();
} else {
file.getParentFile().mkdirs();
InputStream in = zfile.getInputStream(entry);
try {
copy(in, file);
} finally {
in.close();
}
}
}
}
代码示例来源:origin: stackoverflow.com
List<String> classNames = new ArrayList<String>();
ZipInputStream zip = new ZipInputStream(new FileInputStream("/path/to/jar/file.jar"));
for (ZipEntry entry = zip.getNextEntry(); entry != null; entry = zip.getNextEntry()) {
if (!entry.isDirectory() && entry.getName().endsWith(".class")) {
// This ZipEntry represents a class. Now, what class does it represent?
String className = entry.getName().replace('/', '.'); // including ".class"
classNames.add(className.substring(0, className.length() - ".class".length()));
}
}
代码示例来源:origin: apache/ignite
zip = new ZipFile(zipFile);
for (ZipEntry entry : asIterable(zip.entries())) {
if (entry.isDirectory()) {
new File(toDir, entry.getName()).mkdirs();
in = zip.getInputStream(entry);
File outFile = new File(toDir, entry.getName());
outFile.getParentFile().mkdirs();
out = new BufferedOutputStream(new FileOutputStream(outFile));
代码示例来源:origin: marytts/marytts
private static void unzipEntry(ZipFile zipfile, ZipEntry entry, File outputDir) throws IOException {
if (entry.isDirectory()) {
createDir(new File(outputDir, entry.getName()));
return;
}
File outputFile = new File(outputDir, entry.getName());
if (!outputFile.getParentFile().exists()) {
createDir(outputFile.getParentFile());
}
BufferedInputStream inputStream = new BufferedInputStream(zipfile.getInputStream(entry));
BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile));
try {
IOUtils.copy(inputStream, outputStream);
} finally {
outputStream.close();
inputStream.close();
}
}
代码示例来源:origin: Blankj/AndroidUtilCode
final ZipEntry entry,
final String name) throws IOException {
File file = new File(destDir, name);
files.add(file);
if (entry.isDirectory()) {
return createOrExistsDir(file);
} else {
try {
in = new BufferedInputStream(zip.getInputStream(entry));
out = new BufferedOutputStream(new FileOutputStream(file));
byte buffer[] = new byte[BUFFER_LEN];
int len;
代码示例来源:origin: ankidroid/Anki-Android
public static void unzipFiles(ZipFile zipFile, String targetDirectory, String[] zipEntries,
Map<String, String> zipEntryToFilenameMap) throws IOException {
File dir = new File(targetDirectory);
if (!dir.exists() && !dir.mkdirs()) {
throw new IOException("Failed to create target directory: " + targetDirectory);
}
if (zipEntryToFilenameMap == null) {
zipEntryToFilenameMap = new HashMap<>();
}
for (String requestedEntry : zipEntries) {
ZipEntry ze = zipFile.getEntry(requestedEntry);
if (ze != null) {
String name = ze.getName();
if (zipEntryToFilenameMap.containsKey(name)) {
name = zipEntryToFilenameMap.get(name);
}
File destFile = new File(dir, name);
if (!isInside(destFile, dir)) {
Timber.e("Refusing to decompress invalid path: %s", destFile.getCanonicalPath());
throw new IOException("File is outside extraction target directory.");
}
if (!ze.isDirectory()) {
Timber.i("uncompress %s", name);
try (InputStream zis = zipFile.getInputStream(ze)) {
writeToFile(zis, destFile.getAbsolutePath());
}
}
}
}
}
代码示例来源:origin: zeroturnaround/zt-zip
public void process(InputStream in, ZipEntry zipEntry) throws IOException {
String entryName = zipEntry.getName();
if (visitedNames.contains(entryName)) {
return;
}
visitedNames.add(entryName);
File file = new File(destination, entryName);
if (zipEntry.isDirectory()) {
FileUtils.forceMkdir(file);
return;
}
else {
FileUtils.forceMkdir(file.getParentFile());
file.createNewFile();
}
ZipEntryTransformer transformer = (ZipEntryTransformer) entryByPath.remove(entryName);
if (transformer == null) { // no transformer
FileUtils.copy(in, file);
}
else { // still transform entry
transformIntoFile(transformer, in, zipEntry, file);
}
}
代码示例来源:origin: geoserver/geoserver
public static void decompress(InputStream input, File destDir) throws IOException {
ZipInputStream zin = new ZipInputStream(input);
ZipEntry entry = null;
byte[] buffer = new byte[1024];
while ((entry = zin.getNextEntry()) != null) {
File f = getZipOutputFile(destDir, entry);
if (entry.isDirectory()) {
f.mkdirs();
continue;
}
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(f));
int n = -1;
while ((n = zin.read(buffer)) != -1) {
out.write(buffer, 0, n);
}
out.flush();
out.close();
}
}
代码示例来源:origin: pxb1988/dex2jar
byte[] data = Files.readAllBytes(new File(remainingArgs[0]).toPath());
try(com.googlecode.d2j.util.zip.ZipFile zipFile = new com.googlecode.d2j.util.zip.ZipFile(data)) {
for (com.googlecode.d2j.util.zip.ZipEntry e : zipFile.entries()) {
zos.putNextEntry(nEntry);
if (!nEntry.isDirectory()) {
try (InputStream is = zipFile.getInputStream(e)) {
while (true) {
代码示例来源:origin: spotbugs/spotbugs
private void scanForNextEntry() {
while (nextEntry == null) {
if (!zipEntryEnumerator.hasMoreElements()) {
return;
}
ZipEntry zipEntry = zipEntryEnumerator.nextElement();
if (!zipEntry.isDirectory()) {
addLastModifiedTime(zipEntry.getTime());
nextEntry = new ZipFileCodeBaseEntry(ZipFileCodeBase.this, zipEntry);
break;
}
}
}
};
代码示例来源:origin: org.apache.ant/ant
jarEntry = jarStream.getNextEntry();
String entryName = jarEntry.getName();
if (!jarEntry.isDirectory() && entryName.endsWith(".class")) {
jarEntry = jarStream.getNextEntry();
代码示例来源:origin: h2oai/h2o-2
return bs;
case ZIP: {
ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(bs));
ZipEntry ze = zis.getNextEntry(); // Get the *FIRST* entry
if( ze != null && !ze.isDirectory() ) {
is = zis;
break;
代码示例来源:origin: stackoverflow.com
JarFile jarFile = new JarFile(pathToJar);
Enumeration<JarEntry> e = jarFile.entries();
URL[] urls = { new URL("jar:file:" + pathToJar+"!/") };
URLClassLoader cl = URLClassLoader.newInstance(urls);
while (e.hasMoreElements()) {
JarEntry je = e.nextElement();
if(je.isDirectory() || !je.getName().endsWith(".class")){
continue;
}
// -6 because of .class
String className = je.getName().substring(0,je.getName().length()-6);
className = className.replace('/', '.');
Class c = cl.loadClass(className);
}
代码示例来源:origin: plantuml/plantuml
private InputStream getDataFromZip(InputStream is, String name) throws IOException {
final ZipInputStream zis = new ZipInputStream(is);
ZipEntry ze = zis.getNextEntry();
while (ze != null) {
final String fileName = ze.getName();
if (ze.isDirectory()) {
} else if (fileName.equals(name)) {
return zis;
}
ze = zis.getNextEntry();
}
zis.closeEntry();
zis.close();
return null;
}
代码示例来源:origin: marytts/marytts
private static void unzipEntry(ZipFile zipfile, ZipEntry entry, File outputDir) throws IOException {
if (entry.isDirectory()) {
createDir(new File(outputDir, entry.getName()));
return;
}
File outputFile = new File(outputDir, entry.getName());
if (!outputFile.getParentFile().exists()) {
createDir(outputFile.getParentFile());
}
BufferedInputStream inputStream = new BufferedInputStream(zipfile.getInputStream(entry));
BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile));
try {
IOUtils.copy(inputStream, outputStream);
} finally {
outputStream.close();
inputStream.close();
}
}
代码示例来源:origin: spotbugs/spotbugs
while (true) {
ZipEntry e = in.getNextEntry();
if (e == null) {
break;
if (!e.isDirectory()) {
String name = e.getName();
long size = e.getSize();
代码示例来源:origin: Atmosphere/atmosphere
private boolean accept(final ZipEntry entry) {
if (entry.isDirectory()) {
return false;
}
if (entryNameFilter == null) {
return true;
}
for (final String filter : entryNameFilter) {
if (entry.getName().startsWith(filter)) {
return true;
}
}
return false;
}
代码示例来源:origin: stackoverflow.com
java.util.jar.JarFile jar = new java.util.jar.JarFile(jarFile);
java.util.Enumeration enumEntries = jar.entries();
while (enumEntries.hasMoreElements()) {
java.util.jar.JarEntry file = (java.util.jar.JarEntry) enumEntries.nextElement();
java.io.File f = new java.io.File(destDir + java.io.File.separator + file.getName());
if (file.isDirectory()) { // if its a directory, create it
f.mkdir();
continue;
}
java.io.InputStream is = jar.getInputStream(file); // get the input stream
java.io.FileOutputStream fos = new java.io.FileOutputStream(f);
while (is.available() > 0) { // write contents of 'is' to 'fos'
fos.write(is.read());
}
fos.close();
is.close();
}
代码示例来源:origin: stackoverflow.com
import org.apache.commons.io.IOUtils;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public boolean unzip(InputStream inputStream, File outputFolder) throws IOException {
ZipInputStream zis = new ZipInputStream(inputStream);
ZipEntry entry;
boolean isEmpty = true;
while ((entry = zis.getNextEntry()) != null) {
isEmpty = false;
File newFile = new File(outputFolder, entry.getName());
if (newFile.getParentFile().mkdirs() && !entry.isDirectory()) {
FileOutputStream fos = new FileOutputStream(newFile);
IOUtils.copy(zis, fos);
IOUtils.closeQuietly(fos);
}
}
IOUtils.closeQuietly(zis);
return !isEmpty;
}
内容来源于网络,如有侵权,请联系作者删除!