本文整理汇总了Java中org.apache.commons.compress.archivers.zip.ZipArchiveEntry.isDirectory方法的典型用法代码示例。如果您正苦于以下问题:Java ZipArchiveEntry.isDirectory方法的具体用法?Java ZipArchiveEntry.isDirectory怎么用?Java ZipArchiveEntry.isDirectory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.compress.archivers.zip.ZipArchiveEntry
的用法示例。
在下文中一共展示了ZipArchiveEntry.isDirectory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extractZip
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
private void extractZip(ZipFile zipFile) {
Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();
while (entries.hasMoreElements()) {
ZipArchiveEntry entry = entries.nextElement();
String fileName = entry.getName();
File outputFile = new File(config.getExtractionFolder(), fileName);
if (entry.isDirectory()) {
makeDirectory(outputFile);
} else {
createNewFile(outputFile);
try {
InputStream inputStream = zipFile.getInputStream(entry);
extractFile(inputStream, outputFile, fileName);
} catch (IOException e) {
throw new ExtractionException("Error extracting file '" + fileName + "' "
+ "from downloaded file: " + config.getDownloadTarget(), e);
}
}
}
}
示例2: TestBarInstaller
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
/**
* barファイル内エントリのファイルサイズ上限値を超えた場合に例外が発生すること.
*/
@Test
public void barファイル内エントリのファイルサイズ上限値を超えた場合に例外が発生すること() {
TestBarInstaller testBarInstaller = new TestBarInstaller();
URL fileUrl = ClassLoader.getSystemResource("requestData/barInstall/V1_1_2_bar_minimum.bar");
File file = new File(fileUrl.getPath());
try {
ZipFile zipFile = new ZipFile(file, "UTF-8");
Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();
long maxBarEntryFileSize = 0;
while (entries.hasMoreElements()) {
ZipArchiveEntry zae = entries.nextElement();
if (zae.isDirectory()) {
continue;
}
testBarInstaller.checkBarFileEntrySize(zae, zae.getName(), maxBarEntryFileSize);
}
fail("Unexpected exception");
} catch (PersoniumCoreException dce) {
String code = PersoniumCoreException.BarInstall.BAR_FILE_ENTRY_SIZE_TOO_LARGE.getCode();
assertEquals(code, dce.getCode());
} catch (Exception ex) {
fail("Unexpected exception");
}
}
示例3: getStroomZipNameSet
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
public StroomZipNameSet getStroomZipNameSet() throws IOException {
if (stroomZipNameSet == null) {
stroomZipNameSet = new StroomZipNameSet(false);
Enumeration<ZipArchiveEntry> entryE = getZipFile().getEntries();
while (entryE.hasMoreElements()) {
ZipArchiveEntry entry = entryE.nextElement();
// Skip Dir's
if (!entry.isDirectory()) {
String fileName = entry.getName();
stroomZipNameSet.add(fileName);
}
long entrySize = entry.getSize();
if (entrySize == -1 || totalSize == -1) {
// Can nolonger sum
} else {
totalSize += entrySize;
}
}
}
return stroomZipNameSet;
}
示例4: unZip
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
public static void unZip(Path file, Path target) throws IOException {
try (final ZipFile zipFile = new ZipFile(file.toFile())) {
final Enumeration<ZipArchiveEntry> files = zipFile.getEntriesInPhysicalOrder();
while (files.hasMoreElements()) {
final ZipArchiveEntry entry = files.nextElement();
final Path entryFile = target.resolve(REMOVE_LEADING_GO_PATH_PATTERN.matcher(entry.getName()).replaceFirst("")).toAbsolutePath();
if (entry.isDirectory()) {
createDirectoriesIfRequired(entryFile);
} else {
ensureParentOf(entryFile);
try (final InputStream is = zipFile.getInputStream(entry)) {
try (final OutputStream os = newOutputStream(entryFile)) {
copy(is, os);
}
}
}
}
}
}
示例5: unZipToFolder
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
/**
* 把一个ZIP文件解压到一个指定的目录中
* @param zipfilename ZIP文件抽象地址
* @param outputdir 目录绝对地址
*/
public static void unZipToFolder(String zipfilename, String outputdir) throws IOException {
File zipfile = new File(zipfilename);
if (zipfile.exists()) {
outputdir = outputdir + File.separator;
FileUtils.forceMkdir(new File(outputdir));
ZipFile zf = new ZipFile(zipfile, "UTF-8");
Enumeration zipArchiveEntrys = zf.getEntries();
while (zipArchiveEntrys.hasMoreElements()) {
ZipArchiveEntry zipArchiveEntry = (ZipArchiveEntry) zipArchiveEntrys.nextElement();
if (zipArchiveEntry.isDirectory()) {
FileUtils.forceMkdir(new File(outputdir + zipArchiveEntry.getName() + File.separator));
} else {
IOUtils.copy(zf.getInputStream(zipArchiveEntry), FileUtils.openOutputStream(new File(outputdir + zipArchiveEntry.getName())));
}
}
} else {
throw new IOException("指定的解压文件不存在:\t" + zipfilename);
}
}
示例6: getStroomZipNameSet
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
public StroomZipNameSet getStroomZipNameSet() throws IOException {
if (stroomZipNameSet == null) {
stroomZipNameSet = new StroomZipNameSet(false);
Enumeration<ZipArchiveEntry> entryE = getZipFile().getEntries();
while (entryE.hasMoreElements()) {
ZipArchiveEntry entry = entryE.nextElement();
// Skip Dir's
if (!entry.isDirectory()) {
String fileName = entry.getName();
stroomZipNameSet.add(fileName);
}
long entrySize = entry.getSize();
if (entrySize > 0) {
totalSize += entrySize;
}
}
}
return stroomZipNameSet;
}
示例7: extract
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
private static void extract(ZipArchiveEntry zipArchiveEntry, ZipFile zipFile, File outputDir) throws IOException {
File extractedFile = new File(outputDir, zipArchiveEntry.getName());
FileUtils.forceMkdir(extractedFile.getParentFile());
if (zipArchiveEntry.isUnixSymlink()) {
if (PosixUtil.isPosixFileStore(outputDir)) {
logger.debug("Extracting [l] "+zipArchiveEntry.getName());
String symlinkTarget = zipFile.getUnixSymlink(zipArchiveEntry);
Files.createSymbolicLink(extractedFile.toPath(), new File(symlinkTarget).toPath());
} else {
logger.debug("Skipping ! [l] "+zipArchiveEntry.getName());
}
} else if (zipArchiveEntry.isDirectory()) {
logger.debug("Extracting [d] "+zipArchiveEntry.getName());
FileUtils.forceMkdir(extractedFile);
} else {
logger.debug("Extracting [f] "+zipArchiveEntry.getName());
try (
InputStream in = zipFile.getInputStream(zipArchiveEntry);
OutputStream out = new FileOutputStream(extractedFile)
) {
IOUtils.copy(in, out);
}
}
updatePermissions(extractedFile, zipArchiveEntry.getUnixMode());
}
示例8: getZipArchiveEntryNames
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
private static List<String> getZipArchiveEntryNames(File sourceZip) throws IOException {
List<String> content = new ArrayList<>();
try (ZipFile zipFile = new ZipFile(sourceZip);) {
List<ZipArchiveEntry> zipEntries = Collections.list(zipFile.getEntries());
for (ZipArchiveEntry zipEntry : zipEntries) {
if (zipEntry.isUnixSymlink()) {
content.add("[l]"+zipEntry.getName());
} else if (zipEntry.isDirectory()) {
content.add("[d]"+zipEntry.getName());
} else {
content.add("[f]"+zipEntry.getName());
}
}
}
Collections.sort(content);
return content;
}
示例9: extractZipFile
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
private static void extractZipFile(final File destination, final ZipFile zipFile) throws IOException {
final Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();
while (entries.hasMoreElements()) {
final ZipArchiveEntry entry = entries.nextElement();
final File entryDestination = new File(destination, entry.getName());
if (entry.isDirectory()) {
entryDestination.mkdirs();
} else {
entryDestination.getParentFile().mkdirs();
final InputStream in = zipFile.getInputStream(entry);
try (final OutputStream out = new FileOutputStream(entryDestination)) {
IOUtils.copy(in, out);
IOUtils.closeQuietly(in);
}
}
}
}
示例10: detectKmz
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
private static MediaType detectKmz(ZipFile zip) {
boolean kmlFound = false;
Enumeration<ZipArchiveEntry> entries = zip.getEntries();
while (entries.hasMoreElements()) {
ZipArchiveEntry entry = entries.nextElement();
String name = entry.getName();
if (!entry.isDirectory()
&& name.indexOf('/') == -1 && name.indexOf('\\') == -1) {
if (name.endsWith(".kml") && !kmlFound) {
kmlFound = true;
} else {
return null;
}
}
}
if (kmlFound) {
return MediaType.application("vnd.google-earth.kmz");
} else {
return null;
}
}
示例11: extractEntireZip
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
@SuppressWarnings("ResultOfMethodCallIgnored")
public static void extractEntireZip(@NotNull final File zip, @NotNull final File restoreDir) throws IOException {
try (ZipFile zipFile = new ZipFile(zip)) {
final Enumeration<ZipArchiveEntry> zipEntries = zipFile.getEntries();
while (zipEntries.hasMoreElements()) {
final ZipArchiveEntry zipEntry = zipEntries.nextElement();
final File entryFile = new File(restoreDir, zipEntry.getName());
if (zipEntry.isDirectory()) {
entryFile.mkdirs();
} else {
entryFile.getParentFile().mkdirs();
try (FileOutputStream target = new FileOutputStream(entryFile)) {
try (InputStream in = zipFile.getInputStream(zipEntry)) {
IOUtil.copyStreams(in, target, IOUtil.BUFFER_ALLOCATOR);
}
}
}
}
}
}
示例12: unzip
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
private void unzip(File file, String dest) throws IOException {
try (ZipFile zip = new ZipFile(file)) {
Enumeration<? extends ZipArchiveEntry> entries = zip.getEntries();
while (entries.hasMoreElements()) {
ZipArchiveEntry entry = entries.nextElement();
File entryDestination = new File(dest, entry.getName());
if (entry.isDirectory()) {
entryDestination.mkdirs();
} else {
if (!entryDestination.getParentFile().exists()) {
entryDestination.getParentFile().mkdirs();
}
try (InputStream in = zip.getInputStream(entry);
OutputStream out = new FileOutputStream(entryDestination)) {
IOUtils.copy(in, out);
}
}
}
}
}
示例13: unpackEntry
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
private void unpackEntry(final File destFile, final ZipFile zipFile, final ZipArchiveEntry entry)
throws IOException, ZipException {
if (entry.isDirectory()) {
touchedFiles.add(destFile);
destFile.mkdirs();
} else if (!isSameFile(destFile, entry.getSize(),
entry.getLastModifiedDate().getTime())) {
File parentFolder = destFile.getParentFile();
parentFolder.mkdirs();
InputStream inputStream = zipFile.getInputStream(entry);
overCopyFile(Channels.newChannel(inputStream), entry.getSize(),
entry.getLastModifiedDate().getTime(), destFile);
FileManager.setPermissionsOnFile(destFile, entry);
} else {
touchedFiles.add(destFile);
}
}
示例14: analyseRlc
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
/**
* This method takes a potential RLC file and unpacks it as a ZIP file. Then
* filters through the entries in the ZIP file to find the XML file for
* processing. XML is then parsed through XStream and stored in an engine
* for data collection.
*
* @param file
* - file for processing
* @throws FileNotFoundException
* @throws IOException
*/
private void analyseRlc(final File file) throws FileNotFoundException, IOException, RuntimeException {
final InputStream inputStream = new BufferedInputStream(new FileInputStream(file));
final ZipArchiveInputStream zipInputStream = new ZipArchiveInputStream(inputStream);
ZipArchiveEntry entry;
try {
while ((entry = zipInputStream.getNextZipEntry()) != null) {
// Find the XML configuration file and ignore the rest
if (!entry.isDirectory()) {
final String entryName = entry.getName().trim().toLowerCase();
final int directoryIndex = entryName.indexOf('/');
if (entryName.length() > 4 && entryName.endsWith(".xml") && directoryIndex <= 0) {
if (!zipInputStream.canReadEntryData(entry)) {
throw new RuntimeException("RLC file could not be processed.");
}
logger.info("[PROCESSING] : " + entryName);
final Engine engine = parser.parse(zipInputStream);
if (engine == null) {
// Null returned do not add to engine list
logger.error("[ERROR] : Could not process " + entryName);
} else {
this.fileCounter++; // increment file count.
// file count used as a way to name files and distinguish RLC's with same names.
// Name of a file: FileCoutner + ":" + <FileName>. n is the file count.
engine.setFileName(this.fileCounter + ":" + file.getName());
this.engineList.add(engine);
this.dataCollector.collectData(engine);
}
}
}
}
} finally {
zipInputStream.close();
}
}
示例15: unzip
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
public static void unzip(File zipFile, File destination)
throws IOException {
ZipFile zip = new ZipFile(zipFile);
try {
Enumeration<ZipArchiveEntry> e = zip.getEntries();
while (e.hasMoreElements()) {
ZipArchiveEntry entry = e.nextElement();
File file = new File(destination, entry.getName());
if (entry.isDirectory()) {
file.mkdirs();
} else {
InputStream is = zip.getInputStream(entry);
File parent = file.getParentFile();
if (parent != null && parent.exists() == false) {
parent.mkdirs();
}
FileOutputStream os = new FileOutputStream(file);
try {
IOUtils.copy(is, os);
} finally {
os.close();
is.close();
}
file.setLastModified(entry.getTime());
int mode = entry.getUnixMode();
if ((mode & EXEC_MASK) != 0) {
if (!file.setExecutable(true)) {
}
}
}
}
} finally {
ZipFile.closeQuietly(zip);
}
}