@@ -128,8 +128,6 @@ protected ResultCode doInBackground(Object[] params) {
128128
129129 ResultCode result = ResultCode .UNKNOWN_ERROR ;
130130
131- InputStream inputStream = null ;
132- FileOutputStream outputStream = null ;
133131 String fullTempPath = null ;
134132 Uri currentUri = null ;
135133
@@ -148,19 +146,20 @@ protected ResultCode doInBackground(Object[] params) {
148146 currentRemotePath = uploadPath + UriUtils .getDisplayNameForUri (currentUri , mAppContext );
149147
150148 fullTempPath = FileStorageUtils .getTemporalPath (account .name , spaceId ) + currentRemotePath ;
151- inputStream = leakedContentResolver .openInputStream (currentUri );
152149 File cacheFile = new File (fullTempPath );
153150 File tempDir = cacheFile .getParentFile ();
154151 if (!tempDir .exists ()) {
155152 tempDir .mkdirs ();
156153 }
157154 cacheFile .createNewFile ();
158- outputStream = new FileOutputStream (fullTempPath );
159- byte [] buffer = new byte [4096 ];
160155
161- int count ;
162- while ((count = inputStream .read (buffer )) > 0 ) {
163- outputStream .write (buffer , 0 , count );
156+ try (InputStream inputStream = leakedContentResolver .openInputStream (currentUri );
157+ FileOutputStream outputStream = new FileOutputStream (fullTempPath )) {
158+ byte [] buffer = new byte [4096 ];
159+ int count ;
160+ while ((count = inputStream .read (buffer )) > 0 ) {
161+ outputStream .write (buffer , 0 , count );
162+ }
164163 }
165164
166165 filesToUpload .add (fullTempPath );
@@ -208,22 +207,6 @@ protected ResultCode doInBackground(Object[] params) {
208207 }
209208 }
210209
211- } finally {
212- if (inputStream != null ) {
213- try {
214- inputStream .close ();
215- } catch (Exception e ) {
216- Timber .w ("Ignoring exception of inputStream closure" );
217- }
218- }
219-
220- if (outputStream != null ) {
221- try {
222- outputStream .close ();
223- } catch (Exception e ) {
224- Timber .w ("Ignoring exception of outStream closure" );
225- }
226- }
227210 }
228211
229212 return result ;
0 commit comments