Java ByteBuffer Contain contains(ByteBuffer buffer, byte b)

Here you can find the source of contains(ByteBuffer buffer, byte b)

Description

contains

License

Open Source License

Declaration

public static boolean contains(ByteBuffer buffer, byte b) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.nio.ByteBuffer;

public class Main {
    public static boolean contains(ByteBuffer buffer, byte b) {
        return contains(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining(), b);
    }/*from   w w  w. j  a  va 2 s .c om*/

    public static boolean contains(byte[] data, byte b) {
        return contains(data, 0, data.length, b);
    }

    public static boolean contains(byte[] data, int offset, int length, byte b) {
        return indexOf(data, offset, length, b) >= 0;
    }

    public static int indexOf(ByteBuffer buffer, byte b) {
        return indexOf(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining(), b);
    }

    public static int indexOf(byte[] data, byte b) {
        return indexOf(data, 0, data.length, b);
    }

    public static int indexOf(byte[] data, int offset, int length, byte b) {
        int idx = -1;

        for (int i = offset; i < offset + length; i++) {
            if (data[i] == b) {
                idx = i;
                break;
            }
        }

        return idx;
    }
}

Related

  1. contains(ByteBuffer buffer, ByteBuffer subBuffer)