mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 09:49:19 +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;
|
package org.geometerplus.fbreader.book;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.File;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||||
import org.geometerplus.zlibrary.core.filesystem.ZLPhysicalFile;
|
import org.geometerplus.zlibrary.core.filesystem.ZLPhysicalFile;
|
||||||
import org.geometerplus.zlibrary.core.image.ZLImage;
|
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.text.view.ZLTextPosition;
|
||||||
import org.geometerplus.zlibrary.ui.android.image.ZLAndroidImageData;
|
import org.geometerplus.zlibrary.ui.android.image.ZLAndroidImageData;
|
||||||
|
@ -618,64 +616,22 @@ public class BookCollection extends AbstractBookCollection {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean saveCover(Book book, String url) {
|
public boolean saveCover(Book book, String url) {
|
||||||
|
|
||||||
if (getBookById(book.getId()) == null) {
|
if (getBookById(book.getId()) == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final ZLImage image = BookUtil.getCover(book);
|
final ZLImage image = BookUtil.getCover(book);
|
||||||
if (image == null) {
|
if (image == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (image instanceof ZLLoadableImage) {
|
|
||||||
final ZLLoadableImage loadableImage = (ZLLoadableImage)image;
|
|
||||||
if (!loadableImage.isSynchronized()) {
|
|
||||||
loadableImage.synchronize();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
final ZLAndroidImageData data =
|
final ZLAndroidImageData data =
|
||||||
((ZLAndroidImageManager)ZLAndroidImageManager.Instance()).getImageData(image);
|
((ZLAndroidImageManager)ZLAndroidImageManager.Instance()).getImageData(image);
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final InputStream inputStream = ((ZLSingleImage)image).inputStream();
|
return image.saveToFile(url);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Bookmark> bookmarks(BookmarkQuery query) {
|
public List<Bookmark> bookmarks(BookmarkQuery query) {
|
||||||
|
|
|
@ -21,4 +21,5 @@ package org.geometerplus.zlibrary.core.image;
|
||||||
|
|
||||||
public interface ZLImage {
|
public interface ZLImage {
|
||||||
String getURI();
|
String getURI();
|
||||||
|
boolean saveToFile(String url);
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,4 +49,12 @@ public abstract class ZLLoadableImage extends ZLSingleImage {
|
||||||
public abstract void synchronize();
|
public abstract void synchronize();
|
||||||
public abstract void synchronizeFast();
|
public abstract void synchronizeFast();
|
||||||
public abstract String getId();
|
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;
|
package org.geometerplus.zlibrary.core.image;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.*;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.util.MimeType;
|
import org.geometerplus.zlibrary.core.util.MimeType;
|
||||||
|
|
||||||
|
@ -35,4 +35,44 @@ public abstract class ZLSingleImage implements ZLImage {
|
||||||
public final MimeType mimeType() {
|
public final MimeType mimeType() {
|
||||||
return myMimeType;
|
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