+ // max is buffer.size !
+ public boolean startsWith(byte[] search) throws IOException {
+ if (search.length > originalBuffer.length) {
+ throw new IOException(
+ "This stream does not support searching for more than "
+ + buffer.length + " bytes");
+ }
+
+ checkClose();
+
+ if (available() < search.length) {
+ preRead();
+ }
+
+ if (available() >= search.length) {
+ // Easy path
+ return startsWith(search, buffer, pos);
+ } else if (!eof) {
+ // Harder path
+ if (buffer2 == null && buffer.length == originalBuffer.length) {
+ buffer2 = Arrays.copyOf(buffer, buffer.length * 2);
+
+ pos2 = buffer.length;
+ len2 = in.read(buffer2, pos2, buffer.length);
+ if (len2 > 0) {
+ bytesRead += len2;
+ }
+
+ // Note: here, len/len2 = INDEX of last good byte
+ len2 += pos2;
+ }
+
+ if (available() + (len2 - pos2) >= search.length) {
+ return startsWith(search, buffer2, pos2);
+ }
+ }
+