14
14
*******************************************************************************/
15
15
package org .eclipse .core .filesystem .provider ;
16
16
17
- import java .io .*;
17
+ import java .io .IOException ;
18
+ import java .io .InputStream ;
19
+ import java .io .OutputStream ;
18
20
import java .net .URI ;
19
- import org .eclipse .core .filesystem .*;
20
- import org .eclipse .core .internal .filesystem .*;
21
- import org .eclipse .core .runtime .*;
21
+ import org .eclipse .core .filesystem .EFS ;
22
+ import org .eclipse .core .filesystem .IFileInfo ;
23
+ import org .eclipse .core .filesystem .IFileStore ;
24
+ import org .eclipse .core .filesystem .IFileSystem ;
25
+ import org .eclipse .core .internal .filesystem .FileCache ;
26
+ import org .eclipse .core .internal .filesystem .Messages ;
27
+ import org .eclipse .core .internal .filesystem .Policy ;
28
+ import org .eclipse .core .runtime .CoreException ;
29
+ import org .eclipse .core .runtime .IPath ;
30
+ import org .eclipse .core .runtime .IProgressMonitor ;
31
+ import org .eclipse .core .runtime .PlatformObject ;
32
+ import org .eclipse .core .runtime .SubMonitor ;
22
33
import org .eclipse .osgi .util .NLS ;
23
34
24
35
/**
@@ -57,7 +68,7 @@ public abstract class FileStore extends PlatformObject implements IFileStore {
57
68
private static final void transferStreams (InputStream source , OutputStream destination , long length , String path , IProgressMonitor monitor ) throws CoreException {
58
69
byte [] buffer = new byte [8192 ];
59
70
SubMonitor subMonitor = SubMonitor .convert (monitor , length >= 0 ? 1 + (int ) (length / buffer .length ) : 1000 );
60
- try {
71
+ try ( source ; destination ) {
61
72
while (true ) {
62
73
int bytesRead = -1 ;
63
74
try {
@@ -78,9 +89,7 @@ private static final void transferStreams(InputStream source, OutputStream desti
78
89
}
79
90
subMonitor .worked (1 );
80
91
}
81
- } finally {
82
- Policy .safeClose (source );
83
- Policy .safeClose (destination );
92
+ } catch (IOException e ) { // ignore
84
93
}
85
94
}
86
95
@@ -193,16 +202,13 @@ protected void copyFile(IFileInfo sourceInfo, IFileStore destination, int option
193
202
long length = sourceInfo .getLength ();
194
203
String sourcePath = toString ();
195
204
SubMonitor subMonitor = SubMonitor .convert (monitor , NLS .bind (Messages .copying , sourcePath ), 100 );
196
- InputStream in = null ;
197
- OutputStream out = null ;
198
- try {
199
- in = openInputStream (EFS .NONE , subMonitor .newChild (1 ));
200
- out = destination .openOutputStream (EFS .NONE , subMonitor .newChild (1 ));
205
+ try (InputStream in = openInputStream (EFS .NONE , subMonitor .newChild (1 )); //
206
+ OutputStream out = destination .openOutputStream (EFS .NONE , subMonitor .newChild (1 ));) {
201
207
transferStreams (in , out , length , sourcePath , subMonitor .newChild (98 ));
202
208
transferAttributes (sourceInfo , destination );
209
+ } catch (IOException e ) {
210
+ // ignore
203
211
} catch (CoreException e ) {
204
- Policy .safeClose (in );
205
- Policy .safeClose (out );
206
212
//if we failed to write, try to cleanup the half written file
207
213
if (!destination .fetchInfo (0 , null ).exists ())
208
214
destination .delete (EFS .NONE , null );
0 commit comments