Example usage for java.nio IntBuffer hasRemaining

List of usage examples for java.nio IntBuffer hasRemaining

Introduction

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

Prototype

public final boolean hasRemaining() 

Source Link

Document

Indicates if there are elements remaining in this buffer, that is if position < limit .

Usage

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();//w  w  w. j  av  a 2  s  .  c o  m
    fc.close();
}

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  ww w . ja v  a 2 s.  c  o 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();//  w  ww.  j  a v  a  2s.  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:MainClass.java

public static void main(String[] args) {
    ByteBuffer bb = ByteBuffer.allocate(BSIZE);
    IntBuffer ib = bb.asIntBuffer();

    ib.put(new int[] { 1, 2, 7, 9, 3, 8, 6 });

    System.out.println(ib.get(3));
    ib.put(3, 1811);//from  w ww  .j  a va  2 s .  c  o  m
    ib.rewind();
    while (ib.hasRemaining()) {
        int i = ib.get();
        if (i == 0)
            break; // Else we'll get the entire buffer
        System.out.println(i);
    }
}

From source file:IntBufferDemo.java

public static void main(String[] args) {
    ByteBuffer bb = ByteBuffer.allocate(BSIZE);
    IntBuffer ib = bb.asIntBuffer();
    // Store an array of int:
    ib.put(new int[] { 11, 42, 47, 99, 143, 811, 1016 });
    // Absolute location read and write:
    System.out.println(ib.get(3));
    ib.put(3, 1811);//from w  w w. j av a2  s  .c  om
    ib.rewind();
    while (ib.hasRemaining()) {
        int i = ib.get();
        if (i == 0)
            break; // Else we'll get the entire buffer
        System.out.println(i);
    }

}

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

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

    zigzagDecodeAll(block.lum.data);//from ww  w .ja va  2 s  .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");
    }

}