bufixes
authorNiki Roo <niki@nikiroo.be>
Sun, 28 Apr 2019 17:18:24 +0000 (19:18 +0200)
committerNiki Roo <niki@nikiroo.be>
Sun, 28 Apr 2019 17:18:24 +0000 (19:18 +0200)
src/be/nikiroo/utils/Image.java
src/be/nikiroo/utils/streams/BufferedInputStream.java

index cfcaa74e2c1b8e2f1cd280f687afbfd7e8ad51bf..ace43dedc59d52b596442575ac75fefae2ef99a7 100644 (file)
@@ -7,6 +7,8 @@ import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 
+import be.nikiroo.utils.streams.MarkableFileInputStream;
+
 /**
  * This class represents an image data.
  * 
@@ -91,7 +93,7 @@ public class Image implements Closeable {
         *             in case of I/O error
         */
        public InputStream newInputStream() throws IOException {
-               return new FileInputStream(data);
+               return new MarkableFileInputStream(new FileInputStream(data));
        }
 
        /**
index af1e2ac932a4abb7d46815d34963dfcf8dbf6305..397f6fcf9b22f414631cddb899ab38a3b38f3fa1 100644 (file)
@@ -249,7 +249,7 @@ public class BufferedInputStream extends InputStream {
                while (hasMoreData() && done < blen) {
                        preRead();
                        if (hasMoreData()) {
-                               int now = Math.min(blen, stop) - start;
+                               int now = Math.min(blen - done, stop - start);
                                if (now > 0) {
                                        System.arraycopy(buffer, start, b, boff + done, now);
                                        start += now;