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