Example usage for java.nio IntBuffer get

List of usage examples for java.nio IntBuffer get

Introduction

In this page you can find the example usage for java.nio IntBuffer get.

Prototype

public abstract int get();

Source Link

Document

Returns the int at the current position and increases the position by 1.

Usage

From source file:Main.java

public static void main(String[] args) {
    IntBuffer bb = IntBuffer.allocate(10);
    bb.put(100);/*from  ww w  .  j  a  v a 2  s .c  o m*/

    bb.rewind();
    System.out.println(bb.get());

}

From source file:MainClass.java

public static void main(String[] args) throws IOException {
    FileChannel fc = new FileInputStream(new File("temp.tmp")).getChannel();
    IntBuffer ib = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size()).asIntBuffer();
    while (ib.hasRemaining())
        ib.get();
    fc.close();//from w  w  w. ja v  a  2s  . co m
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    int port = 1919;

    SocketAddress address = new InetSocketAddress("127.0.0.1", port);
    SocketChannel client = SocketChannel.open(address);
    ByteBuffer buffer = ByteBuffer.allocate(4);
    IntBuffer view = buffer.asIntBuffer();

    for (int expected = 0;; expected++) {
        client.read(buffer);/*from  w ww . j av a 2s .c o m*/
        int actual = view.get();
        buffer.clear();
        view.rewind();

        if (actual != expected) {
            System.err.println("Expected " + expected + "; was " + actual);
            break;
        }
        System.out.println(actual);
    }
}

From source file:MainClass.java

public static void main(String[] args) {
    ByteBuffer bb = ByteBuffer.wrap(new byte[] { 0, 0, 0, 0, 0, 0, 0, 'a' });
    bb.rewind();//from  w  ww.  j a v a2s .  co m
    IntBuffer ib = ((ByteBuffer) bb.rewind()).asIntBuffer();
    System.out.println("Int Buffer");
    while (ib.hasRemaining())
        System.out.println(ib.position() + " -> " + ib.get());

}

From source file:Main.java

public static void main(String[] args) {
    ByteBuffer bb = ByteBuffer.wrap(new byte[] { 0, 0, 0, 0, 0, 0, 0, 'a' });
    bb.rewind();/*from w  ww . java2s .c  o m*/
    System.out.println("Byte Buffer");
    while (bb.hasRemaining())
        System.out.println(bb.position() + " -> " + bb.get());
    CharBuffer cb = ((ByteBuffer) bb.rewind()).asCharBuffer();
    System.out.println("Char Buffer");
    while (cb.hasRemaining())
        System.out.println(cb.position() + " -> " + cb.get());
    FloatBuffer fb = ((ByteBuffer) bb.rewind()).asFloatBuffer();
    System.out.println("Float Buffer");
    while (fb.hasRemaining())
        System.out.println(fb.position() + " -> " + fb.get());
    IntBuffer ib = ((ByteBuffer) bb.rewind()).asIntBuffer();
    System.out.println("Int Buffer");
    while (ib.hasRemaining())
        System.out.println(ib.position() + " -> " + ib.get());
    LongBuffer lb = ((ByteBuffer) bb.rewind()).asLongBuffer();
    System.out.println("Long Buffer");
    while (lb.hasRemaining())
        System.out.println(lb.position() + " -> " + lb.get());
    ShortBuffer sb = ((ByteBuffer) bb.rewind()).asShortBuffer();
    System.out.println("Short Buffer");
    while (sb.hasRemaining())
        System.out.println(sb.position() + " -> " + sb.get());
    DoubleBuffer db = ((ByteBuffer) bb.rewind()).asDoubleBuffer();
    System.out.println("Double Buffer");
    while (db.hasRemaining())
        System.out.println(db.position() + " -> " + db.get());
}

From source file:Main.java

/**
 * Create a new int[] array and populate it with the given IntBuffer's
 * contents./*from w  ww  . j  ava  2s. c  om*/
 * 
 * @param buff
 *            the IntBuffer to read from
 * @return a new int array populated from the IntBuffer
 */
