本文整理匯總了Java中org.apache.commons.compress.archivers.zip.ZipFile.getEntry方法的典型用法代碼示例。如果您正苦於以下問題:Java ZipFile.getEntry方法的具體用法?Java ZipFile.getEntry怎麽用?Java ZipFile.getEntry使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.compress.archivers.zip.ZipFile
的用法示例。
在下文中一共展示了ZipFile.getEntry方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: compareFiles
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<ZipArchiveEntry> 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();
}
}
示例2: runJarPatcher
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
/**
* Run jar patcher.
*
* @param originalName the original name
* @param targetName the target name
* @param originalZip the original zip
* @param newZip the new zip
* @param comparefiles the comparefiles
* @throws Exception the exception
*/
private void runJarPatcher(String originalName, String targetName, ZipFile originalZip, ZipFile newZip, boolean comparefiles) throws Exception {
try (ZipArchiveOutputStream output = new ZipArchiveOutputStream(new FileOutputStream(patchFile))) {
new JarDelta().computeDelta(originalName, targetName, originalZip, newZip, output);
}
ZipFile patch = new ZipFile(patchFile);
ZipArchiveEntry listEntry = patch.getEntry("META-INF/file.list");
if (listEntry == null) {
patch.close();
throw new IOException("Invalid patch - list entry 'META-INF/file.list' not found");
}
BufferedReader patchlist = new BufferedReader(new InputStreamReader(patch.getInputStream(listEntry)));
String next = patchlist.readLine();
String sourceName = next;
next = patchlist.readLine();
new JarPatcher(patchFile.getName(), sourceName).applyDelta(patch, new ZipFile(originalName), new ZipArchiveOutputStream(new FileOutputStream(resultFile)), patchlist);
if (comparefiles) {
compareFiles(new ZipFile(targetName), new ZipFile(resultFile));
}
}
示例3: testJarPatcherIdentFile
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
/**
* Tests JarDelta and JarPatcher on two identical files.
*
* @throws Exception the exception
*/
@Test
public void testJarPatcherIdentFile() throws Exception {
ZipFile originalZip = makeSourceZipFile(sourceFile);
new JarDelta().computeDelta(sourceFile.getAbsolutePath(), sourceFile.getAbsolutePath(), originalZip, originalZip, new ZipArchiveOutputStream(new FileOutputStream(patchFile)));
ZipFile patch = new ZipFile(patchFile);
ZipArchiveEntry listEntry = patch.getEntry("META-INF/file.list");
if (listEntry == null) {
patch.close();
throw new IOException("Invalid patch - list entry 'META-INF/file.list' not found");
}
BufferedReader patchlist = new BufferedReader(new InputStreamReader(patch.getInputStream(listEntry)));
String next = patchlist.readLine();
String sourceName = next;
next = patchlist.readLine();
ZipFile source = new ZipFile(sourceFile);
new JarPatcher(patchFile.getName(), sourceName).applyDelta(patch, source, new ZipArchiveOutputStream(new FileOutputStream(resultFile)), patchlist);
compareFiles(new ZipFile(sourceFile), new ZipFile(resultFile));
}
示例4: addPrimaryPicture
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
/**
* Add the primary picture to the collection.
*
* @param primaryPicture
* @param c
* @param repository
* @param zip
*/
private void addPrimaryPicture(String primaryPicture, InstitutionalCollection c, Repository repository, ZipFile zip)
{
File f = new File(primaryPicture);
ZipArchiveEntry entry = zip.getEntry(primaryPicture);
zipHelper.getZipEntry(f, entry, zip);
IrFile picture;
try {
picture = repositoryService.createIrFile(repository, f, primaryPicture, "primary news picture for collection id = "
+ c.getId());
c.setPrimaryPicture(picture);
} catch (IllegalFileSystemNameException e) {
log.error(e);
}
if( !FileUtils.deleteQuietly(f) )
{
log.error("file " + f + " not deleted");
}
}
示例5: addPicture
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
/**
* Add a single picture to the collection.
*
* @param picture
* @param c
* @param repository
* @param zip
*/
private void addPicture(String picture, InstitutionalCollection c, Repository repository, ZipFile zip)
{
if( picture != null )
{
File f = new File(picture);
ZipArchiveEntry entry = zip.getEntry(picture);
zipHelper.getZipEntry(f, entry, zip);
IrFile thePicture;
try {
thePicture = repositoryService.createIrFile(repository, f, picture, "primary news picture for collection id = "
+ c.getId());
c.addPicture(thePicture);
} catch (IllegalFileSystemNameException e) {
log.error(e);
}
if( !FileUtils.deleteQuietly(f) )
{
log.error("file " + f + " not deleted");
}
}
}
示例6: detectOpenDocument
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
/**
* OpenDocument files, along with EPub files, have a mimetype
* entry in the root of their Zip file. This entry contains the
* mimetype of the overall file, stored as a single string.
*/
private static MediaType detectOpenDocument(ZipFile zip) {
try {
ZipArchiveEntry mimetype = zip.getEntry("mimetype");
if (mimetype != null) {
InputStream stream = zip.getInputStream(mimetype);
try {
return MediaType.parse(IOUtils.toString(stream, "UTF-8"));
} finally {
stream.close();
}
} else {
return null;
}
} catch (IOException e) {
return null;
}
}
示例7: detectIWork
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
private static MediaType detectIWork(ZipFile zip) {
if (zip.getEntry(IWorkPackageParser.IWORK_COMMON_ENTRY) != null) {
// Locate the appropriate index file entry, and reads from that
// the root element of the document. That is used to the identify
// the correct type of the keynote container.
for (String entryName : IWorkPackageParser.IWORK_CONTENT_ENTRIES) {
IWORKDocumentType type = IWORKDocumentType.detectType(zip.getEntry(entryName), zip);
if (type != null) {
return type.getType();
}
}
// Not sure, fallback to the container type
return MediaType.application("vnd.apple.iwork");
} else {
return null;
}
}
示例8: testShouldBeAbleToCreateCustomizedAndroidApplicationXML
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
@Test
public void testShouldBeAbleToCreateCustomizedAndroidApplicationXML() throws Exception {
SelendroidServerBuilder builder = getDefaultBuilder();
builder.init(new DefaultAndroidApp(new File(APK_FILE)));
builder.cleanUpPrebuildServer();
File file = builder.createAndAddCustomizedAndroidManifestToSelendroidServer();
ZipFile zipFile = new ZipFile(file);
ZipArchiveEntry entry = zipFile.getEntry("AndroidManifest.xml");
Assert.assertEquals(entry.getName(), "AndroidManifest.xml");
Assert.assertTrue("Expecting non empty AndroidManifest.xml file", entry.getSize() > 700);
// Verify that apk is not yet signed
CommandLine cmd = new CommandLine(AndroidSdk.aapt());
cmd.addArgument("list", false);
cmd.addArgument(builder.getSelendroidServer().getAbsolutePath(), false);
String output = ShellCommand.exec(cmd);
assertResultDoesNotContainFile(output, "META-INF/CERT.RSA");
assertResultDoesNotContainFile(output, "META-INF/CERT.SF");
}
示例9: fastSignInfo
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
public static int fastSignInfo(File file) {
int v1 = SIGNED_NOT;
int v2 = SIGNED_NOT;
try {
ZipFile zip = new ZipFile(file);
if (zip.getEntry("META-INF/CERT.RSA") != null) {
v1 = SIGNED_V1;
}
Field archiveField = ZipFile.class.getDeclaredField("archive");
archiveField.setAccessible(true);
final RandomAccessFile archive = (RandomAccessFile) archiveField.get(zip);
Method positionAtCentralDirectory = ZipFile.class.getDeclaredMethod("positionAtCentralDirectory");
positionAtCentralDirectory.setAccessible(true);
positionAtCentralDirectory.invoke(zip);
long centralDirectoryOffset = archive.getFilePointer();
archive.seek(centralDirectoryOffset - 24);
byte[] buffer = new byte[24];
archive.readFully(buffer);
zip.close();
ByteBuffer footer = ByteBuffer.wrap(buffer);
footer.order(ByteOrder.LITTLE_ENDIAN);
if ((footer.getLong(8) == APK_SIG_BLOCK_MAGIC_LO)
&& (footer.getLong(16) == APK_SIG_BLOCK_MAGIC_HI)) {
v2 = SIGNED_V2;
}
} catch (IOException | NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException | NoSuchMethodException | InvocationTargetException ex) {
}
return v1 | v2;
}
示例10: importDatasource
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
@Override
protected void importDatasource(Datasource datasource, List<String> geographyScope, List<String> temporalScope, List<String> datasourceLocation) throws Exception {
SubjectType subjectType = SubjectTypeUtils.getOrCreate(AbstractONSImporter.PROVIDER,
OaImporter.OaType.localAuthority.name(), OaImporter.OaType.localAuthority.datasourceSpec.getDescription());
ExcelUtils excelUtils = new ExcelUtils();
File localFile = downloadUtils.fetchFile(new URL(DATAFILE), getProvider().getLabel(), ".zip");
ZipFile zipFile = new ZipFile(localFile);
for (AttributePrefix attributePrefix : AttributePrefix.values()){
ZipArchiveEntry zipEntry = zipFile.getEntry(bookNames[attributePrefix.ordinal()]);
Workbook workbook = excelUtils.getWorkbook(zipFile.getInputStream(zipEntry));
for (String sheetName : sheetNames) {
RowCellExtractor subjectLabelExtractor = new RowCellExtractor(1, CellType.STRING);
ConstantExtractor timestampExtractor = new ConstantExtractor("2016"); // FIXME: Need to generalise when we update Datasource to be time aware
List<TimedValueExtractor> extractors = new ArrayList<>();
for (String metricName : metricNames) {
ConstantExtractor attributeLabelExtractor = new ConstantExtractor(getAttributeLabel(attributePrefix, sheetName, metricName));
RowCellExtractor valueExtractor;
switch (metricName){
case "Mean":
valueExtractor = new RowCellExtractor(5, CellType.NUMERIC);
break;
case "Median":
valueExtractor = new RowCellExtractor(3, CellType.NUMERIC);
break;
default:
throw new Error("Unknown metric name: " + metricName);
}
extractors.add(new TimedValueExtractor(getProvider(), subjectType, subjectLabelExtractor, attributeLabelExtractor, timestampExtractor, valueExtractor));
}
Sheet sheet = workbook.getSheet(sheetName);
excelUtils.extractAndSaveTimedValues(sheet,this,extractors);
}
}
}
示例11: getEntry
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);
}
}
示例12: detectJar
import org.apache.commons.compress.archivers.zip.ZipFile; //導入方法依賴的package包/類
private static MediaType detectJar(ZipFile zip) {
if (zip.getEntry("META-INF/MANIFEST.MF") != null) {
// It's a Jar file, or something based on Jar
// Is it an Android APK?
if (zip.getEntry("AndroidManifest.xml") != null) {
return MediaType.application("vnd.android.package-archive");
}
// Check for WAR and EAR
if (zip.getEntry("WEB-INF/") != null) {
return MediaType.application("x-tika-java-web-archive");
}
if (zip.getEntry("META-INF/application.xml") != null) {
return MediaType.application("x-tika-java-enterprise-archive");
}
// Looks like a regular Jar Archive
return MediaType.application("java-archive");
} else {
// Some Android APKs miss the default Manifest
if (zip.getEntry("AndroidManifest.xml") != null) {
return MediaType.application("vnd.android.package-archive");
}
return null;
}
}