mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +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);
|
notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private long countBytes(InputStream source) throws IOException {
|
|
||||||
long length = 0;
|
|
||||||
while(source.read() != -1) {
|
|
||||||
length++;
|
|
||||||
}
|
|
||||||
return length;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onHandleIntent(Intent intent) {
|
protected void onHandleIntent(Intent intent) {
|
||||||
MWApi api = ((CommonsApplication)this.getApplicationContext()).getApi();
|
MWApi api = ((CommonsApplication)this.getApplicationContext()).getApi();
|
||||||
|
|
@ -85,9 +77,7 @@ public class UploadService extends IntentService {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
file = this.getContentResolver().openInputStream(mediaUri);
|
file = this.getContentResolver().openInputStream(mediaUri);
|
||||||
InputStream streamForCounting = this.getContentResolver().openInputStream(mediaUri);
|
length = this.getContentResolver().openAssetFileDescriptor(mediaUri, "r").getLength();
|
||||||
length = countBytes(streamForCounting);
|
|
||||||
streamForCounting.close();
|
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue