1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-03 17:59:33 +02:00

With InputStream

This commit is contained in:
lidoxod 2013-07-27 23:21:14 +04:00
parent 5c006fa0c8
commit c35bb90dd4

View file

@ -26,6 +26,7 @@ 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.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;
@ -617,15 +618,16 @@ 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) { if (image instanceof ZLLoadableImage) {
final ZLLoadableImage loadableImage = (ZLLoadableImage)image; final ZLLoadableImage loadableImage = (ZLLoadableImage)image;
if (!loadableImage.isSynchronized()) { if (!loadableImage.isSynchronized()) {
@ -638,8 +640,8 @@ public class BookCollection extends AbstractBookCollection {
return false; return false;
} }
final Bitmap coverBitmap = data.getFullSizeBitmap(); final InputStream inputStream = ((ZLSingleImage)image).inputStream();
if (coverBitmap == null) { if (inputStream == null) {
return false; return false;
} }
@ -649,18 +651,30 @@ public class BookCollection extends AbstractBookCollection {
parent.mkdirs(); parent.mkdirs();
try { try {
outputStream = new FileOutputStream(file); outputStream = new FileOutputStream(file);
coverBitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream); int read = 0;
outputStream.flush(); byte[] bytes = new byte[1024];
while ((read = inputStream.read(bytes)) != -1) {
outputStream.write(bytes, 0, read);
}
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
return false; return false;
} finally { } finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (outputStream != null) {
try { try {
outputStream.close(); outputStream.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
}
return true; return true;
} }