當前位置: 首頁>>代碼示例>>Java>>正文


Java ZipFile.getEntry方法代碼示例

本文整理匯總了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();
  }
}
 
開發者ID:NitorCreations,項目名稱:javaxdelta,代碼行數:28,代碼來源:JarDeltaJarPatcherTest.java

示例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));
  }
}
 
開發者ID:NitorCreations,項目名稱:javaxdelta,代碼行數:30,代碼來源:JarDeltaJarPatcherTest.java

示例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));
}
 
開發者ID:NitorCreations,項目名稱:javaxdelta,代碼行數:24,代碼來源:JarDeltaJarPatcherTest.java

示例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");
	}
}
 
開發者ID:nate-rcl,項目名稱:irplus,代碼行數:28,代碼來源:DefaultCollectionImportService.java

示例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");
		}
	}
}
 
開發者ID:nate-rcl,項目名稱:irplus,代碼行數:31,代碼來源:DefaultCollectionImportService.java

示例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;
    }
}
 
開發者ID:kolbasa,項目名稱:OCRaptor,代碼行數:23,代碼來源:ZipContainerDetector.java

示例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;
    }
}
 
開發者ID:kolbasa,項目名稱:OCRaptor,代碼行數:19,代碼來源:ZipContainerDetector.java

示例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");
}
 
開發者ID:selendroid,項目名稱:selendroid,代碼行數:22,代碼來源:SelendroidServerBuilderTest.java

示例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;
}
 
開發者ID:NBANDROIDTEAM,項目名稱:NBANDROID-V2,代碼行數:31,代碼來源:ApkUtils.java

示例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);
        }
    }
}
 
開發者ID:FutureCitiesCatapult,項目名稱:TomboloDigitalConnector,代碼行數:40,代碼來源:ONSWagesImporter.java

示例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);
  }
}
 
開發者ID:NitorCreations,項目名稱:javaxdelta,代碼行數:20,代碼來源:JarPatcher.java

示例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;
   }
}
 
開發者ID:kolbasa,項目名稱:OCRaptor,代碼行數:29,代碼來源:ZipContainerDetector.java


注:本文中的org.apache.commons.compress.archivers.zip.ZipFile.getEntry方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。