@@ -52,7 +52,7 @@ public void upload(String source, String dest)
5252 throws IOException {
5353 upload (source , dest , 0 );
5454 }
55-
55+
5656 @ Override
5757 public void upload (String source , String dest , long byteOffset )
5858 throws IOException {
@@ -64,7 +64,7 @@ public void download(String source, String dest)
6464 throws IOException {
6565 download (source , dest , 0 );
6666 }
67-
67+
6868 @ Override
6969 public void download (String source , String dest , long byteOffset )
7070 throws IOException {
@@ -75,7 +75,7 @@ public void download(String source, String dest, long byteOffset)
7575 public void upload (LocalSourceFile localFile , String remotePath ) throws IOException {
7676 upload (localFile , remotePath , 0 );
7777 }
78-
78+
7979 @ Override
8080 public void upload (LocalSourceFile localFile , String remotePath , long byteOffset ) throws IOException {
8181 new Uploader (localFile , remotePath ).upload (getTransferListener (), byteOffset );
@@ -85,7 +85,7 @@ public void upload(LocalSourceFile localFile, String remotePath, long byteOffset
8585 public void download (String source , LocalDestFile dest ) throws IOException {
8686 download (source , dest , 0 );
8787 }
88-
88+
8989 @ Override
9090 public void download (String source , LocalDestFile dest , long byteOffset ) throws IOException {
9191 final PathComponents pathComponents = engine .getPathHelper ().getComponents (source );
@@ -140,12 +140,9 @@ private LocalDestFile downloadDir(final TransferListener listener,
140140 final LocalDestFile local )
141141 throws IOException {
142142 final LocalDestFile adjusted = local .getTargetDirectory (remote .getName ());
143- final RemoteDirectory rd = engine .openDir (remote .getPath ());
144- try {
143+ try (RemoteDirectory rd = engine .openDir (remote .getPath ())) {
145144 for (RemoteResourceInfo rri : rd .scan (getDownloadFilter ()))
146145 download (listener , rri , adjusted .getChild (rri .getName ()), 0 ); // not supporting individual byte offsets for these files
147- } finally {
148- rd .close ();
149146 }
150147 return adjusted ;
151148 }
@@ -156,23 +153,16 @@ private LocalDestFile downloadFile(final StreamCopier.Listener listener,
156153 final long byteOffset )
157154 throws IOException {
158155 final LocalDestFile adjusted = local .getTargetFile (remote .getName ());
159- final RemoteFile rf = engine .open (remote .getPath ());
160- try {
156+ try (RemoteFile rf = engine .open (remote .getPath ())) {
161157 log .debug ("Attempting to download {} with offset={}" , remote .getPath (), byteOffset );
162- final RemoteFile .ReadAheadRemoteFileInputStream rfis = rf .new ReadAheadRemoteFileInputStream (16 , byteOffset );
163- final OutputStream os = adjusted .getOutputStream (byteOffset != 0 );
164- try {
158+ try (RemoteFile .ReadAheadRemoteFileInputStream rfis = rf .new ReadAheadRemoteFileInputStream (16 , byteOffset );
159+ OutputStream os = adjusted .getOutputStream (byteOffset != 0 )) {
165160 new StreamCopier (rfis , os , engine .getLoggerFactory ())
166161 .bufSize (engine .getSubsystem ().getLocalMaxPacketSize ())
167162 .keepFlushing (false )
168163 .listener (listener )
169164 .copy ();
170- } finally {
171- rfis .close ();
172- os .close ();
173165 }
174- } finally {
175- rf .close ();
176166 }
177167 return adjusted ;
178168 }
@@ -266,7 +256,7 @@ private String uploadFile(final StreamCopier.Listener listener,
266256 // Starting at some offset, append
267257 modes = EnumSet .of (OpenMode .WRITE , OpenMode .APPEND );
268258 }
269-
259+
270260 log .debug ("Attempting to upload {} with offset={}" , local .getName (), byteOffset );
271261 rf = engine .open (adjusted , modes );
272262 fis = local .getInputStream ();
0 commit comments