大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺
本文整理匯總了Java中org.apache.commons.compress.archivers.zip.ZipFile.getEntries方法的典型用法代碼示例。如果您正苦於以下問題:Java ZipFile.getEntries方法的具體用法?Java ZipFile.getEntries怎麽用?Java ZipFile.getEntries使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.compress.archivers.zip.ZipFile的用法示例。
在下文中一共展示了ZipFile.getEntries方法的30個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。
示例1: extractZip
點讚 4
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
private void extractZip(ZipFile zipFile) {
Enumeration 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);
}
}
}
}
開發者ID:AlejandroRivera,項目名稱:embedded-rabbitmq,代碼行數:23,
示例2: TestBarInstaller
點讚 3
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的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 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”);
}
}
開發者ID:personium,項目名稱:personium-core,代碼行數:29,
示例3: unZipToFolder
點讚 3
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的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);
}
}
開發者ID:h819,項目名稱:spring-boot,代碼行數:26,
示例4: getHashesFromZipFile
點讚 3
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
public List getHashesFromZipFile(File file) throws IOException {
List hashes = new ArrayList<>();
ZipFile zipFile = new ZipFile(file);
byte[] buf = new byte[65536];
Enumeration> entries = zipFile.getEntries();
while (entries.hasMoreElements()) {
ZipArchiveEntry zipArchiveEntry = (ZipArchiveEntry) entries.nextElement();
int n;
InputStream is = zipFile.getInputStream(zipArchiveEntry);
ZipArchiveInputStream zis = new ZipArchiveInputStream(is);
if (zis.canReadEntryData(zipArchiveEntry)) {
while ((n = is.read(buf)) != -1) {
if (n > 0) {
hashes.add(DigestUtils.md5Hex(buf));
}
}
}
zis.close();
}
return hashes;
}
開發者ID:sysunite,項目名稱:excel-microservice,代碼行數:25,
示例5: extractZipFile
點讚 3
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
private static void extractZipFile(final File destination, final ZipFile zipFile) throws IOException {
final Enumeration 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);
}
}
}
}
開發者ID:awslabs,項目名稱:aws-codepipeline-plugin-for-jenkins,代碼行數:20,
示例6: makeTargetZipFile
點讚 3
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
/**
* Writes a modified version of zip_Source into target.
*
* @author S3460
* @param zipSource the zip source
* @param target the target
* @return the zip file
* @throws Exception the exception
*/
private ZipFile makeTargetZipFile(ZipFile zipSource, File target) throws Exception {
ZipArchiveOutputStream out = new ZipArchiveOutputStream(new FileOutputStream(target));
for (Enumeration enumer = zipSource.getEntries(); enumer.hasMoreElements();) {
ZipArchiveEntry sourceEntry = enumer.nextElement();
out.putArchiveEntry(new ZipArchiveEntry(sourceEntry.getName()));
byte[] oldBytes = toBytes(zipSource, sourceEntry);
byte[] newBytes = getRandomBytes();
byte[] mixedBytes = mixBytes(oldBytes, newBytes);
out.write(mixedBytes, 0, mixedBytes.length);
out.flush();
out.closeArchiveEntry();
}
out.putArchiveEntry(new ZipArchiveEntry(“zipentry” + entryMaxSize + 1));
byte[] bytes = getRandomBytes();
out.write(bytes, 0, bytes.length);
out.flush();
out.closeArchiveEntry();
out.putArchiveEntry(new ZipArchiveEntry(“zipentry” + (entryMaxSize + 2)));
out.closeArchiveEntry();
out.flush();
out.finish();
out.close();
return new ZipFile(targetFile);
}
開發者ID:NitorCreations,項目名稱:javaxdelta,代碼行數:34,
示例7: compareFiles
點讚 3
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
/**
* Compares the content of two zip files. The zip files are considered equal, if
* the content of all zip entries is equal to the content of its corresponding entry
* in the other zip file.
*
* @author S3460
* @param zipSource the zip source
* @param resultZip the result zip
* @throws Exception the exception
*/
private void compareFiles(ZipFile zipSource, ZipFile resultZip) throws Exception {
boolean rc = false;
try {
for (Enumeration enumer = zipSource.getEntries(); enumer.hasMoreElements();) {
ZipArchiveEntry sourceEntry = enumer.nextElement();
ZipArchiveEntry resultEntry = resultZip.getEntry(sourceEntry.getName());
assertNotNull(“Entry nicht generiert: ” + sourceEntry.getName(), resultEntry);
byte[] oldBytes = toBytes(zipSource, sourceEntry);
byte[] newBytes = toBytes(resultZip, resultEntry);
rc = equal(oldBytes, newBytes);
assertTrue(“bytes the same ” + sourceEntry, rc);
}
} finally {
zipSource.close();
resultZip.close();
}
}
開發者ID:NitorCreations,項目名稱:javaxdelta,代碼行數:28,
示例8: detectKmz
點讚 3
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
private static MediaType detectKmz(ZipFile zip) {
boolean kmlFound = false;
Enumeration 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;
}
}
開發者ID:kolbasa,項目名稱:OCRaptor,代碼行數:24,
示例9: detectIpa
點讚 3
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
@SuppressWarnings(“unchecked”)
private static MediaType detectIpa(ZipFile zip) {
// Note – consider generalising this logic, if another format needs many regexp matching
Set tmpPatterns = (Set)ipaEntryPatterns.clone();
Enumeration entries = zip.getEntries();
while (entries.hasMoreElements()) {
ZipArchiveEntry entry = entries.nextElement();
String name = entry.getName();
Iterator ip = tmpPatterns.iterator();
while (ip.hasNext()) {
if (ip.next().matcher(name).matches()) {
ip.remove();
}
}
if (tmpPatterns.isEmpty()) {
// We’ve found everything we need to find
return MediaType.application(“x-itunes-ipa”);
}
}
// If we get here, not all required entries were found
return null;
}
開發者ID:kolbasa,項目名稱:OCRaptor,代碼行數:26,
示例10: testEmptyBaseDirRelativeDir
點讚 3
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
@Test
public void testEmptyBaseDirRelativeDir() throws Exception {
String aTargetFilename = “target/Z6-input.zip”;
ZipFilesTasklet aTasklet = new ZipFilesTasklet();
aTasklet.setSourceBaseDirectory(new FileSystemResource(“”));
FileSystemResourcesFactory aSourceFactory = new FileSystemResourcesFactory();
aSourceFactory.setPattern(“file:src/test/resources/testFiles/input.csv”);
aTasklet.setSourceFactory(aSourceFactory );
ExpressionResourceFactory aDestinationFactory = new ExpressionResourceFactory();
aDestinationFactory.setExpression(aTargetFilename);
aTasklet.setDestinationFactory(aDestinationFactory );
assertEquals(RepeatStatus.FINISHED, aTasklet.execute(null, null));
assertTrue(new File(aTargetFilename).exists());
ZipFile aZipFile = new ZipFile(new File(aTargetFilename));
Enumeration aEntries = aZipFile.getEntries();
assertTrue(aEntries.hasMoreElements());
assertEquals(“src/test/resources/testFiles/input.csv”, aEntries.nextElement().getName());
assertFalse(aEntries.hasMoreElements());
aZipFile.close();
}
開發者ID:acxio,項目名稱:AGIA,代碼行數:23,
示例11: readFirstZipEntry
點讚 3
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
/**
* Reads the first file entry in a zip file and returns it’s contents
* as uncompressed byte-array
* @param zipFile the zip file to read from
* @return the first file entry (uncompressed)
* @throws IOException if there is an error accessing the zip file
*/
public static byte[] readFirstZipEntry(File zipFile) throws IOException {
// open zip
ZipFile zf = new ZipFile(zipFile);
Enumeration entries = zf.getEntries();
// read first entry to byte[]
ZipArchiveEntry entry = entries.nextElement();
InputStream is = zf.getInputStream(entry);
byte[] raw = ByteStreams.toByteArray(is);
// close all streams and return byte[]
is.close();
zf.close();
return raw;
}
開發者ID:klamann,項目名稱:maps4cim,代碼行數:23,
示例12: unzip
點讚 2
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
public static void unzip(File zipFile, File destination)
throws IOException {
ZipFile zip = new ZipFile(zipFile);
try {
Enumeration 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);
}
}
開發者ID:NBANDROIDTEAM,項目名稱:NBANDROID-V2,代碼行數:36,
示例13: unzipToTemporaryDirectory
點讚 2
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
public static Path unzipToTemporaryDirectory(File file) throws IOException {
ZipFile zipFile = new ZipFile(file);
Enumeration zipEntries = zipFile.getEntries();
Path tempDirectory = Files.createTempDirectory(“temp”);
while (zipEntries.hasMoreElements()) {
ZipArchiveEntry entry = zipEntries.nextElement();
FileUtils.copyInputStreamToFile(zipFile.getInputStream(entry), new File(Paths.get(tempDirectory.toString(),”/” + entry.getName()).toString()));
}
zipFile.close();
return tempDirectory;
}
開發者ID:FutureCitiesCatapult,項目名稱:TomboloDigitalConnector,代碼行數:13,
示例14: extractAll
點讚 2
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
public static void extractAll(String zipFile, String extractDir) throws Exception {
ZipFile unzipFile = new ZipFile(zipFile);
try {
File root = new File(extractDir);
Enumeration fileHeaderList = unzipFile.getEntries();
while(fileHeaderList.hasMoreElements()) {
ZipArchiveEntry fileHeader = fileHeaderList.nextElement();
if (fileHeader.isDirectory()) {
//…
} else if (!fileHeader.isUnixSymlink()) {
File f = new File(root, fileHeader.getName());
File dir = f.getParentFile();
if (!dir.exists()) {
dir.mkdirs();
}
FileOutputStream fout = new FileOutputStream(f);
try {
IOUtils.copy(unzipFile.getInputStream(fileHeader), fout);
} finally {
try {
fout.close();
} catch (Throwable e) {
}
}
f.setLastModified(fileHeader.getLastModifiedDate().getTime());
}
}
} finally {
ZipFile.closeQuietly(unzipFile);
}
}
開發者ID:BeckYang,項目名稱:TeamFileList,代碼行數:32,
示例15: decompressZip
點讚 2
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
public void decompressZip(File zipFile, String dir) throws IOException {
ZipFile zf = new ZipFile(zipFile);
try {
for (Enumeration entries = zf.getEntries(); entries
.hasMoreElements();) {
ZipArchiveEntry ze = entries.nextElement();
// 不存在則創建目標文件夾。
File targetFile = new File(dir, ze.getName());
// 遇到根目錄時跳過。
if (ze.getName().lastIndexOf(“/”) == (ze.getName().length() – 1)) {
continue;
}
// 如果文件夾不存在,創建文件夾。
if (!targetFile.getParentFile().exists()) {
targetFile.getParentFile().mkdirs();
}
InputStream i = zf.getInputStream(ze);
OutputStream o = null;
try {
o = new FileOutputStream(targetFile);
IOUtils.copy(i, o);
} finally {
if (i != null) {
i.close();
}
if (o != null) {
o.close();
}
}
}
} finally {
zf.close();
}
}
開發者ID:hoozheng,項目名稱:AndroidRobot,代碼行數:36,
示例16: readZip
點讚 2
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
public ZipArchiveEntry readZip(File zipFile, String fileName)
throws IOException {
ZipFile zf = new ZipFile(zipFile);
Enumeration zips = zf.getEntries();
ZipArchiveEntry zip = null;
while (zips.hasMoreElements()) {
zip = zips.nextElement();
if (fileName.equals(zip.getName())) {
return zip;
}
}
return null;
}
開發者ID:hoozheng,項目名稱:AndroidRobot,代碼行數:14,
示例17: findBestSource
點讚 2
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
/**
* Find best source.
*
* @param source the source
* @param target the target
* @param targetEntry the target entry
* @return the zip archive entry
* @throws IOException Signals that an I/O exception has occurred.
*/
public ZipArchiveEntry findBestSource(ZipFile source, ZipFile target, ZipArchiveEntry targetEntry) throws IOException {
ArrayList ret = new ArrayList<>();
for (ZipArchiveEntry next : source.getEntries(targetEntry.getName())) {
if (next.getCrc() == targetEntry.getCrc())
return next;
ret.add(next);
}
if (ret.size() == 0)
return null;
if (ret.size() == 1 || targetEntry.isDirectory())
return ret.get(0);
//More than one and no matching crc — need to calculate xdeltas and pick the shortest
ZipArchiveEntry retEntry = null;
for (ZipArchiveEntry sourceEntry : ret) {
try (ByteArrayOutputStream outbytes = new ByteArrayOutputStream()) {
Delta d = new Delta();
DiffWriter diffWriter = new GDiffWriter(new DataOutputStream(outbytes));
int sourceSize = (int) sourceEntry.getSize();
byte[] sourceBytes = new byte[sourceSize];
try (InputStream sourceStream = source.getInputStream(sourceEntry)) {
for (int erg = sourceStream.read(sourceBytes); erg < sourceBytes.length; erg += sourceStream.read(sourceBytes, erg, sourceBytes.length – erg));
}
d.compute(sourceBytes, target.getInputStream(targetEntry), diffWriter);
byte[] nextDiff = outbytes.toByteArray();
if (calculatedDelta == null || calculatedDelta.length > nextDiff.length) {
retEntry = sourceEntry;
calculatedDelta = nextDiff;
}
}
}
return retEntry;
}
開發者ID:NitorCreations,項目名稱:javaxdelta,代碼行數:42,
示例18: getEntry
點讚 2
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
/**
* Gets the entry.
*
* @param source the source
* @param name the name
* @param crc the crc
* @return the entry
*/
private ZipArchiveEntry getEntry(ZipFile source, String name, long crc) {
for (ZipArchiveEntry next : source.getEntries(name)) {
if (next.getCrc() == crc)
return next;
}
if (!JarDelta.zipFilesPattern.matcher(name).matches()) {
return null;
} else {
return source.getEntry(name);
}
}
開發者ID:NitorCreations,項目名稱:javaxdelta,代碼行數:20,
示例19: getPatchEntry
點讚 2
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
/**
* Gets the patch entry.
*
* @param source the source
* @param name the name
* @param crc the crc
* @return the patch entry
*/
private ZipArchiveEntry getPatchEntry(ZipFile source, String name, long crc) {
for (ZipArchiveEntry next : source.getEntries(name)) {
long nextCrc = Long.parseLong(next.getComment());
if (nextCrc == crc)
return next;
}
return null;
}
開發者ID:NitorCreations,項目名稱:javaxdelta,代碼行數:17,
示例20: parseMQZip
點讚 2
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
/**
* 解析 memoQ 的源文件,並將內容拷貝至骨架文件中
* @param mqZip
* @param hsSkeletonR8 hsxliff的骨架文件
* @throws Exception
*/
private void parseMQZip(String mqZip, String hsSkeleton) throws Exception{
ZipFile zipFile = new ZipFile(new File(mqZip), “utf-8”);
Enumeration> e = zipFile.getEntries();
byte ch[] = new byte[1024];
String outputFile = “”;
File mqSklTempFile = File.createTempFile(“tempskl”, “skl”);
mqSklTempFile.deleteOnExit();
while (e.hasMoreElements()) {
ZipArchiveEntry zipEntry = (ZipArchiveEntry) e.nextElement();
if (“document.mqxliff”.equals(zipEntry.getName())) {
outputFile = hsSkeleton;
}else {
outputFile = mqSklTempFile.getAbsolutePath();
}
File zfile = new File(outputFile);
FileOutputStream fouts = new FileOutputStream(zfile);
InputStream in = zipFile.getInputStream(zipEntry);
int i;
while ((i = in.read(ch)) != -1)
fouts.write(ch, 0, i);
fouts.close();
in.close();
}
//解析r8骨加文件,並把 mq 的骨架信息添加到 r8 的骨架文件中
parseHSSkeletonFile();
copyMqSklToHsSkl(mqSklTempFile);
}
開發者ID:heartsome,項目名稱:translationstudio8,代碼行數:35,
示例21: testZipFile
點讚 2
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
@Test
public void testZipFile() throws Exception {
String aTargetFilename = “target/Z0-input.zip”;
ZipFilesTasklet aTasklet = new ZipFilesTasklet();
aTasklet.setSourceBaseDirectory(new FileSystemResource(“src/test/resources/testFiles/”));
FileSystemResourcesFactory aSourceFactory = new FileSystemResourcesFactory();
aSourceFactory.setPattern(“file:src/test/resources/testFiles/input.csv”);
aTasklet.setSourceFactory(aSourceFactory );
ExpressionResourceFactory aDestinationFactory = new ExpressionResourceFactory();
aDestinationFactory.setExpression(aTargetFilename);
aTasklet.setDestinationFactory(aDestinationFactory );
assertFalse(new File(aTargetFilename).exists());
StepContribution aStepContribution = mock(StepContribution.class);
assertEquals(RepeatStatus.FINISHED, aTasklet.execute(aStepContribution, null));
verify(aStepContribution, times(1)).incrementReadCount();
verify(aStepContribution, times(1)).incrementWriteCount(1);
assertTrue(new File(aTargetFilename).exists());
ZipFile aZipFile = new ZipFile(new File(aTargetFilename));
Enumeration aEntries = aZipFile.getEntries();
assertTrue(aEntries.hasMoreElements());
assertEquals(“input.csv”, aEntries.nextElement().getName());
assertFalse(aEntries.hasMoreElements());
aZipFile.close();
}
開發者ID:acxio,項目名稱:AGIA,代碼行數:28,
示例22: testZipTwoFile
點讚 2
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
@Test
public void testZipTwoFile() throws Exception {
FileUtils.forceMkdir(new File(“target/Z-testfiles/source”));
FileUtils.copyFile(new File(“src/test/resources/testFiles/input.csv”), new File(“target/Z-testfiles/source/CP0-input.csv”));
FileUtils.copyFile(new File(“src/test/resources/testFiles/input.csv”), new File(“target/Z-testfiles/source/CP1-input.csv”));
String aTargetFilename = “target/Z1-input.zip”;
ZipFilesTasklet aTasklet = new ZipFilesTasklet();
aTasklet.setSourceBaseDirectory(new FileSystemResource(“target/Z-testfiles/source/”));
FileSystemResourcesFactory aSourceFactory = new FileSystemResourcesFactory();
aSourceFactory.setPattern(“file:target/Z-testfiles/source/*input*.csv”);
aTasklet.setSourceFactory(aSourceFactory );
ExpressionResourceFactory aDestinationFactory = new ExpressionResourceFactory();
aDestinationFactory.setExpression(aTargetFilename);
aTasklet.setDestinationFactory(aDestinationFactory );
assertFalse(new File(aTargetFilename).exists());
StepContribution aStepContribution = mock(StepContribution.class);
assertEquals(RepeatStatus.FINISHED, aTasklet.execute(aStepContribution, null));
verify(aStepContribution, times(2)).incrementReadCount();
verify(aStepContribution, times(2)).incrementWriteCount(1);
assertTrue(new File(aTargetFilename).exists());
ZipFile aZipFile = new ZipFile(new File(aTargetFilename));
Enumeration aEntries = aZipFile.getEntries();
assertTrue(aEntries.hasMoreElements());
assertEquals(“CP0-input.csv”, aEntries.nextElement().getName());
assertTrue(aEntries.hasMoreElements());
assertEquals(“CP1-input.csv”, aEntries.nextElement().getName());
assertFalse(aEntries.hasMoreElements());
aZipFile.close();
}
開發者ID:acxio,項目名稱:AGIA,代碼行數:34,
示例23: testZipDirectory
點讚 2
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
@Test
public void testZipDirectory() throws Exception {
FileUtils.forceMkdir(new File(“target/Z-testfiles/source”));
FileUtils.copyFile(new File(“src/test/resources/testFiles/input.csv”), new File(“target/Z-testfiles/source/CP0-input.csv”));
FileUtils.copyFile(new File(“src/test/resources/testFiles/input.csv”), new File(“target/Z-testfiles/source/CP1-input.csv”));
String aTargetFilename = “target/Z2-input.zip”;
ZipFilesTasklet aTasklet = new ZipFilesTasklet();
aTasklet.setSourceBaseDirectory(new FileSystemResource(“target/Z-testfiles/”));
FileSystemResourcesFactory aSourceFactory = new FileSystemResourcesFactory();
aSourceFactory.setPattern(“file:target/Z-testfiles/source/”);
aTasklet.setSourceFactory(aSourceFactory );
ExpressionResourceFactory aDestinationFactory = new ExpressionResourceFactory();
aDestinationFactory.setExpression(aTargetFilename);
aTasklet.setDestinationFactory(aDestinationFactory );
assertFalse(new File(aTargetFilename).exists());
StepContribution aStepContribution = mock(StepContribution.class);
assertEquals(RepeatStatus.FINISHED, aTasklet.execute(aStepContribution, null));
verify(aStepContribution, times(3)).incrementReadCount();
verify(aStepContribution, times(3)).incrementWriteCount(1);
assertTrue(new File(aTargetFilename).exists());
ZipFile aZipFile = new ZipFile(new File(aTargetFilename));
Enumeration aEntries = aZipFile.getEntries();
assertTrue(aEntries.hasMoreElements());
assertEquals(“source”, aEntries.nextElement().getName());
assertTrue(aEntries.hasMoreElements());
assertEquals(“source/CP0-input.csv”, aEntries.nextElement().getName());
assertTrue(aEntries.hasMoreElements());
assertEquals(“source/CP1-input.csv”, aEntries.nextElement().getName());
assertFalse(aEntries.hasMoreElements());
aZipFile.close();
}
開發者ID:acxio,項目名稱:AGIA,代碼行數:36,
示例24: testZipDirectories
點讚 2
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
@Test
public void testZipDirectories() throws Exception {
FileUtils.forceMkdir(new File(“target/Z-testfiles/source/subdir”));
FileUtils.copyFile(new File(“src/test/resources/testFiles/input.csv”), new File(“target/Z-testfiles/source/CP0-input.csv”));
FileUtils.copyFile(new File(“src/test/resources/testFiles/input.csv”), new File(“target/Z-testfiles/source/subdir/CP1-input.csv”));
String aTargetFilename = “target/Z3-input.zip”;
ZipFilesTasklet aTasklet = new ZipFilesTasklet();
aTasklet.setSourceBaseDirectory(new FileSystemResource(“target/Z-testfiles/”));
FileSystemResourcesFactory aSourceFactory = new FileSystemResourcesFactory();
aSourceFactory.setPattern(“file:target/Z-testfiles/source/”);
aTasklet.setSourceFactory(aSourceFactory );
ExpressionResourceFactory aDestinationFactory = new ExpressionResourceFactory();
aDestinationFactory.setExpression(aTargetFilename);
aTasklet.setDestinationFactory(aDestinationFactory );
assertFalse(new File(aTargetFilename).exists());
StepContribution aStepContribution = mock(StepContribution.class);
assertEquals(RepeatStatus.FINISHED, aTasklet.execute(aStepContribution, null));
verify(aStepContribution, times(4)).incrementReadCount();
verify(aStepContribution, times(4)).incrementWriteCount(1);
assertTrue(new File(aTargetFilename).exists());
ZipFile aZipFile = new ZipFile(new File(aTargetFilename));
Enumeration aEntries = aZipFile.getEntries();
assertTrue(aEntries.hasMoreElements());
assertEquals(“source”, aEntries.nextElement().getName());
assertTrue(aEntries.hasMoreElements());
assertEquals(“source/CP0-input.csv”, aEntries.nextElement().getName());
assertTrue(aEntries.hasMoreElements());
assertEquals(“source/subdir”, aEntries.nextElement().getName());
assertTrue(aEntries.hasMoreElements());
assertEquals(“source/subdir/CP1-input.csv”, aEntries.nextElement().getName());
assertFalse(aEntries.hasMoreElements());
aZipFile.close();
}
開發者ID:acxio,項目名稱:AGIA,代碼行數:38,
示例25: testZipDirectoriesNotRecursive
點讚 2
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
@Test
public void testZipDirectoriesNotRecursive() throws Exception {
FileUtils.forceMkdir(new File(“target/Z-testfiles/source/subdir”));
FileUtils.copyFile(new File(“src/test/resources/testFiles/input.csv”), new File(“target/Z-testfiles/source/CP0-input.csv”));
FileUtils.copyFile(new File(“src/test/resources/testFiles/input.csv”), new File(“target/Z-testfiles/source/subdir/CP1-input.csv”));
String aTargetFilename = “target/Z4-input.zip”;
ZipFilesTasklet aTasklet = new ZipFilesTasklet();
aTasklet.setSourceBaseDirectory(new FileSystemResource(“target/Z-testfiles/”));
FileSystemResourcesFactory aSourceFactory = new FileSystemResourcesFactory();
aSourceFactory.setPattern(“file:target/Z-testfiles/source/”);
aTasklet.setSourceFactory(aSourceFactory );
ExpressionResourceFactory aDestinationFactory = new ExpressionResourceFactory();
aDestinationFactory.setExpression(aTargetFilename);
aTasklet.setDestinationFactory(aDestinationFactory );
aTasklet.setRecursive(false);
assertFalse(new File(aTargetFilename).exists());
StepContribution aStepContribution = mock(StepContribution.class);
assertEquals(RepeatStatus.FINISHED, aTasklet.execute(aStepContribution, null));
verify(aStepContribution, times(2)).incrementReadCount();
verify(aStepContribution, times(2)).incrementWriteCount(1);
assertTrue(new File(aTargetFilename).exists());
ZipFile aZipFile = new ZipFile(new File(aTargetFilename));
Enumeration aEntries = aZipFile.getEntries();
assertTrue(aEntries.hasMoreElements());
assertEquals(“source”, aEntries.nextElement().getName());
assertTrue(aEntries.hasMoreElements());
assertEquals(“source/CP0-input.csv”, aEntries.nextElement().getName());
assertFalse(aEntries.hasMoreElements());
aZipFile.close();
}
開發者ID:acxio,項目名稱:AGIA,代碼行數:35,
示例26: testExistingZipFile
點讚 2
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
@Test
public void testExistingZipFile() throws Exception {
File aTargetFile = File.createTempFile(“target/Z8-input”, “.zip”);
String aTargetFilename = aTargetFile.getAbsolutePath();
ZipFilesTasklet aTasklet = new ZipFilesTasklet();
aTasklet.setSourceBaseDirectory(new FileSystemResource(“src/test/resources/testFiles/”));
FileSystemResourcesFactory aSourceFactory = new FileSystemResourcesFactory();
aSourceFactory.setPattern(“file:src/test/resources/testFiles/input.csv”);
aTasklet.setSourceFactory(aSourceFactory );
ExpressionResourceFactory aDestinationFactory = new ExpressionResourceFactory();
aDestinationFactory.setExpression(aTargetFilename);
aTasklet.setDestinationFactory(aDestinationFactory );
assertTrue(new File(aTargetFilename).exists());
StepContribution aStepContribution = mock(StepContribution.class);
assertEquals(RepeatStatus.FINISHED, aTasklet.execute(aStepContribution, null));
verify(aStepContribution, times(1)).incrementReadCount();
verify(aStepContribution, times(1)).incrementWriteCount(1);
assertTrue(new File(aTargetFilename).exists());
ZipFile aZipFile = new ZipFile(new File(aTargetFilename));
Enumeration aEntries = aZipFile.getEntries();
assertTrue(aEntries.hasMoreElements());
assertEquals(“input.csv”, aEntries.nextElement().getName());
assertFalse(aEntries.hasMoreElements());
aZipFile.close();
}
開發者ID:acxio,項目名稱:AGIA,代碼行數:30,
示例27: testExistingLockedZipFile
點讚 2
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
@Test
public void testExistingLockedZipFile() throws Exception {
exception.expect(IOException.class);
File aTargetFile = File.createTempFile(“target/Z9-input”, “.zip”);
aTargetFile.setWritable(false);
String aTargetFilename = aTargetFile.getAbsolutePath();
ZipFilesTasklet aTasklet = new ZipFilesTasklet();
aTasklet.setSourceBaseDirectory(new FileSystemResource(“src/test/resources/testFiles/”));
FileSystemResourcesFactory aSourceFactory = new FileSystemResourcesFactory();
aSourceFactory.setPattern(“file:src/test/resources/testFiles/input.csv”);
aTasklet.setSourceFactory(aSourceFactory );
ExpressionResourceFactory aDestinationFactory = new ExpressionResourceFactory();
aDestinationFactory.setExpression(aTargetFilename);
aTasklet.setDestinationFactory(aDestinationFactory );
assertTrue(new File(aTargetFilename).exists());
StepContribution aStepContribution = mock(StepContribution.class);
assertEquals(RepeatStatus.FINISHED, aTasklet.execute(aStepContribution, null));
verify(aStepContribution, times(1)).incrementReadCount();
verify(aStepContribution, times(1)).incrementWriteCount(1);
assertTrue(new File(aTargetFilename).exists());
ZipFile aZipFile = new ZipFile(new File(aTargetFilename));
Enumeration aEntries = aZipFile.getEntries();
assertTrue(aEntries.hasMoreElements());
assertEquals(“input.csv”, aEntries.nextElement().getName());
assertFalse(aEntries.hasMoreElements());
aZipFile.close();
}
開發者ID:acxio,項目名稱:AGIA,代碼行數:32,
示例28: extractZip
點讚 2
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
/**
* Extracts a {@code *.zip} archive into the target folder.
* @param monitor the progress monitor
* @param archiveFile the archive file
* @param targetDirectory the target folder
* @throws IOException if failed to extract the archive
*/
public static void extractZip(
IProgressMonitor monitor,
File archiveFile,
File targetDirectory) throws IOException {
SubMonitor sub = SubMonitor.convert(monitor, Messages.IoUtils_monitorExtractZip, 10);
try {
ZipFile zip = new ZipFile(archiveFile);
try {
Enumeration entries = zip.getEntries();
while (entries.hasMoreElements()) {
ZipArchiveEntry entry = entries.nextElement();
if (entry.isDirectory()) {
createDirectory(targetDirectory, entry);
} else {
InputStream input = zip.getInputStream(entry);
try {
File file = createFile(targetDirectory, entry, input);
setFileMode(file, entry.getUnixMode());
} finally {
input.close();
}
sub.worked(1);
sub.setWorkRemaining(10);
}
}
} finally {
zip.close();
}
} finally {
if (monitor != null) {
monitor.done();
}
}
}
開發者ID:asakusafw,項目名稱:asakusafw-shafu,代碼行數:42,
示例29: testExportArchiveZip
點讚 2
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
@Test
public void testExportArchiveZip() throws Exception {
final Project p = makeGoodProject();
final List infos = this.bean.getAvailablePackagingInfos(p);
final PackagingInfo zipPi = Iterables.find(infos, new Predicate() {
@Override
public boolean apply(PackagingInfo t) {
return t.getMethod() == PackagingInfo.PackagingMethod.ZIP;
}
});
final File f = File.createTempFile(“test”, zipPi.getName());
final FileOutputStream fos = new FileOutputStream(f);
this.bean.export(p, “http://example.com/my_experiemnt”, PackagingInfo.PackagingMethod.ZIP, fos);
fos.close();
final ZipFile zf = new ZipFile(f);
final Enumeration en = zf.getEntries();
final Set entries = new HashSet();
entries.addAll(java.util.Arrays.asList(“test-exp-id.soft.txt”, “raw_file.data”, “derived_file.data”,
“supplimental.data”));
while (en.hasMoreElements()) {
final ZipArchiveEntry ze = en.nextElement();
assertTrue(ze.getName() + ” unexpected”, entries.remove(ze.getName()));
}
assertTrue(entries.toString() + ” not found”, entries.isEmpty());
}
開發者ID:NCIP,項目名稱:caarray,代碼行數:28,
示例30: init
點讚 2
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
private void init()
throws MalformedURLException,
IOException {
if (!wrs2Shape.exists()) {
if (!wrs2Directory.delete()) {
LOGGER.warn(“Unable to delete ‘” + wrs2Directory.getAbsolutePath() + “‘”);
}
final File wsDir = wrs2Directory.getParentFile();
if (!wsDir.exists() && !wsDir.mkdirs()) {
LOGGER.warn(“Unable to create directory ‘” + wsDir.getAbsolutePath() + “‘”);
}
// download and unzip the shapefile
final File targetFile = new File(
wsDir,
WRS2_SHAPE_ZIP);
if (targetFile.exists()) {
if (!targetFile.delete()) {
LOGGER.warn(“Unable to delete file ‘” + targetFile.getAbsolutePath() + “‘”);
}
}
FileUtils.copyURLToFile(
new URL(
WRS2_SHAPE_URL),
targetFile);
final ZipFile zipFile = new ZipFile(
targetFile);
try {
final Enumeration entries = zipFile.getEntries();
while (entries.hasMoreElements()) {
final ZipArchiveEntry entry = entries.nextElement();
if (!entry.isDirectory()) {
FileUtils.copyInputStreamToFile(
zipFile.getInputStream(entry),
new File(
wsDir,
entry.getName()));
// HP Fortify “Path Traversal” false positive
// What Fortify considers “user input” comes only
// from users with OS-level access anyway
}
}
}
finally {
zipFile.close();
}
}
// read the shapefile and cache the features for quick lookup by path
// and row
try {
final Map map = new HashMap();
map.put(
“url”,
wrs2Shape.toURI().toURL());
final DataStore dataStore = DataStoreFinder.getDataStore(map);
if (dataStore == null) {
LOGGER.error(“Unable to get a datastore instance, getDataStore returned null”);
return;
}
final SimpleFeatureSource source = dataStore.getFeatureSource(WRS2_TYPE_NAME);
final SimpleFeatureCollection featureCollection = source.getFeatures();
wrs2Type = featureCollection.getSchema();
final SimpleFeatureIterator iterator = featureCollection.features();
while (iterator.hasNext()) {
final SimpleFeature feature = iterator.next();
final Number path = (Number) feature.getAttribute(“PATH”);
final Number row = (Number) feature.getAttribute(“ROW”);
featureCache.put(
new WRS2Key(
path.intValue(),
row.intValue()),
(MultiPolygon) feature.getDefaultGeometry());
}
}
catch (final IOException e) {
LOGGER.error(
“Unable to read wrs2_asc_desc shapefile ‘” + wrs2Shape.getAbsolutePath() + “‘”,
e);
throw (e);
}
}
開發者ID:locationtech,項目名稱:geowave,代碼行數:82,
注:本文中的org.apache.commons.compress.archivers.zip.ZipFile.getEntries方法示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/193631.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...