karlpauls commented on a change in pull request #14: Zip file extract
URL:
https://github.com/apache/sling-org-apache-sling-feature-analyser/pull/14#discussion_r291049316
##########
File path:
src/main/java/org/apache/sling/feature/scanner/impl/ContentPackageScanner.java
##########
@@ -82,117 +83,120 @@ private void extractContentPackage(final
ContentPackageDescriptor cp,
toDir.mkdirs();
final List<File> toProcess = new ArrayList<>();
-
- try (final ZipInputStream zis = new ZipInputStream(new
FileInputStream(archive)) ) {
- boolean done = false;
- while ( !done ) {
- final ZipEntry entry = zis.getNextEntry();
- if ( entry == null ) {
- done = true;
- } else {
- final String entryName = entry.getName();
- if ( !entryName.endsWith("/") &&
entryName.startsWith("jcr_root/") ) {
- final String contentPath = entryName.substring(8);
-
- FileType fileType = null;
-
- if ( entryName.endsWith(".zip") ) {
- // embedded content package
- fileType = FileType.PACKAGE;
-
- // check for libs or apps
- } else if ( entryName.startsWith("jcr_root/libs/")
|| entryName.startsWith("jcr_root/apps/") ) {
-
- // check if this is an install folder (I)
- // install folders are either named:
- // "install" or
- // "install.{runmode}"
- boolean isInstall =
entryName.indexOf("/install/") != -1;
+
+ ZipFile zipFile = null;
+ try {
+ zipFile = new ZipFile(archive);
+ Enumeration<? extends ZipEntry> entries = zipFile.entries();
+
+ while( entries.hasMoreElements() ) {
+ final ZipEntry entry = entries.nextElement();
+ final String entryName = entry.getName();
+ logger.debug("Content package entry {}", entryName);
+ final InputStream zis = zipFile.getInputStream(entry);
Review comment:
Why are you creating the stream at this point (it looks like you only need
it if the below if clause matches)?
Furthermore, it looks like you don't close the stream. Wouldn't it be better
to open it only inside the below if and then in a try (InputStream)?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services