本文整理匯總了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);
}
}