1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-05 10:49:24 +02:00

litres authentication has been fixed: corrected exists() method for asset-based files

This commit is contained in:
Nikolay Pultsin 2010-11-14 01:35:55 +00:00
parent 53856e9fc3
commit fa57c3720e

View file

@ -185,11 +185,11 @@ public final class ZLAndroidLibrary extends ZLibrary {
@Override
public boolean isDirectory() {
try {
AssetFileDescriptor descriptor = myApplication.getAssets().openFd(getPath());
if (descriptor == null) {
InputStream stream = myApplication.getAssets().open(getPath());
if (stream == null) {
return true;
}
descriptor.close();
stream.close();
return false;
} catch (IOException e) {
return true;
@ -199,17 +199,19 @@ public final class ZLAndroidLibrary extends ZLibrary {
@Override
public boolean exists() {
try {
AssetFileDescriptor descriptor = myApplication.getAssets().openFd(getPath());
if (descriptor != null) {
descriptor.close();
InputStream stream = myApplication.getAssets().open(getPath());
if (stream != null) {
stream.close();
// file exists
return true;
}
} catch (IOException e) {
e.printStackTrace();
}
try {
String[] names = myApplication.getAssets().list(getPath());
if (names != null && names.length != 0) {
// directory exists
return true;
}
} catch (IOException e) {
@ -220,6 +222,7 @@ public final class ZLAndroidLibrary extends ZLibrary {
@Override
public long size() {
try {
// TODO: for some files (archives, crt) descriptor cannot be opened
AssetFileDescriptor descriptor = myApplication.getAssets().openFd(getPath());
if (descriptor == null) {
return 0;