mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
synchronization with native branch
This commit is contained in:
parent
d89d4050b6
commit
1fdddf1cf9
1 changed files with 33 additions and 3 deletions
|
@ -267,17 +267,47 @@ public final class ZLAndroidLibrary extends ZLibrary {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private long mySize = -1;
|
||||||
@Override
|
@Override
|
||||||
public long size() {
|
public long size() {
|
||||||
|
if (mySize == -1) {
|
||||||
|
mySize = sizeInternal();
|
||||||
|
}
|
||||||
|
return mySize;
|
||||||
|
}
|
||||||
|
|
||||||
|
private long sizeInternal() {
|
||||||
try {
|
try {
|
||||||
// TODO: for some files (archives, crt) descriptor cannot be opened
|
|
||||||
AssetFileDescriptor descriptor = myApplication.getAssets().openFd(getPath());
|
AssetFileDescriptor descriptor = myApplication.getAssets().openFd(getPath());
|
||||||
|
// for some files (archives, crt) descriptor cannot be opened
|
||||||
if (descriptor == null) {
|
if (descriptor == null) {
|
||||||
return 0;
|
return sizeSlow();
|
||||||
}
|
}
|
||||||
long length = descriptor.getLength();
|
long length = descriptor.getLength();
|
||||||
descriptor.close();
|
descriptor.close();
|
||||||
return length;
|
return length;
|
||||||
|
} catch (IOException e) {
|
||||||
|
return sizeSlow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private long sizeSlow() {
|
||||||
|
try {
|
||||||
|
final InputStream stream = getInputStream();
|
||||||
|
if (stream == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
long size = 0;
|
||||||
|
final long step = 1024 * 1024;
|
||||||
|
while (true) {
|
||||||
|
// TODO: does skip work as expected for these files?
|
||||||
|
long offset = stream.skip(step);
|
||||||
|
size += offset;
|
||||||
|
if (offset < step) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return size;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue