File tree Expand file tree Collapse file tree
src/main/java/org/aarboard/nextcloud/api/webdav Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -164,34 +164,22 @@ public boolean downloadFile(String remotePath, String downloadDirPath) throws IO
164164 String filename = segments [segments .length - 1 ];
165165 downloadDirPath = downloadDirPath + "/" + filename ;
166166 }
167- InputStream in = null ;
168- try
169- {
170- in = sardine .get (path );
171- byte [] buffer = new byte [AWebdavHandler .FILE_BUFFER_SIZE ];
172- int bytesRead ;
173- File targetFile = new File (downloadDirPath );
174- try (OutputStream outStream = new FileOutputStream (targetFile ))
175- {
176- while ((bytesRead = in .read (buffer )) != -1 )
177- {
178- outStream .write (buffer , 0 , bytesRead );
179- }
180- outStream .flush ();
181- outStream .close ();
182- }
183- status = true ;
184- } catch (IOException e )
185- {
186- throw new NextcloudApiException (e );
187- } finally
188- {
189- sardine .shutdown ();
190- if (in != null )
191- {
192- in .close ();
193- }
167+ try (InputStream in = sardine .get (path )) {
168+ byte [] buffer = new byte [AWebdavHandler .FILE_BUFFER_SIZE ];
169+ int bytesRead ;
170+ File targetFile = new File (downloadDirPath );
171+ try (OutputStream outStream = java .nio .file .Files .newOutputStream (targetFile .toPath ())) {
172+ while ((bytesRead = in .read (buffer )) != -1 ) {
173+ outStream .write (buffer , 0 , bytesRead );
174+ }
175+ outStream .flush ();
194176 }
177+ status = true ;
178+ } catch (IOException e ) {
179+ throw new NextcloudApiException (e );
180+ } finally {
181+ sardine .shutdown ();
182+ }
195183 return status ;
196184 }
197185
You can’t perform that action at this time.
0 commit comments