Example usage for java.nio ByteBuffer remaining

List of usage examples for java.nio ByteBuffer remaining

Introduction

In this page you can find the example usage for java.nio ByteBuffer remaining.

Prototype

public final int remaining() 

Source Link

Document

Returns the number of remaining elements in this buffer, that is limit - position .

Usage

From source file:Main.java

public static int sizeP(ByteBuffer bb) {
    return bb.remaining();
}

From source file:Main.java

public static byte[] bufferToBytes(ByteBuffer byteBuffer) {
    byte[] bytes = new byte[byteBuffer.remaining()];
    byteBuffer.get(bytes, 0, bytes.length);
    return bytes;
}

From source file:Main.java

public static InputStream toStream(ByteBuffer bytebuffer) {
    byte abyte0[] = new byte[bytebuffer.remaining()];
    bytebuffer.get(abyte0);/* w w  w.  j a v  a2 s.  c  om*/
    return new ByteArrayInputStream(abyte0);
}

From source file:Main.java

private static int toFloat16LE(ByteBuffer buf, float[] out) {
    int samples = 0;
    while (buf.remaining() >= 2 && samples < out.length) {
        out[samples++] = r16 * (short) ((buf.get() & 0xff) | ((buf.get() & 0xff) << 8));
    }/*w  ww .ja v  a2 s  .  c o  m*/
    return samples;
}

From source file:Main.java

private static int toFloat16BE(ByteBuffer buf, float[] out) {
    int samples = 0;
    while (buf.remaining() >= 2 && samples < out.length) {
        out[samples++] = r16 * (short) (((buf.get() & 0xff) << 8) | (buf.get() & 0xff));
    }/*from  w w w .jav  a 2 s .  c om*/
    return samples;
}

From source file:Main.java

/**
 * Wraps a ByteBuffer in an InputStream. 
 * /*from  w ww .j a v  a2 s .  c o  m*/
 * @param byteBuffer The ByteBuffer to wrap.
 * 
 * @return An InputStream wrapping the ByteBuffer content.
 */
public static InputStream toStream(ByteBuffer byteBuffer) {
    byte[] bytes = new byte[byteBuffer.remaining()];
    byteBuffer.get(bytes);
    return new ByteArrayInputStream(bytes);
}

From source file:Main.java

private static int toFloat24LE(ByteBuffer buf, float[] out) {
    int samples = 0;
    while (buf.remaining() >= 3 && samples < out.length) {
        out[samples++] = r24/*  w ww  .ja va2 s. com*/
                * ((((buf.get() & 0xff) << 8) | ((buf.get() & 0xff) << 16) | ((buf.get() & 0xff) << 24)) >> 8);
    }
    return samples;
}

From source file:Main.java

private static int toFloat24BE(ByteBuffer buf, float[] out) {
    int samples = 0;
    while (buf.remaining() >= 3 && samples < out.length) {
        out[samples++] = r24/*from   ww w  .  ja va 2s . c om*/
                * ((((buf.get() & 0xff) << 24) | ((buf.get() & 0xff) << 16) | ((buf.get() & 0xff) << 8)) >> 8);
    }
    return samples;
}

From source file:Main.java

public static ByteBuffer copyByteBuffer(ByteBuffer buf) {
    ByteBuffer dest = newByteBuffer(buf.remaining());
    buf.mark();/*from  w w  w  .  j  av a  2  s  . co m*/
    dest.put(buf);
    buf.reset();
    dest.rewind();
    return dest;
}

From source file:Main.java

public static void readFully(final ReadableByteChannel channel, final ByteBuffer buf) throws IOException {
    readFully(channel, buf, buf.remaining());
}