Java ByteBuffer from getByteBuffer(ByteBuffer source, int count)

Here you can find the source of getByteBuffer(ByteBuffer source, int count)

Description

Please note that this moves the source buffer forward.

License

Open Source License

Parameter

Parameter Description
source a parameter
count a parameter

Declaration

public static ByteBuffer getByteBuffer(ByteBuffer source, int count) 

Method Source Code

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

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

public class Main {
    /**//ww w  . ja  va  2  s  .co  m
     * Please note that this moves the source buffer forward.
     * 
     * @param source
     * @param count
     * @return
     */
    public static ByteBuffer getByteBuffer(ByteBuffer source, int count) {
        byte[] data = new byte[count];
        source.get(data);
        ByteBuffer result = ByteBuffer.wrap(data);
        result.order(source.order());
        return result;
    }

    public static ByteBuffer getByteBuffer(ByteBuffer source, int count,
            ByteOrder order) {
        byte[] data = new byte[count];
        source.get(data);
        ByteBuffer result = ByteBuffer.wrap(data);
        result.order(order);
        return result;
    }
}

Related

  1. getByteBuffer(byte[] array)
  2. getByteBuffer(byte[] data, int fromByte, int length)
  3. getByteBuffer(final String string, final Charset charset)
  4. getByteBuffer(int size)
  5. getByteBuffer(Object obj)
  6. getByteBuffer(String base64)