Java ByteBuffer Search indexOf(final ByteBuffer buf, final int c, final int start, final int end)

Here you can find the source of indexOf(final ByteBuffer buf, final int c, final int start, final int end)

Description

Returns the index of the given char within the given ByteBuffer .

License

LGPL

Parameter

Parameter Description
buf the ByteBuffer to search.
c the byte to search.
start the first byte.
end the last byte.

Return

the position, or -1 if not found.

Declaration

public static int indexOf(final ByteBuffer buf, final int c, final int start, final int end) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.nio.ByteBuffer;

public class Main {
    /**//from  w  w w  . ja  va2  s. c  om
     * Returns the index of the given char within the given {@link ByteBuffer}.
     *
     * @param buf the {@link ByteBuffer} to search.
     * @param c the byte to search.
     * @param start the first byte.
     * @param end the last byte.
     * @return the position, or -1 if not found.
     */
    public static int indexOf(final ByteBuffer buf, final int c, final int start, final int end) {
        final int cc = c; // having a local copy is faster than the stack version
        final ByteBuffer bb = buf;
        int pos = start, rem = end - start;
        while (rem-- != 0) {
            if (bb.get(pos) == cc)
                return pos;
            ++pos;
        }
        return -1;
    }
}

Related

  1. indexOf(ByteBuffer buf, byte b)
  2. indexOf(ByteBuffer buf, byte value)
  3. indexOf(ByteBuffer buffer, byte b)
  4. indexOf(ByteBuffer buffer, ByteBuffer pattern)
  5. indexOf(ByteBuffer buffer, ByteBuffer pattern)
  6. indexOf(final ByteBuffer haystack, byte[] needle)
  7. search(ByteBuffer buffer, int n, byte[] param)
  8. unsignedBinarySearch(final ByteBuffer array, int position, final int begin, final int end, final short k)