mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 17:59:33 +02:00
Fix
This commit is contained in:
parent
c35bb90dd4
commit
17c6b24b53
4 changed files with 54 additions and 49 deletions
|
@ -19,14 +19,12 @@
|
|||
|
||||
package org.geometerplus.fbreader.book;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||
import org.geometerplus.zlibrary.core.filesystem.ZLPhysicalFile;
|
||||
import org.geometerplus.zlibrary.core.image.ZLImage;
|
||||
import org.geometerplus.zlibrary.core.image.ZLLoadableImage;
|
||||
import org.geometerplus.zlibrary.core.image.ZLSingleImage;
|
||||
|
||||
import org.geometerplus.zlibrary.text.view.ZLTextPosition;
|
||||
import org.geometerplus.zlibrary.ui.android.image.ZLAndroidImageData;
|
||||
|
@ -618,7 +616,6 @@ public class BookCollection extends AbstractBookCollection {
|
|||
|
||||
@Override
|
||||
public boolean saveCover(Book book, String url) {
|
||||
|
||||
if (getBookById(book.getId()) == null) {
|
||||
return false;
|
||||
}
|
||||
|
@ -628,54 +625,13 @@ public class BookCollection extends AbstractBookCollection {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (image instanceof ZLLoadableImage) {
|
||||
final ZLLoadableImage loadableImage = (ZLLoadableImage)image;
|
||||
if (!loadableImage.isSynchronized()) {
|
||||
loadableImage.synchronize();
|
||||
}
|
||||
}
|
||||
final ZLAndroidImageData data =
|
||||
((ZLAndroidImageManager)ZLAndroidImageManager.Instance()).getImageData(image);
|
||||
if (data == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final InputStream inputStream = ((ZLSingleImage)image).inputStream();
|
||||
if (inputStream == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
OutputStream outputStream = null;
|
||||
final File file = new File(url);
|
||||
final File parent = file.getParentFile();
|
||||
parent.mkdirs();
|
||||
try {
|
||||
outputStream = new FileOutputStream(file);
|
||||
int read = 0;
|
||||
byte[] bytes = new byte[1024];
|
||||
while ((read = inputStream.read(bytes)) != -1) {
|
||||
outputStream.write(bytes, 0, read);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
} finally {
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (outputStream != null) {
|
||||
try {
|
||||
outputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return image.saveToFile(url);
|
||||
}
|
||||
|
||||
public List<Bookmark> bookmarks(BookmarkQuery query) {
|
||||
|
|
|
@ -21,4 +21,5 @@ package org.geometerplus.zlibrary.core.image;
|
|||
|
||||
public interface ZLImage {
|
||||
String getURI();
|
||||
boolean saveToFile(String url);
|
||||
}
|
||||
|
|
|
@ -49,4 +49,12 @@ public abstract class ZLLoadableImage extends ZLSingleImage {
|
|||
public abstract void synchronize();
|
||||
public abstract void synchronizeFast();
|
||||
public abstract String getId();
|
||||
|
||||
@Override
|
||||
public boolean saveToFile(String url) {
|
||||
if (!isSynchronized()) {
|
||||
synchronize();
|
||||
}
|
||||
return super.saveToFile(url);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
package org.geometerplus.zlibrary.core.image;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.*;
|
||||
|
||||
import org.geometerplus.zlibrary.core.util.MimeType;
|
||||
|
||||
|
@ -35,4 +35,44 @@ public abstract class ZLSingleImage implements ZLImage {
|
|||
public final MimeType mimeType() {
|
||||
return myMimeType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveToFile(String url) {
|
||||
final InputStream inputStream = inputStream();
|
||||
if (inputStream == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
OutputStream outputStream = null;
|
||||
final File file = new File(url);
|
||||
final File parent = file.getParentFile();
|
||||
parent.mkdirs();
|
||||
try {
|
||||
outputStream = new FileOutputStream(file);
|
||||
int read = 0;
|
||||
byte[] bytes = new byte[1024];
|
||||
while ((read = inputStream.read(bytes)) != -1) {
|
||||
outputStream.write(bytes, 0, read);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
} finally {
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (outputStream != null) {
|
||||
try {
|
||||
outputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue