mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Use much faster way of reading file length
This commit is contained in:
parent
018c565f3b
commit
6b40125982
1 changed files with 1 additions and 11 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue