Search in sources :

Example 1 with MuPdfPasswordRequiredException

use of org.ebookdroid.droids.mupdf.codec.exceptions.MuPdfPasswordRequiredException in project LibreraReader by foobnix.

the class AbstractCodecContext method openDocument.

@Override
public CodecDocument openDocument(String fileNameOriginal, String password) {
    LOG.d("Open-Document", fileNameOriginal);
    // TempHolder.get().loadingCancelled = false;
    if (ExtUtils.isZip(fileNameOriginal)) {
        LOG.d("Open-Document ZIP", fileNameOriginal);
        return openDocumentInnerCanceled(fileNameOriginal, password);
    }
    LOG.d("Open-Document 2 LANG:", BookCSS.get().hypenLang, fileNameOriginal);
    File cacheFileName = getCacheFileName(fileNameOriginal);
    CacheZipUtils.removeFiles(CacheZipUtils.CACHE_BOOK_DIR.listFiles(), cacheFileName);
    if (cacheFileName != null && cacheFileName.isFile()) {
        LOG.d("Open-Document from cache", fileNameOriginal);
        return openDocumentInnerCanceled(fileNameOriginal, password);
    }
    CacheZipUtils.cacheLock.lock();
    CacheZipUtils.createAllCacheDirs();
    try {
        String fileName = CacheZipUtils.extracIfNeed(fileNameOriginal, CacheDir.ZipApp).unZipPath;
        LOG.d("Open-Document extract", fileName);
        if (!ExtUtils.isValidFile(fileName)) {
            return null;
        }
        try {
            return openDocumentInnerCanceled(fileName, password);
        } catch (MuPdfPasswordException e) {
            throw new MuPdfPasswordRequiredException();
        } catch (Throwable e) {
            LOG.e(e);
            return null;
        }
    } finally {
        CacheZipUtils.cacheLock.unlock();
    }
}
Also used : File(java.io.File) MuPdfPasswordException(org.ebookdroid.droids.mupdf.codec.exceptions.MuPdfPasswordException) MuPdfPasswordRequiredException(org.ebookdroid.droids.mupdf.codec.exceptions.MuPdfPasswordRequiredException)

Aggregations

File (java.io.File)1 MuPdfPasswordException (org.ebookdroid.droids.mupdf.codec.exceptions.MuPdfPasswordException)1 MuPdfPasswordRequiredException (org.ebookdroid.droids.mupdf.codec.exceptions.MuPdfPasswordRequiredException)1