X-Git-Url: http://git.nikiroo.be/?p=nikiroo-utils.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fstreams%2FBufferedInputStream.java;h=be4b24d2ec9b477b3556df34fd607923c8c30bf5;hp=7c20f634824841c8c7dd5d60fe94456dce1c78da;hb=c8ce09c4dc57142f94afcdc290dd79c4bddf7820;hpb=8e76f6ab13a8a4a651f2518b6c91d5e6424c7922 diff --git a/src/be/nikiroo/utils/streams/BufferedInputStream.java b/src/be/nikiroo/utils/streams/BufferedInputStream.java index 7c20f63..be4b24d 100644 --- a/src/be/nikiroo/utils/streams/BufferedInputStream.java +++ b/src/be/nikiroo/utils/streams/BufferedInputStream.java @@ -167,7 +167,7 @@ public class BufferedInputStream extends InputStream { if (available() >= search.length) { // Easy path - return startsWith(search, buffer, start, stop); + return StreamUtils.startsWith(search, buffer, start, stop); } else if (!eof) { // Harder path if (buffer2 == null && buffer.length == originalBuffer.length) { @@ -183,7 +183,7 @@ public class BufferedInputStream extends InputStream { len2 += pos2; } - return startsWith(search, buffer2, pos2, len2); + return StreamUtils.startsWith(search, buffer2, pos2, len2); } return false; @@ -416,46 +416,4 @@ public class BufferedInputStream extends InputStream { "This BufferedInputStream was closed, you cannot use it anymore."); } } - - /** - * Check if the buffer starts with the given search term (given as an array, - * a start position and a end position). - *

- * Note: the parameter len is the index of the last - * position, not the length. - *

- * Note: the search term size must be smaller or equal the internal - * buffer size. - * - * @param search - * the term to search for - * @param buffer - * the buffer to look into - * @param offset - * the offset at which to start the search - * @param len - * the maximum index of the data to check (this is not a - * length, but an index) - * - * @return TRUE if the search content is present at the given location and - * does not exceed the len index - */ - static protected boolean startsWith(byte[] search, byte[] buffer, - int offset, int len) { - - // Check if there even is enough space for it - if (search.length > (len - offset)) { - return false; - } - - boolean same = true; - for (int i = 0; i < search.length; i++) { - if (search[i] != buffer[offset + i]) { - same = false; - break; - } - } - - return same; - } }