File tree Expand file tree Collapse file tree 2 files changed +6
-34
lines changed
bundles/org.eclipse.swt/Eclipse SWT
cocoa/org/eclipse/swt/graphics
gtk/org/eclipse/swt/graphics Expand file tree Collapse file tree 2 files changed +6
-34
lines changed Original file line number Diff line number Diff line change @@ -175,18 +175,10 @@ public ImageData[] load(InputStream stream) {
175175 */
176176public ImageData [] load (String filename ) {
177177 if (filename == null ) SWT .error (SWT .ERROR_NULL_ARGUMENT );
178- InputStream stream = null ;
179- try {
180- stream = new FileInputStream (filename );
178+ try (InputStream stream = new FileInputStream (filename )) {
181179 return load (stream );
182180 } catch (IOException e ) {
183181 SWT .error (SWT .ERROR_IO , e );
184- } finally {
185- try {
186- if (stream != null ) stream .close ();
187- } catch (IOException e ) {
188- // Ignore error
189- }
190182 }
191183 return null ;
192184}
@@ -258,17 +250,11 @@ public void save(OutputStream stream, int format) {
258250 */
259251public void save (String filename , int format ) {
260252 if (filename == null ) SWT .error (SWT .ERROR_NULL_ARGUMENT );
261- OutputStream stream = null ;
262- try {
263- stream = new FileOutputStream (filename );
253+ try (OutputStream stream = new FileOutputStream (filename )) {
254+ save (stream , format );
264255 } catch (IOException e ) {
265256 SWT .error (SWT .ERROR_IO , e );
266257 }
267- save (stream , format );
268- try {
269- stream .close ();
270- } catch (IOException e ) {
271- }
272258}
273259
274260/**
Original file line number Diff line number Diff line change @@ -291,18 +291,10 @@ boolean isInterlacedPNG(byte [] imageAsByteArray) {
291291 */
292292public ImageData [] load (String filename ) {
293293 if (filename == null ) SWT .error (SWT .ERROR_NULL_ARGUMENT );
294- InputStream stream = null ;
295- try {
296- stream = new FileInputStream (filename );
294+ try (InputStream stream = new FileInputStream (filename )) {
297295 return load (stream );
298296 } catch (IOException e ) {
299297 SWT .error (SWT .ERROR_IO , e );
300- } finally {
301- try {
302- if (stream != null ) stream .close ();
303- } catch (IOException e ) {
304- // Ignore error
305- }
306298 }
307299 return null ;
308300}
@@ -611,17 +603,11 @@ public void save(OutputStream stream, int format) {
611603 */
612604public void save (String filename , int format ) {
613605 if (filename == null ) SWT .error (SWT .ERROR_NULL_ARGUMENT );
614- OutputStream stream = null ;
615- try {
616- stream = new FileOutputStream (filename );
606+ try (OutputStream stream = new FileOutputStream (filename )) {
607+ save (stream , format );
617608 } catch (IOException e ) {
618609 SWT .error (SWT .ERROR_IO , e );
619610 }
620- save (stream , format );
621- try {
622- stream .close ();
623- } catch (IOException e ) {
624- }
625611}
626612
627613/**
You can’t perform that action at this time.
0 commit comments