X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fstreams%2FBufferedInputStream.java;h=42f0d9d24c123be0fad89cce35f43bb9b5831855;hb=7194ac50b29064a013f177fc9cfc5aaa131a8ec4;hp=af1e2ac932a4abb7d46815d34963dfcf8dbf6305;hpb=028ff7c29a8fb07c702ffd34913a5dd22b688211;p=nikiroo-utils.git diff --git a/src/be/nikiroo/utils/streams/BufferedInputStream.java b/src/be/nikiroo/utils/streams/BufferedInputStream.java index af1e2ac..42f0d9d 100644 --- a/src/be/nikiroo/utils/streams/BufferedInputStream.java +++ b/src/be/nikiroo/utils/streams/BufferedInputStream.java @@ -14,13 +14,22 @@ import java.util.Arrays; * @author niki */ public class BufferedInputStream extends InputStream { + /** + * The size of the internal buffer (can be different if you pass your own + * buffer, of course). + *

+ * A second buffer of twice the size can sometimes be created as needed for + * the {@link BufferedInputStream#startsWith(byte[])} search operation. + */ + static private final int BUFFER_SIZE = 4096; + /** The current position in the buffer. */ protected int start; /** The index of the last usable position of the buffer. */ protected int stop; /** The buffer itself. */ protected byte[] buffer; - /** An End-Of-File (or buffer, here) marker. */ + /** An End-Of-File (or {@link InputStream}, here) marker. */ protected boolean eof; private boolean closed; @@ -45,7 +54,7 @@ public class BufferedInputStream extends InputStream { public BufferedInputStream(InputStream in) { this.in = in; - this.buffer = new byte[4096]; + this.buffer = new byte[BUFFER_SIZE]; this.originalBuffer = this.buffer; this.start = 0; this.stop = 0; @@ -249,7 +258,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;