diff options
author | 2018-08-14 19:56:23 +0000 | |
---|---|---|
committer | 2018-08-14 19:56:23 +0000 | |
commit | d25fc43a67643f95a09ce347b3a4d4b551e51f94 (patch) | |
tree | 4930260b8e6fd4cedd744193f8b0c6f0d4b30329 /ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/util/jar/ExtractJar.java | |
parent | 9ddac93ed79931d674d1b877661a0f7611d3a7d9 (diff) | |
parent | 4ffef33d70eb172fb594e8b50eabaf2b59d7f936 (diff) |
Merge "Fix use try-with-resources issues"
Diffstat (limited to 'ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/util/jar/ExtractJar.java')
-rw-r--r-- | ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/util/jar/ExtractJar.java | 73 |
1 files changed, 37 insertions, 36 deletions
diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/util/jar/ExtractJar.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/util/jar/ExtractJar.java index 12355573..b5390c92 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/util/jar/ExtractJar.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/util/jar/ExtractJar.java @@ -73,17 +73,18 @@ public class ExtractJar { * @throws Exception */ public static void readJar(File jarFile) throws Exception { - JarInputStream in = new JarInputStream(new FileInputStream(jarFile)); - JarEntry je; - while ((je = in.getNextJarEntry()) != null) { - if (je.isDirectory() == false) { - if (je.getName().startsWith("org/onap/portalsdk/analytics/config/")) { - System.out.println(je.getName() + " " + je.getTime()); - + try(JarInputStream in = new JarInputStream(new FileInputStream(jarFile))) + { + JarEntry je; + while ((je = in.getNextJarEntry()) != null) { + if (je.isDirectory() == false) { + if (je.getName().startsWith("org/onap/portalsdk/analytics/config/")) { + System.out.println(je.getName() + " " + je.getTime()); + + } } } } - in.close(); } /** @@ -95,37 +96,37 @@ public class ExtractJar { Class clazz = ExtractJar.class; URL jarUrl = clazz.getProtectionDomain().getCodeSource().getLocation(); - JarInputStream entryStream = new JarInputStream(jarUrl.openStream()); - JarEntry entry; - - while (true) { - entry = entryStream.getNextJarEntry(); - if (entry == null) - break; - if (entry.getName().indexOf("jarutil") < 0) { - System.out.println(entry.getName()); - File file = new File(directory, entry.getName()); - if (entry.isDirectory()) { - if (!file.exists()) - file.mkdirs(); - } else { - File dir = new File(file.getParent()); - if (!dir.exists()) - dir.mkdirs(); - if (file.exists()) - file.delete(); - FileOutputStream fout = new FileOutputStream(file); - copy(entryStream, fout); - fout.close(); - - if (entry.getTime() >= 0) - file.setLastModified(entry.getTime()); + try(JarInputStream entryStream = new JarInputStream(jarUrl.openStream())){ + JarEntry entry; + + while (true) { + entry = entryStream.getNextJarEntry(); + if (entry == null) + break; + if (entry.getName().indexOf("jarutil") < 0) { + System.out.println(entry.getName()); + File file = new File(directory, entry.getName()); + if (entry.isDirectory()) { + if (!file.exists()) + file.mkdirs(); + } else { + File dir = new File(file.getParent()); + if (!dir.exists()) + dir.mkdirs(); + if (file.exists()) + file.delete(); + try(FileOutputStream fout = new FileOutputStream(file)){ + copy(entryStream, fout); + } + + if (entry.getTime() >= 0) + file.setLastModified(entry.getTime()); + } + } - + entryStream.closeEntry(); } - entryStream.closeEntry(); } - entryStream.close(); System.out.println("/WEB-INF/classes/org/onap/portalsdk/analytics"); System.out.println("Delete .... "); |