summaryrefslogtreecommitdiff
path: root/src/main/org/apache/tools/ant/types/ZipScanner.java
diff options
context:
space:
mode:
authorMatt Benson <mbenson@apache.org>2017-04-13 10:15:22 -0500
committerMatt Benson <mbenson@apache.org>2017-04-13 10:15:22 -0500
commitb7d1e9bde44cb8e5233d6e70bb96e14cbb2f3e2d (patch)
treeee39db3a46b9da337a5f6424a74e578177a8d266 /src/main/org/apache/tools/ant/types/ZipScanner.java
parentaf74d1f6b882cef5f4167d972638ad886d12d58c (diff)
downloadant-b7d1e9bde44cb8e5233d6e70bb96e14cbb2f3e2d.tar.gz
java 5-8java8
Diffstat (limited to 'src/main/org/apache/tools/ant/types/ZipScanner.java')
-rw-r--r--src/main/org/apache/tools/ant/types/ZipScanner.java31
1 files changed, 11 insertions, 20 deletions
diff --git a/src/main/org/apache/tools/ant/types/ZipScanner.java b/src/main/org/apache/tools/ant/types/ZipScanner.java
index 05392226a..49f66ebd9 100644
--- a/src/main/org/apache/tools/ant/types/ZipScanner.java
+++ b/src/main/org/apache/tools/ant/types/ZipScanner.java
@@ -52,31 +52,20 @@ public class ZipScanner extends ArchiveScanner {
* resources found inside the archive that matched all include
* patterns and didn't match any exclude patterns.
*/
+ @Override
protected void fillMapsFromArchive(Resource src, String encoding,
Map<String, Resource> fileEntries, Map<String, Resource> matchFileEntries,
Map<String, Resource> dirEntries, Map<String, Resource> matchDirEntries) {
- ZipEntry entry = null;
- ZipFile zf = null;
- File srcFile = null;
- FileProvider fp = src.as(FileProvider.class);
- if (fp != null) {
- srcFile = fp.getFile();
- } else {
- throw new BuildException("Only file provider resources are supported");
- }
+ File srcFile = src.asOptional(FileProvider.class)
+ .map(FileProvider::getFile).orElseThrow(() -> new BuildException(
+ "Only file provider resources are supported"));
+
+ try (ZipFile zf = new ZipFile(srcFile, encoding)) {
- try {
- try {
- zf = new ZipFile(srcFile, encoding);
- } catch (ZipException ex) {
- throw new BuildException("Problem reading " + srcFile, ex);
- } catch (IOException ex) {
- throw new BuildException("Problem opening " + srcFile, ex);
- }
Enumeration<ZipEntry> e = zf.getEntries();
while (e.hasMoreElements()) {
- entry = e.nextElement();
+ ZipEntry entry = e.nextElement();
Resource r = new ZipResource(srcFile, encoding, entry);
String name = entry.getName();
if (entry.isDirectory()) {
@@ -92,8 +81,10 @@ public class ZipScanner extends ArchiveScanner {
}
}
}
- } finally {
- ZipFile.closeQuietly(zf);
+ } catch (ZipException ex) {
+ throw new BuildException("Problem reading " + srcFile, ex);
+ } catch (IOException ex) {
+ throw new BuildException("Problem opening " + srcFile, ex);
}
}
} \ No newline at end of file