本文整理匯總了Java中org.apache.commons.compress.archivers.zip.ZipArchiveEntry類的典型用法代碼示例。如果您正苦於以下問題:Java ZipArchiveEntry類的具體用法?Java ZipArchiveEntry怎麽用?Java ZipArchiveEntry使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ZipArchiveEntry類屬於org.apache.commons.compress.archivers.zip包,在下文中一共展示了ZipArchiveEntry類的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: makeOnlyUnZip
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入依賴的package包/類
public static void makeOnlyUnZip() throws ArchiveException, IOException{
final InputStream is = new FileInputStream("D:/中文名字.zip");
ArchiveInputStream in = new ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.ZIP, is);
ZipArchiveEntry entry = entry = (ZipArchiveEntry) in.getNextEntry();
String dir = "D:/cnname";
File filedir = new File(dir);
if(!filedir.exists()){
filedir.mkdir();
}
// OutputStream out = new FileOutputStream(new File(dir, entry.getName()));
OutputStream out = new FileOutputStream(new File(filedir, entry.getName()));
IOUtils.copy(in, out);
out.close();
in.close();
}
示例3: getDownloadEntries
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入依賴的package包/類
public Set<String> getDownloadEntries(final NodeRef downloadNode)
{
return transactionHelper.doInTransaction(new RetryingTransactionCallback<Set<String>>()
{
@Override
public Set<String> execute() throws Throwable
{
Set<String> entryNames = new TreeSet<String>();
ContentReader reader = contentService.getReader(downloadNode, ContentModel.PROP_CONTENT);
try (ZipArchiveInputStream zipInputStream = new ZipArchiveInputStream(reader.getContentInputStream()))
{
ZipArchiveEntry zipEntry = null;
while ((zipEntry = zipInputStream.getNextZipEntry()) != null)
{
String name = zipEntry.getName();
entryNames.add(name);
}
}
return entryNames;
}
});
}
示例4: testApache
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入依賴的package包/類
public void testApache() throws IOException, ArchiveException {
log.debug("testApache()");
File zip = File.createTempFile("apache_", ".zip");
// Create zip
FileOutputStream fos = new FileOutputStream(zip);
ArchiveOutputStream aos = new ArchiveStreamFactory().createArchiveOutputStream("zip", fos);
aos.putArchiveEntry(new ZipArchiveEntry("coñeta"));
aos.closeArchiveEntry();
aos.close();
// Read zip
FileInputStream fis = new FileInputStream(zip);
ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream("zip", fis);
ZipArchiveEntry zae = (ZipArchiveEntry) ais.getNextEntry();
assertEquals(zae.getName(), "coñeta");
ais.close();
}
示例5: contentImpl
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入依賴的package包/類
@Override
public void contentImpl(NodeRef nodeRef, QName property, InputStream content, ContentData contentData, int index)
{
// if the content stream to output is empty, then just return content descriptor as is
if (content == null)
{
return;
}
try
{
// ALF-2016
ZipArchiveEntry zipEntry=new ZipArchiveEntry(getPath());
zipStream.putArchiveEntry(zipEntry);
// copy export stream to zip
copyStream(zipStream, content);
zipStream.closeArchiveEntry();
filesAddedCount = filesAddedCount + 1;
}
catch (IOException e)
{
throw new ExporterException("Failed to zip export stream", e);
}
}
示例6: importStream
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入依賴的package包/類
public InputStream importStream(String content)
{
ZipArchiveEntry zipEntry = zipFile.getEntry(content);
if (zipEntry == null)
{
// Note: for some reason, when modifying a zip archive the path seperator changes
// TODO: Need to investigate further as to why and whether this workaround is enough
content = content.replace('\\', '/');
zipEntry = zipFile.getEntry(content);
if (zipEntry == null)
{
throw new ImporterException("Failed to find content " + content + " within zip package");
}
}
try
{
return zipFile.getInputStream(zipEntry);
}
catch (IOException e)
{
throw new ImporterException("Failed to open content " + content + " within zip package due to " + e.getMessage(), e);
}
}
示例7: postUnzipFileHook
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入依賴的package包/類
/**
* Hook called right after a file has been unzipped (during an install).
* <p/>
* The base class implementation makes sure to properly adjust set executable
* permission on Linux and MacOS system if the zip entry was marked as +x.
*
* @param archive The archive that is being installed.
* @param monitor The {@link ITaskMonitor} to display errors.
* @param fileOp The {@link IFileOp} used by the archive installer.
* @param unzippedFile The file that has just been unzipped in the install temp directory.
* @param zipEntry The {@link ZipArchiveEntry} that has just been unzipped.
*/
public void postUnzipFileHook(
Archive archive,
ITaskMonitor monitor,
IFileOp fileOp,
File unzippedFile,
ZipArchiveEntry zipEntry) {
// if needed set the permissions.
if (sUsingUnixPerm && fileOp.isFile(unzippedFile)) {
// get the mode and test if it contains the executable bit
int mode = zipEntry.getUnixMode();
if ((mode & 0111) != 0) {
try {
fileOp.setExecutablePermission(unzippedFile);
} catch (IOException ignore) {}
}
}
}
示例8: downloadZipAndExtract
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入依賴的package包/類
protected static void downloadZipAndExtract(final String url, final File targetDirectory) {
download(url, inputStream -> {
try {
final byte[] bytes = IOUtils.toByteArray(inputStream);
try (final ZipFile zipFile = new ZipFile(new SeekableInMemoryByteChannel(bytes))) {
final Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();
while (entries.hasMoreElements()) {
final ZipArchiveEntry entry = entries.nextElement();
final File file = new File(targetDirectory, entry.getName());
if (entry.isDirectory()) {
file.mkdir();
continue;
}
try (final OutputStream outputStream =
new BufferedOutputStream(new FileOutputStream(file))) {
IOUtils.copy(zipFile.getInputStream(entry), outputStream);
}
}
}
} catch (final IOException exception) {
throw new RuntimeException(exception);
}
});
}
示例9: 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");
}
}
示例10: handle
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入依賴的package包/類
@Override
public List<ProcessTask> handle(EntityManager manager) throws Exception {
if (!file.exists()) {
return todo;
}
try (ZipFile zip = new ZipFile(file)) {
for (ZipArchiveEntry entry : new IteratorIterable<>(new EnumerationIterator<>(zip.getEntries()))) {
try {
handleSingleZipEntry(zip, entry, manager);
} catch (IOException ex) {
System.out.println(ex.getLocalizedMessage());
}
}
}
return todo;
}
示例11: 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;
}
示例12: 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);
}
}
}
}
}
}
示例13: 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);
}
}
示例14: makeOnlyZip
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入依賴的package包/類
public static void makeOnlyZip() throws IOException, ArchiveException{
File f1 = new File("D:/compresstest.txt");
File f2 = new File("D:/test1.xml");
final OutputStream out = new FileOutputStream("D:/中文名字.zip");
ArchiveOutputStream os = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, out);
os.putArchiveEntry(new ZipArchiveEntry(f1.getName()));
IOUtils.copy(new FileInputStream(f1), os);
os.closeArchiveEntry();
os.putArchiveEntry(new ZipArchiveEntry(f2.getName()));
IOUtils.copy(new FileInputStream(f2), os);
os.closeArchiveEntry();
os.close();
}
示例15: addFilesToZip
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入依賴的package包/類
void addFilesToZip(File source, File destination) throws IOException, ArchiveException {
OutputStream archiveStream = new FileOutputStream(destination);
ArchiveOutputStream archive = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, archiveStream);
Collection<File> fileList = FileUtils.listFiles(source, null, true);
for (File file : fileList) {
String entryName = getEntryName(source, file);
ZipArchiveEntry entry = new ZipArchiveEntry(entryName);
archive.putArchiveEntry(entry);
BufferedInputStream input = new BufferedInputStream(new FileInputStream(file));
IOUtils.copy(input, archive);
input.close();
archive.closeArchiveEntry();
}
archive.finish();
archiveStream.close();
}