Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulian Honnen2019-02-11 16:09:26 +0000
committerAlexander Kurtakov2019-02-11 17:33:48 +0000
commit924b1a8a0b000cc9293a7aa22ec599bf3df46cd7 (patch)
tree4a768f76e283856eb52d74fc01a7364f404e1ffe
parent9ec538f7d3d570d009d4ef5959aad02ea24e902d (diff)
downloadrt.equinox.framework-924b1a8a0b000cc9293a7aa22ec599bf3df46cd7.tar.gz
rt.equinox.framework-924b1a8a0b000cc9293a7aa22ec599bf3df46cd7.tar.xz
rt.equinox.framework-924b1a8a0b000cc9293a7aa22ec599bf3df46cd7.zip
Bug 544265 - Use try-with-resources in org.eclipse.equinox.launcher.Main
Change-Id: Idd90f73819ba84aa8ca65e5d6a453dcc02052673 Signed-off-by: Julian Honnen <julian.honnen@vector.com>
-rw-r--r--bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java79
1 files changed, 10 insertions, 69 deletions
diff --git a/bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java b/bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java
index 43c6d266c..adf7373af 100644
--- a/bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java
+++ b/bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java
@@ -23,6 +23,8 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.*;
import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.security.*;
import java.util.*;
import java.util.zip.ZipEntry;
@@ -2090,17 +2092,8 @@ public class Main {
// try to load saved configuration file
Properties props = new Properties();
- InputStream is = null;
- try {
- is = getStream(url);
+ try (InputStream is = getStream(url)) {
props.load(is);
- } finally {
- if (is != null)
- try {
- is.close();
- } catch (IOException e) {
- //ignore failure to close
- }
}
return props;
}
@@ -2277,44 +2270,6 @@ public class Main {
return null;
}
- /**
- * Transfers all available bytes from the given input stream to the given output stream.
- * Regardless of failure, this method closes both streams.
- */
- private static void transferStreams(InputStream source, OutputStream destination) {
- byte[] buffer = new byte[8096];
- try {
- while (true) {
- int bytesRead = -1;
- try {
- bytesRead = source.read(buffer);
- } catch (IOException e) {
- return;
- }
- if (bytesRead == -1)
- break;
- try {
- destination.write(buffer, 0, bytesRead);
- } catch (IOException e) {
- return;
- }
- }
- } finally {
- try {
- source.close();
- } catch (IOException e) {
- // ignore
- } finally {
- //close destination in finally in case source.close fails
- try {
- destination.close();
- } catch (IOException e) {
- // ignore
- }
- }
- }
- }
-
/*
* Look for the specified spash file in the given JAR and extract it to the config
* area for caching purposes.
@@ -2356,32 +2311,18 @@ public class Main {
ZipEntry entry = file.getEntry(jarEntry.replace(File.separatorChar, '/'));
if (entry == null)
return null;
- InputStream input = null;
- try {
- input = file.getInputStream(entry);
+
+ Path outputFile = splash.toPath();
+ Files.createDirectories(outputFile.getParent());
+
+ try (InputStream input = file.getInputStream(entry)) {
+ Files.copy(input, outputFile);
} catch (IOException e) {
log("Exception opening splash: " + entry.getName() + " in JAR file: " + jarPath); //$NON-NLS-1$ //$NON-NLS-2$
log(e);
return null;
}
- new File(splash.getParent()).mkdirs();
- OutputStream output;
- try {
- output = new BufferedOutputStream(new FileOutputStream(splash));
- } catch (FileNotFoundException e) {
- try {
- input.close();
- } catch (IOException e1) {
- // ignore
- }
- return null;
- }
- transferStreams(input, output);
- try {
- file.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
+
return splash.exists() ? splash.getAbsolutePath() : null;
} catch (IOException e) {
log("Exception looking for " + jarEntry + " in JAR file: " + jarPath); //$NON-NLS-1$ //$NON-NLS-2$

Back to the top