Java ByteBuffer Skip skipChars(ByteBuffer buffer, byte[] chars)

Here you can find the source of skipChars(ByteBuffer buffer, byte[] chars)

Description

skip Chars

License

Open Source License

Declaration

public static void skipChars(ByteBuffer buffer, byte[] chars) 

Method Source Code


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

import java.nio.ByteBuffer;

public class Main {
    public static void skipChars(ByteBuffer buffer, byte[] chars) {
        while (buffer.hasRemaining()) {
            byte b = buffer.get();
            if (contains(chars, b)) {
                continue;
            } else {
                buffer.position(buffer.position() - 1);
                break;
            }/*from  www. j  a  va 2 s.  c o m*/
        }
    }

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

    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. skip(ByteBuffer buffer, int count)
  2. skip(ByteBuffer buffer, int length)
  3. skip(ByteBuffer dest, int length)
  4. skipBufs(ByteBuffer[] bufs, int nextWithRemaining)
  5. skipBytes(ByteBuffer buf, int count)
  6. skipToNALUnit(ByteBuffer buf)
  7. skipUnknown(ByteBuffer buf, int length)