public static int[] getIntArray(IntBuffer buff) {
    if (buff == null) {
        return null;
    }
    buff.clear();
    int[] inds = new int[buff.limit()];
    for (int x = 0; x < inds.length; x++) {
        inds[x] = buff.get();
    }
    return inds;
}

From source file:Main.java

private static String formatInts(byte[] data) {
    IntBuffer bb = ByteBuffer.wrap(data).order(ByteOrder.LITTLE_ENDIAN).asIntBuffer();

    StringBuilder sb = new StringBuilder(bb.capacity() * 3);

    while (bb.remaining() > 0) {
        sb.append(bb.get());
        sb.append(',');
        sb.append('\n');
    }/*  ww  w . j a v a 2  s.  c  o  m*/

    return sb.toString();
}

From source file:Main.java

public static int[] getIntArray(final IntBuffer buff) {
    if (buff == null) {
        return null;
    }//from w w w. j  a va 2  s  . c om
    buff.rewind();
    final int[] inds = new int[buff.limit()];
    for (int x = 0; x < inds.length; x++) {
        inds[x] = buff.get();
    }
    return inds;
}

From source file:org.jcodec.codecs.mjpeg.JpegDecoder.java

private static void decodeBlock(MCU block, QuantTable qLum, QuantTable qChrom) {

    zigzagDecodeAll(block.lum.data);//from   www . j av  a  2s  .  co  m
    zigzagDecodeAll(block.cb.data);
    zigzagDecodeAll(block.cr.data);

    dequantAll(block.lum.data, qLum);
    dequantAll(block.cb.data, qChrom);
    dequantAll(block.cr.data, qChrom);

    dct.decodeAll(block.lum.data);
    dct.decodeAll(block.cb.data);
    dct.decodeAll(block.cr.data);

    IntBuffer rgb = block.getRgb24();
    IntBuffer Cb = IntBuffer.wrap(block.cb.data[0]);
    IntBuffer Cr = IntBuffer.wrap(block.cr.data[0]);
    if (block.is420()) {
        IntBuffer y00 = IntBuffer.wrap(block.lum.data[0]);
        IntBuffer y01 = IntBuffer.wrap(block.lum.data[1]);
        IntBuffer y10 = IntBuffer.wrap(block.lum.data[2]);
        IntBuffer y11 = IntBuffer.wrap(block.lum.data[3]);

        for (int j = 0; j < 8; j++) {
            Cb.position((j & ~1) << 2);
            Cr.position((j & ~1) << 2);
            lineToRgb(y00, Cb, Cr, rgb);
            lineToRgb(y01, Cb, Cr, rgb);
        }
        for (int j = 8; j < 16; j++) {
            Cb.position((j & ~1) << 2);
            Cr.position((j & ~1) << 2);
            lineToRgb(y10, Cb, Cr, rgb);
            lineToRgb(y11, Cb, Cr, rgb);
        }
    } else if (block.is422()) {
        IntBuffer y00 = IntBuffer.wrap(block.lum.data[0]);
        IntBuffer y01 = IntBuffer.wrap(block.lum.data[1]);
        for (int j = 0; j < 8; j++) {
            Cb.position(j << 3);
            Cr.position(j << 3);
            lineToRgb(y00, Cb, Cr, rgb);
            lineToRgb(y01, Cb, Cr, rgb);
        }
    } else if (block.is444()) {
        IntBuffer Y = IntBuffer.wrap(block.lum.data[0]);
        while (rgb.hasRemaining()) {
            rgb.put(ImageConvert.ycbcr_to_rgb24(Y.get(), Cb.get(), Cr.get()));
        }
    } else {
        throw new IllegalStateException("unsupported MCU");
    }

}

From source file:org.jcodec.codecs.mjpeg.JpegDecoder.java

private static void lineToRgb(IntBuffer Y, IntBuffer Cb, IntBuffer Cr, IntBuffer rgb) {
    for (int i = 0; i < 8; i++) {
        Cb.position(Cb.position() - (i & 1));
        Cr.position(Cr.position() - (i & 1));
        int y = Y.get();
        int cb = Cb.get();
        int cr = Cr.get();
        rgb.put(ImageConvert.ycbcr_to_rgb24(y, cb, cr));
    }//from   w  w w . j av a 2  s .com
}