As reported in https://bitbucket.org/javafxports/android/issue/14/some-ensemble8-preview-images-are-not in Ensemble8 the preview images of some samples are not displayed. Loading the PNG-Image causes an EOFException. Debugging the issue reveals, that the skip method in java.util.zip.InflaterInputStream on Android, in accordance with the javadoc, does not skip all requested bytes in one go. e.g.: only 1 instead of 4.
So the following patch fixes it by implementing a loop:
diff --git a/modules/graphics/src/main/java/com/sun/javafx/iio/png/PNGIDATChunkInputStream.java b/modules/graphics/src/main/java/com/sun/javafx/iio/png/PNGIDATChunkInputStream.java
--- a/modules/graphics/src/main/java/com/sun/javafx/iio/png/PNGIDATChunkInputStream.java
+++ b/modules/graphics/src/main/java/com/sun/javafx/iio/png/PNGIDATChunkInputStream.java
@@ -68,7 +68,16 @@
private void nextChunk() throws IOException {
if (!foundAllIDATChunks) {
- if (4 != source.skip(4)) { // CRC
+ // must use loop, because java.util.zip.InflaterInputStream on Android, sometimes does not skip all bytes in one go
+ long toBeSkipped = 4; // CRC
+ while (toBeSkipped > 0) {
+ long skipped = source.skip(toBeSkipped);
+ if(skipped <= 0) {
+ break;
+ }
+ toBeSkipped -= skipped;
+ }
+ if (toBeSkipped > 0) {
throw new EOFException();
}
int chunkLength = (source.read() << 24) | (source.read() << 16) |
So the following patch fixes it by implementing a loop:
diff --git a/modules/graphics/src/main/java/com/sun/javafx/iio/png/PNGIDATChunkInputStream.java b/modules/graphics/src/main/java/com/sun/javafx/iio/png/PNGIDATChunkInputStream.java
--- a/modules/graphics/src/main/java/com/sun/javafx/iio/png/PNGIDATChunkInputStream.java
+++ b/modules/graphics/src/main/java/com/sun/javafx/iio/png/PNGIDATChunkInputStream.java
@@ -68,7 +68,16 @@
private void nextChunk() throws IOException {
if (!foundAllIDATChunks) {
- if (4 != source.skip(4)) { // CRC
+ // must use loop, because java.util.zip.InflaterInputStream on Android, sometimes does not skip all bytes in one go
+ long toBeSkipped = 4; // CRC
+ while (toBeSkipped > 0) {
+ long skipped = source.skip(toBeSkipped);
+ if(skipped <= 0) {
+ break;
+ }
+ toBeSkipped -= skipped;
+ }
+ if (toBeSkipped > 0) {
throw new EOFException();
}
int chunkLength = (source.read() << 24) | (source.read() << 16) |