X-Git-Url: http://git.nikiroo.be/?p=nikiroo-utils.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fstreams%2FBufferedInputStream.java;h=336dba4000c54a26b25e33d0e84a2d8f46b2a01d;hp=da862e3f6802aa22f47586196a680d53d89d302f;hb=dce410fec00030c0affde7b19bcde6de847fae13;hpb=bd86c2218b4a8befeb9b2789b62e1697993f0b5b diff --git a/src/be/nikiroo/utils/streams/BufferedInputStream.java b/src/be/nikiroo/utils/streams/BufferedInputStream.java index da862e3..336dba4 100644 --- a/src/be/nikiroo/utils/streams/BufferedInputStream.java +++ b/src/be/nikiroo/utils/streams/BufferedInputStream.java @@ -105,6 +105,15 @@ public class BufferedInputStream extends InputStream { this.stop = length; } + /** + * The internal buffer size (can be useful to know for search methods). + * + * @return the size of the internal buffer, in bytes. + */ + public int getInternalBufferSize() { + return originalBuffer.length; + } + /** * Return this very same {@link BufferedInputStream}, but keep a counter of * how many streams were open this way. When calling @@ -127,6 +136,50 @@ public class BufferedInputStream extends InputStream { return this; } + /** + * Check if the current content (until eof) is equal to the given search + * term. + *

+ * Note: the search term size must be smaller or equal the internal + * buffer size. + * + * @param search + * the term to search for + * + * @return TRUE if the content that will be read starts with it + * + * @throws IOException + * in case of I/O error or if the size of the search term is + * greater than the internal buffer + */ + public boolean is(String search) throws IOException { + return is(StringUtils.getBytes(search)); + } + + /** + * Check if the current content (until eof) is equal to the given search + * term. + *

+ * Note: the search term size must be smaller or equal the internal + * buffer size. + * + * @param search + * the term to search for + * + * @return TRUE if the content that will be read starts with it + * + * @throws IOException + * in case of I/O error or if the size of the search term is + * greater than the internal buffer + */ + public boolean is(byte[] search) throws IOException { + if (startsWith(search)) { + return stop == search.length; + } + + return false; + } + /** * Check if the current content (what will be read next) starts with the * given search term.