mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 09:49:19 +02:00
With InputStream
This commit is contained in:
parent
5c006fa0c8
commit
c35bb90dd4
1 changed files with 23 additions and 9 deletions
|
@ -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,16 +651,28 @@ 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 {
|
||||||
try {
|
if (inputStream != null) {
|
||||||
outputStream.close();
|
try {
|
||||||
} catch (IOException e) {
|
inputStream.close();
|
||||||
e.printStackTrace();
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (outputStream != null) {
|
||||||
|
try {
|
||||||
|
outputStream.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue