Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarsten Hammer2019-05-21 18:57:56 +0000
committerAlexander Kurtakov2019-06-11 08:34:59 +0000
commit1a00f4db72c9202c75f502b152e10d36319440da (patch)
tree9bf72d7705639ba239cd2b3e503a4a09273539f0 /bundles/org.eclipse.equinox.p2.publisher.eclipse
parent57f73a80ecd119d590f7f5158b44858393031084 (diff)
downloadrt.equinox.p2-1a00f4db72c9202c75f502b152e10d36319440da.tar.gz
rt.equinox.p2-1a00f4db72c9202c75f502b152e10d36319440da.tar.xz
rt.equinox.p2-1a00f4db72c9202c75f502b152e10d36319440da.zip
Use try-with-resources
Convert try finally block to try-with-resources Change-Id: I1b6632068bb6fbb4934cf25d040e4b2ae22749a5 Signed-off-by: Carsten Hammer <carsten.hammer@t-online.de>
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.publisher.eclipse')
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher.eclipse/META-INF/MANIFEST.MF2
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher.eclipse/pom.xml2
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher.eclipse/src/org/eclipse/pde/internal/swt/tools/IconExe.java75
3 files changed, 41 insertions, 38 deletions
diff --git a/bundles/org.eclipse.equinox.p2.publisher.eclipse/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.publisher.eclipse/META-INF/MANIFEST.MF
index 8a6048c33..dd9eec45c 100644
--- a/bundles/org.eclipse.equinox.p2.publisher.eclipse/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.publisher.eclipse/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %bundleName
Bundle-SymbolicName: org.eclipse.equinox.p2.publisher.eclipse;singleton:=true
-Bundle-Version: 1.3.200.qualifier
+Bundle-Version: 1.3.300.qualifier
Bundle-Activator: org.eclipse.pde.internal.publishing.Activator
Bundle-ActivationPolicy: lazy
Bundle-Vendor: %providerName
diff --git a/bundles/org.eclipse.equinox.p2.publisher.eclipse/pom.xml b/bundles/org.eclipse.equinox.p2.publisher.eclipse/pom.xml
index 12f016ade..ff9d57186 100644
--- a/bundles/org.eclipse.equinox.p2.publisher.eclipse/pom.xml
+++ b/bundles/org.eclipse.equinox.p2.publisher.eclipse/pom.xml
@@ -10,6 +10,6 @@
<groupId>org.eclipse.equinox</groupId>
<artifactId>org.eclipse.equinox.p2.publisher.eclipse</artifactId>
- <version>1.3.200-SNAPSHOT</version>
+ <version>1.3.300-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/bundles/org.eclipse.equinox.p2.publisher.eclipse/src/org/eclipse/pde/internal/swt/tools/IconExe.java b/bundles/org.eclipse.equinox.p2.publisher.eclipse/src/org/eclipse/pde/internal/swt/tools/IconExe.java
index a93034d3a..052aa07c4 100644
--- a/bundles/org.eclipse.equinox.p2.publisher.eclipse/src/org/eclipse/pde/internal/swt/tools/IconExe.java
+++ b/bundles/org.eclipse.equinox.p2.publisher.eclipse/src/org/eclipse/pde/internal/swt/tools/IconExe.java
@@ -125,13 +125,15 @@ public class IconExe {
* @param program the Windows executable e.g c:/eclipse/eclipse.exe
*/
static ImageData[] loadIcons(String program) throws FileNotFoundException, IOException {
- RandomAccessFile raf = new RandomAccessFile(program, "r"); //$NON-NLS-1$
- IconExe iconExe = new IconExe();
- IconResInfo[] iconInfo = iconExe.getIcons(raf);
- ImageData[] data = new ImageData[iconInfo.length];
- for (int i = 0; i < data.length; i++)
- data[i] = iconInfo[i].data;
- raf.close();
+ ImageData[] data;
+ try (RandomAccessFile raf = new RandomAccessFile(program, "r") //$NON-NLS-1$
+ ) {
+ IconExe iconExe = new IconExe();
+ IconResInfo[] iconInfo = iconExe.getIcons(raf);
+ data = new ImageData[iconInfo.length];
+ for (int i = 0; i < data.length; i++)
+ data[i] = iconInfo[i].data;
+ }
return data;
}
@@ -176,31 +178,33 @@ public class IconExe {
* @return the list of icons from the original program that were not successfully replaced (empty if success)
*/
static List<IconResInfo> unloadIcons(String program, ImageData[] icons) throws FileNotFoundException, IOException {
- RandomAccessFile raf = new RandomAccessFile(program, "rw"); //$NON-NLS-1$
- IconExe iconExe = new IconExe();
- List<IconResInfo> iconInfo = new ArrayList<>(Arrays.asList(iconExe.getIcons(raf)));
- // Display an error if no icons found in target executable.
- if (iconInfo.isEmpty()) {
- System.err.println("Warning - no icons detected in \"" + program + "\"."); //$NON-NLS-1$ //$NON-NLS-2$
- raf.close();
- return Collections.emptyList();
- }
- Iterator<IconResInfo> originalIconsIterator = iconInfo.iterator();
- while (originalIconsIterator.hasNext()) {
- IconResInfo iconToReplace = originalIconsIterator.next();
- for (ImageData iconToWrite : Arrays.asList(icons)) {
- if (iconToWrite == null)
- continue;
-
- if (iconToReplace.data.width == iconToWrite.width && iconToReplace.data.height == iconToWrite.height && iconToReplace.data.depth == iconToWrite.depth) {
- raf.seek(iconToReplace.offset);
- unloadIcon(raf, iconToWrite);
- originalIconsIterator.remove();
- break;
+ List<IconResInfo> iconInfo;
+ try (RandomAccessFile raf = new RandomAccessFile(program, "rw") //$NON-NLS-1$
+ ) {
+ IconExe iconExe = new IconExe();
+ iconInfo = new ArrayList<>(Arrays.asList(iconExe.getIcons(raf)));
+ // Display an error if no icons found in target executable.
+ if (iconInfo.isEmpty()) {
+ System.err.println("Warning - no icons detected in \"" + program + "\"."); //$NON-NLS-1$ //$NON-NLS-2$
+ raf.close();
+ return Collections.emptyList();
+ }
+ Iterator<IconResInfo> originalIconsIterator = iconInfo.iterator();
+ while (originalIconsIterator.hasNext()) {
+ IconResInfo iconToReplace = originalIconsIterator.next();
+ for (ImageData iconToWrite : Arrays.asList(icons)) {
+ if (iconToWrite == null)
+ continue;
+
+ if (iconToReplace.data.width == iconToWrite.width && iconToReplace.data.height == iconToWrite.height && iconToReplace.data.depth == iconToWrite.depth) {
+ raf.seek(iconToReplace.offset);
+ unloadIcon(raf, iconToWrite);
+ originalIconsIterator.remove();
+ break;
+ }
}
}
}
- raf.close();
return iconInfo;
}
@@ -516,13 +520,12 @@ public class IconExe {
static void copyFile(String src, String dst) throws FileNotFoundException, IOException {
File srcFile = new File(src);
File dstFile = new File(dst);
- InputStream in = new BufferedInputStream(new FileInputStream(srcFile));
- OutputStream out = new BufferedOutputStream(new FileOutputStream(dstFile));
- int c;
- while ((c = in.read()) != -1)
- out.write(c);
- in.close();
- out.close();
+ try (InputStream in = new BufferedInputStream(new FileInputStream(srcFile));
+ OutputStream out = new BufferedOutputStream(new FileOutputStream(dstFile))) {
+ int c;
+ while ((c = in.read()) != -1)
+ out.write(c);
+ }
}
/* IO utilities to parse Windows executable */

Back to the top