Package java.nio

Examples of java.nio.LongBuffer


                         i < 512 ? 0 : MAGIC, array[i]);
        }
    }
    public void testWrappedLongArrayArguent() {
        long[] array = new long[1024];
        LongBuffer buf  = LongBuffer.wrap(array, 512, 512).slice();
        final long MAGIC = 0x1234567887654321L;
        lib.fillInt64Buffer(buf, 512, MAGIC);
        for (int i=0;i < array.length;i++) {
            assertEquals("Bad value at index " + i,
                         i < 512 ? 0 : MAGIC, array[i]);


    return String.format("%016x", length + head + tail);
  }

  private static long computeHashForChunk(ByteBuffer buffer) {

    LongBuffer longBuffer = buffer.order(ByteOrder.LITTLE_ENDIAN).asLongBuffer();
    long hash = 0;

    while (longBuffer.hasRemaining()) {
      hash += longBuffer.get();
    }

    return hash;
  }

    private MutableLongArray array;

    @Before
    public void setUp() throws Exception {
        long[] a = new long[] {0, 0, 1, 1, 2, 1, 2, 3, 3, 4};
        LongBuffer buffer = LongBuffer.wrap(a, 1, 9);
        array = MutableLongArray.valueOf(buffer);
        array = serializeAndDeserialize(array); // Test serialization.
        array = Arrays.synchronizedArray(array, array);    // Test synchronized array.
        array = array.offset(1);
    }

        assertArrayEquals(new long[]{1, 1, 2, 1, 2, 3, 3, 4}, array.toArray());
        MutableLongArray backedByArray = MutableLongArray.copyOf(array);
        Arrays.reverse(backedByArray);
        array.setAll(backedByArray);
        assertArrayEquals(new long[]{4, 3, 3, 2, 1, 2, 1, 1}, array.toArray());
        LongBuffer buffer = ByteBuffer.allocateDirect(Long.SIZE / Byte.SIZE * 8).asLongBuffer();
        MutableLongArray notBackedByArray = Arrays.newMutableArray(buffer);
        notBackedByArray.setAll(backedByArray);
        array.setAll(notBackedByArray);
        assertArrayEquals(new long[]{4, 3, 3, 2, 1, 2, 1, 1}, array.toArray());
        UnboundedLongArray tooBig = UnboundedLongArray.copyOf(array);

    private BoundedLongArray array;

    @Before
    public void setUp() throws Exception {
        long[] a = new long[] {0, 1, 1, 2, 1, 2, 3, 3, 4, 0, 0};
        LongBuffer buffer = LongBuffer.wrap(a, 1, 8);
        array = BoundedLongArray.valueOf(buffer);
        array = serializeAndDeserialize(array); // Test serialization.
        long[] b = new long[11];
        array.toArray(b, 1, 8);
        buffer = LongBuffer.wrap(b, 1, 8);

        array.addLong((long) 4);
        MutableLongArray backedByArray = MutableLongArray.copyOf(array);
        Arrays.reverse(backedByArray);
        array.setAll(backedByArray);
        assertArrayEquals(new long[]{4, 3, 3, 2, 1, 2, 1, 1}, array.toArray());
        LongBuffer buffer = ByteBuffer.allocateDirect(Long.SIZE / Byte.SIZE * 8).asLongBuffer();
        MutableLongArray notBackedByArray = Arrays.newMutableArray(buffer);
        notBackedByArray.setAll(backedByArray);
        array.setAll(notBackedByArray);
        assertArrayEquals(new long[]{4, 3, 3, 2, 1, 2, 1, 1}, array.toArray());
        UnboundedLongArray bigger = UnboundedLongArray.copyOf(array);

        assertArrayEquals(new long[]{1, 1, 2, 1, 2, 3, 3, 4}, array.toArray());
    }

    @Test
    public void testAddAllNoBackingArray0() throws Exception {
        LongBuffer buffer = ByteBuffer.allocateDirect(Long.SIZE / Byte.SIZE * 10).asLongBuffer();
        buffer.position(1).limit(9);
        BoundedLongArray notBackedByArray = BoundedLongArray.valueOf(buffer);
        notBackedByArray.setAll(array);
        notBackedByArray.addAll(LongArray.unsafeValueOf());
        assertEquals(8, notBackedByArray.length());
        assertArrayEquals(new long[]{1, 1, 2, 1, 2, 3, 3, 4}, notBackedByArray.toArray());

        assertArrayEquals(new long[]{1, 1, 2, 1, 2, 3, 3, 4}, notBackedByArray.toArray());
    }

    @Test
    public void testAddAllNoBackingArray1() throws Exception {
        LongBuffer buffer = ByteBuffer.allocateDirect(Long.SIZE / Byte.SIZE * 11).asLongBuffer();
        buffer.position(1).limit(9);
        BoundedLongArray notBackedByArray = BoundedLongArray.valueOf(buffer);
        notBackedByArray.setAll(array);
        notBackedByArray.addAll(LongArray.unsafeValueOf((long) 5));
        assertEquals(9, notBackedByArray.length());
        assertArrayEquals(new long[]{1, 1, 2, 1, 2, 3, 3, 4, 5}, notBackedByArray.toArray());

        assertArrayEquals(new long[]{1, 1, 2, 1, 2, 3, 3, 4, 5}, notBackedByArray.toArray());
    }

    @Test
    public void testAddAllNoBackingArray2() throws Exception {
        LongBuffer buffer = ByteBuffer.allocateDirect(Long.SIZE / Byte.SIZE * 11).asLongBuffer();
        buffer.position(1).limit(9);
        BoundedLongArray notBackedByArray = BoundedLongArray.valueOf(buffer);
        notBackedByArray.setAll(array);
        notBackedByArray.addAll(LongArray.unsafeValueOf((long) 5, (long) 5));
        assertEquals(10, notBackedByArray.length());
        assertArrayEquals(new long[]{1, 1, 2, 1, 2, 3, 3, 4, 5, 5}, notBackedByArray.toArray());

        assertArrayEquals(new long[]{1, 1, 2, 1, 2, 3, 3, 4, 5, 5}, notBackedByArray.toArray());
    }

    @Test
    public void testAddAllNoBackingArray3() throws Exception {
        LongBuffer buffer = ByteBuffer.allocateDirect(Long.SIZE / Byte.SIZE * 11).asLongBuffer();
        buffer.position(1).limit(9);
        BoundedLongArray notBackedByArray = BoundedLongArray.valueOf(buffer);
        notBackedByArray.setAll(array);
        try {
            notBackedByArray.addAll(LongArray.unsafeValueOf((long) 5, (long) 5, (long) 5));
            fail();

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.