Package java.nio

Examples of java.nio.LongBuffer


            LongBuffer.wrap((long[])null, -1, 0);
            fail("Should throw NPE"); //$NON-NLS-1$
        } catch (NullPointerException e) {
        }

        LongBuffer buf = LongBuffer.wrap(array, 2, 16);
        assertEquals(buf.position(), 2);
        assertEquals(buf.limit(), 18);
        assertEquals(buf.capacity(), 20);
    }


        buf.clear();
        buf.order(ByteOrder.BIG_ENDIAN);
    }

    public void testAsLongBuffer() {
        LongBuffer longBuffer;
        byte bytes[] = new byte[8];
        long value;

        // test BIG_ENDIAN long buffer, read
        buf.clear();
        buf.order(ByteOrder.BIG_ENDIAN);
        longBuffer = buf.asLongBuffer();
        assertSame(ByteOrder.BIG_ENDIAN, longBuffer.order());
        while (longBuffer.remaining() > 0) {
            buf.get(bytes);
            value = longBuffer.get();
            assertEquals(bytes2long(bytes, buf.order()), value);
        }

        // test LITTLE_ENDIAN long buffer, read
        buf.clear();
        buf.order(ByteOrder.LITTLE_ENDIAN);
        longBuffer = buf.asLongBuffer();
        assertSame(ByteOrder.LITTLE_ENDIAN, longBuffer.order());
        while (longBuffer.remaining() > 0) {
            buf.get(bytes);
            value = longBuffer.get();
            assertEquals(bytes2long(bytes, buf.order()), value);
        }

        if (!buf.isReadOnly()) {
            // test BIG_ENDIAN long buffer, write
            buf.clear();
            buf.order(ByteOrder.BIG_ENDIAN);
            longBuffer = buf.asLongBuffer();
            assertSame(ByteOrder.BIG_ENDIAN, longBuffer.order());
            while (longBuffer.remaining() > 0) {
                value = (long) longBuffer.remaining();
                longBuffer.put(value);
                buf.get(bytes);
                assertTrue(Arrays.equals(bytes, long2bytes(value, buf.order())));
            }

            // test LITTLE_ENDIAN long buffer, write
            buf.clear();
            buf.order(ByteOrder.LITTLE_ENDIAN);
            longBuffer = buf.asLongBuffer();
            assertSame(ByteOrder.LITTLE_ENDIAN, longBuffer.order());
            while (longBuffer.remaining() > 0) {
                value = (long) longBuffer.remaining();
                longBuffer.put(value);
                buf.get(bytes);
                assertTrue(Arrays.equals(bytes, long2bytes(value, buf.order())));
            }
        }

            //expected
        }
    }

    public void testHashCode() {
        LongBuffer duplicate = buf.duplicate();
        assertEquals(buf.hashCode(), duplicate.hashCode());
    }

            // expected
        }
    }

    public void testPutLongBuffer() {
        LongBuffer other = LongBuffer.allocate(1);
        try {
            buf.put(other);
            fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
        } catch (ReadOnlyBufferException e) {
            // expected

    }

    public static long getLong(byte[] bytes) {
        ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
        LongBuffer lBuffer = byteBuffer.asLongBuffer();
        return lBuffer.get();
    }

          ByteArrayInputStream bis = new ByteArrayInputStream(buf.array());
          return bis;
        } else if (type.getName().equals(CAS.TYPE_NAME_LONG_ARRAY)) {
          arrayStart = this.heap.heap[getArrayStartAddress(fs.getAddress())];
          buf = ByteBuffer.allocate(arraySize * 8);
          LongBuffer longbuf = buf.asLongBuffer();
          longbuf.put(this.longHeap.heap, arrayStart, arraySize);
          ByteArrayInputStream bis = new ByteArrayInputStream(buf.array());
          return bis;
        } else if (type.getName().equals(CAS.TYPE_NAME_DOUBLE_ARRAY)) {
          arrayStart = this.heap.heap[getArrayStartAddress(fs.getAddress())];
          buf = ByteBuffer.allocate(arraySize * 8);
 

        _max = iin.get();
        iin.get(_counts);
        in.position(iin.position() * INT_SIZE);

        // read our long data
        LongBuffer lin = in.asLongBuffer();
        _snapTotal = (_total = lin.get());
        in.position(iin.position() * INT_SIZE + lin.position() * 2 * INT_SIZE);

        // read our min value (which was added afterwards and must do some jockeying to maintain
        // backwards compatibility)
        if (in.position() == in.limit()) {
            _min = 0; // legacy

        iout.put(_max);
        iout.put(_counts);
        out.position(iout.position() * INT_SIZE);

        // write our long data
        LongBuffer lout = out.asLongBuffer();
        lout.put(_total);
        out.position(iout.position() * INT_SIZE + lout.position() * 2 * INT_SIZE);

        // write our min value (added later so we can't write it above like we wish we could)
        out.asIntBuffer().put(_min);

        return data;

      // ByteBuffer buf = ByteBuffer.wrap(b);
      // buf.putLong(l);
      // return b;

      ByteBuffer buf = ByteBuffer.wrap(b);
      LongBuffer lBuffer = buf.asLongBuffer();
      lBuffer.put(0, l);
      return b;
    }

   
    FloatBuffer fBuffer = buffer.asFloatBuffer();
    fBuffer.position(1);
    System.out.println(Memory.getPosition(fBuffer));
   
    LongBuffer lBuffer = buffer.asLongBuffer();
    lBuffer.position(1);
    System.out.println(Memory.getPosition(lBuffer));
   
    DoubleBuffer dBuffer = buffer.asDoubleBuffer();
    dBuffer.position(1);
    System.out.println(Memory.getPosition(dBuffer));

TOP

Related Classes of java.nio.LongBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.