@@ -55,6 +55,7 @@ public enum Status {
55
55
private static final Pattern ARCHIVES_PATH_PATTERN = Pattern .compile (".+/archives/(.+)" );
56
56
private static final Pattern SHARED_PUBLIC_READ_PATTERN = Pattern .compile ("shared-public-read/onboarding/(.+)" );
57
57
private static final Pattern SCREENSHOT_PATH_PATTERN = Pattern .compile (".+/screenshots/(.+)" );
58
+
58
59
private Type type ;
59
60
private String id ;
60
61
private Status status ;
@@ -295,31 +296,14 @@ public TransferObserver upload(Context context, User user, Callback<Exception, A
295
296
);
296
297
}
297
298
298
- public InputStream downloadAsInputStream (Context context , User user ) throws FileNotFoundException {
299
- if (status .equals (Status .SYNCHRONIZED ) || status .equals (Status .UPLOAD_REQUIRED )) {
300
- return new FileInputStream (getFile (context ));
301
- } else if (status .equals (Status .DOWNLOAD_REQUIRED )) {
302
- S3Object s3Object = StorageRepository .getS3Object (context , getAmazonS3URI (context , user ));
303
- File file = getFile (context );
304
- S3ObjectInputStream inputStream = null ;
305
- try {
306
- inputStream = s3Object .getObjectContent ();
307
- Files .copy (inputStream , file .toPath (), StandardCopyOption .REPLACE_EXISTING );
308
- } catch (IOException e ) {
309
- ErrorRepository .captureException (e );
310
- } finally {
311
- if (inputStream != null ) {
312
- try {
313
- inputStream .close ();
314
- } catch (IOException e1 ) {
315
- ErrorRepository .captureException (e1 );
316
- }
317
- }
318
- }
299
+ public ObjectMetadata download (Context context , User user ) {
300
+ ObjectMetadata objectMetadata = null ;
301
+ try {
302
+ objectMetadata = StorageRepository .getObject (context , getAmazonS3URI (context , user ), getFile (context ));
319
303
status = Status .SYNCHRONIZED ;
320
- return new FileInputStream (file );
321
- } else {
322
- throw new FileNotFoundException ("Unable to resolve StorageObject." );
304
+ } catch (Exception e ) {
305
+ ErrorRepository .captureException (e );
323
306
}
307
+ return objectMetadata ;
324
308
}
325
309
}
0 commit comments