diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/ImageLoader.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/ImageLoader.java
index 5b063ab2e7..376d18316f 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/ImageLoader.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/ImageLoader.java
@@ -143,7 +143,7 @@ void reset() {
*
ERROR_NULL_ARGUMENT - if the stream is null
*
* @exception SWTException
- * - ERROR_IO - if an IO error occurs while reading from the stream
+ * - ERROR_IO - if an IO error occurs while reading the stream
* - ERROR_INVALID_IMAGE - if the image stream contains invalid data
* - ERROR_UNSUPPORTED_FORMAT - if the image stream contains an unrecognized format
*
@@ -168,25 +168,17 @@ public ImageData[] load(InputStream stream) {
* ERROR_NULL_ARGUMENT - if the file name is null
*
* @exception SWTException
- * - ERROR_IO - if an IO error occurs while reading from the file
+ * - ERROR_IO - if an IO error occurs while reading the file
* - ERROR_INVALID_IMAGE - if the image file contains invalid data
* - ERROR_UNSUPPORTED_FORMAT - if the image file contains an unrecognized format
*
*/
public ImageData[] load(String filename) {
if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- InputStream stream = null;
- try {
- stream = new FileInputStream(filename);
+ try (InputStream stream = new FileInputStream(filename)) {
return load(stream);
} catch (IOException e) {
SWT.error(SWT.ERROR_IO, e);
- } finally {
- try {
- if (stream != null) stream.close();
- } catch (IOException e) {
- // Ignore error
- }
}
return null;
}
@@ -258,17 +250,11 @@ public void save(OutputStream stream, int format) {
*/
public void save(String filename, int format) {
if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- OutputStream stream = null;
- try {
- stream = new FileOutputStream(filename);
+ try (OutputStream stream = new FileOutputStream(filename)) {
+ save(stream, format);
} catch (IOException e) {
SWT.error(SWT.ERROR_IO, e);
}
- save(stream, format);
- try {
- stream.close();
- } catch (IOException e) {
- }
}
/**
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/ImageLoader.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/ImageLoader.java
index 4fbda1029d..67336de12b 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/ImageLoader.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/ImageLoader.java
@@ -153,7 +153,7 @@ void reset() {
* ERROR_NULL_ARGUMENT - if the stream is null
*
* @exception SWTException
- * - ERROR_IO - if an IO error occurs while reading from the stream
+ * - ERROR_IO - if an IO error occurs while reading the stream
* - ERROR_INVALID_IMAGE - if the image stream contains invalid data
* - ERROR_UNSUPPORTED_FORMAT - if the image stream contains an unrecognized format
*
@@ -284,25 +284,17 @@ boolean isInterlacedPNG(byte [] imageAsByteArray) {
* ERROR_NULL_ARGUMENT - if the file name is null
*
* @exception SWTException
- * - ERROR_IO - if an IO error occurs while reading from the file
+ * - ERROR_IO - if an IO error occurs while reading the file
* - ERROR_INVALID_IMAGE - if the image file contains invalid data
* - ERROR_UNSUPPORTED_FORMAT - if the image file contains an unrecognized format
*
*/
public ImageData[] load(String filename) {
if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- InputStream stream = null;
- try {
- stream = new FileInputStream(filename);
+ try (InputStream stream = new FileInputStream(filename)) {
return load(stream);
} catch (IOException e) {
SWT.error(SWT.ERROR_IO, e);
- } finally {
- try {
- if (stream != null) stream.close();
- } catch (IOException e) {
- // Ignore error
- }
}
return null;
}
@@ -611,17 +603,11 @@ public void save(OutputStream stream, int format) {
*/
public void save(String filename, int format) {
if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- OutputStream stream = null;
- try {
- stream = new FileOutputStream(filename);
+ try (OutputStream stream = new FileOutputStream(filename)) {
+ save(stream, format);
} catch (IOException e) {
SWT.error(SWT.ERROR_IO, e);
}
- save(stream, format);
- try {
- stream.close();
- } catch (IOException e) {
- }
}
/**
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/ImageLoader.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/ImageLoader.java
index a8e4c2f684..da78f52d24 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/ImageLoader.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/ImageLoader.java
@@ -143,7 +143,7 @@ void reset() {
* ERROR_NULL_ARGUMENT - if the stream is null
*
* @exception SWTException
- * - ERROR_IO - if an IO error occurs while reading from the stream
+ * - ERROR_IO - if an IO error occurs while reading the stream
* - ERROR_INVALID_IMAGE - if the image stream contains invalid data
* - ERROR_UNSUPPORTED_FORMAT - if the image stream contains an unrecognized format
*
@@ -168,7 +168,7 @@ public ImageData[] load(InputStream stream) {
* ERROR_NULL_ARGUMENT - if the file name is null
*
* @exception SWTException
- * - ERROR_IO - if an IO error occurs while reading from the file
+ * - ERROR_IO - if an IO error occurs while reading the file
* - ERROR_INVALID_IMAGE - if the image file contains invalid data
* - ERROR_UNSUPPORTED_FORMAT - if the image file contains an unrecognized format
*