From 6b40125982e99f813130c0eef65045ae5a0cc623 Mon Sep 17 00:00:00 2001 From: YuviPanda Date: Sun, 14 Oct 2012 15:36:59 +0530 Subject: [PATCH] Use much faster way of reading file length --- src/org/wikimedia/commons/UploadService.java | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/org/wikimedia/commons/UploadService.java b/src/org/wikimedia/commons/UploadService.java index f73420b27..dccec5306 100644 --- a/src/org/wikimedia/commons/UploadService.java +++ b/src/org/wikimedia/commons/UploadService.java @@ -61,14 +61,6 @@ public class UploadService extends IntentService { notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); } - private long countBytes(InputStream source) throws IOException { - long length = 0; - while(source.read() != -1) { - length++; - } - return length; - } - @Override protected void onHandleIntent(Intent intent) { MWApi api = ((CommonsApplication)this.getApplicationContext()).getApi(); @@ -85,9 +77,7 @@ public class UploadService extends IntentService { try { file = this.getContentResolver().openInputStream(mediaUri); - InputStream streamForCounting = this.getContentResolver().openInputStream(mediaUri); - length = countBytes(streamForCounting); - streamForCounting.close(); + length = this.getContentResolver().openAssetFileDescriptor(mediaUri, "r").getLength(); } catch (FileNotFoundException e) { throw new RuntimeException(e); } catch (IOException e) {