Here you can find the source of find(ByteBuffer buffer, int offset, byte searchKey)
public static int find(ByteBuffer buffer, int offset, byte searchKey)
//package com.java2s; //License from project: Apache License import java.nio.ByteBuffer; public class Main { public static int find(ByteBuffer buffer, int offset, byte searchKey) { for (int i = buffer.position() + offset; i < buffer.limit(); i++) { byte nextByte = buffer.get(i); if (nextByte == searchKey) { return i; }/*w w w. j a va 2 s. co m*/ } return -1; } public static int find(ByteBuffer buffer, int offset, byte[] searchKey) { int searchIndex = 0; for (int i = buffer.position() + offset; i < buffer.limit() - searchKey.length; i++) { byte nextByte = buffer.get(i); if (nextByte != searchKey[searchIndex]) { searchIndex = 0; } else { searchIndex++; if (searchIndex == searchKey.length) { return i + 1 - searchKey.length; } } } return -1; } }