X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fstreams%2FBufferedInputStream.java;h=da862e3f6802aa22f47586196a680d53d89d302f;hb=f8147a0ee57317e96d9ff0bf19573f7168d0354c;hp=397f6fcf9b22f414631cddb899ab38a3b38f3fa1;hpb=f04d5e49e91832e122617fbbaa5cdb053459a7e7;p=nikiroo-utils.git diff --git a/src/be/nikiroo/utils/streams/BufferedInputStream.java b/src/be/nikiroo/utils/streams/BufferedInputStream.java index 397f6fc..da862e3 100644 --- a/src/be/nikiroo/utils/streams/BufferedInputStream.java +++ b/src/be/nikiroo/utils/streams/BufferedInputStream.java @@ -4,6 +4,8 @@ import java.io.IOException; import java.io.InputStream; import java.util.Arrays; +import be.nikiroo.utils.StringUtils; + /** * A simple {@link InputStream} that is buffered with a bytes array. *

@@ -14,13 +16,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 +56,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; @@ -133,7 +144,7 @@ public class BufferedInputStream extends InputStream { * greater than the internal buffer */ public boolean startsWiths(String search) throws IOException { - return startsWith(search.getBytes("UTF-8")); + return startsWith(StringUtils.getBytes(search)); } /**