Search in sources :

Example 86 with DoubleBuffer

use of java.nio.DoubleBuffer in project j2objc by google.

the class DoubleBufferTest method testSlice.

public void testSlice() {
    assertTrue(buf.capacity() > 5);
    buf.position(1);
    buf.limit(buf.capacity() - 1);
    DoubleBuffer slice = buf.slice();
    assertEquals(buf.isReadOnly(), slice.isReadOnly());
    assertEquals(buf.isDirect(), slice.isDirect());
    assertEquals(buf.order(), slice.order());
    assertEquals(slice.position(), 0);
    assertEquals(slice.limit(), buf.remaining());
    assertEquals(slice.capacity(), buf.remaining());
    try {
        slice.reset();
        // $NON-NLS-1$
        fail("Should throw Exception");
    } catch (InvalidMarkException e) {
    // expected
    }
    // FIXME:
    if (!slice.isReadOnly()) {
        loadTestData1(slice);
        assertContentLikeTestData1(buf, 1, 0, slice.capacity());
        buf.put(2, 500);
        assertEquals(slice.get(1), 500, 0.0);
    }
}
Also used : DoubleBuffer(java.nio.DoubleBuffer) InvalidMarkException(java.nio.InvalidMarkException)

Example 87 with DoubleBuffer

use of java.nio.DoubleBuffer in project j2objc by google.

the class DoubleBufferTest method testCompact.

public void testCompact() {
    // case: buffer is full
    buf.clear();
    buf.mark();
    loadTestData1(buf);
    DoubleBuffer ret = buf.compact();
    assertSame(ret, buf);
    assertEquals(buf.position(), buf.capacity());
    assertEquals(buf.limit(), buf.capacity());
    assertContentLikeTestData1(buf, 0, 0.0, buf.capacity());
    try {
        buf.reset();
        // $NON-NLS-1$
        fail("Should throw Exception");
    } catch (InvalidMarkException e) {
    // expected
    }
    // case: buffer is empty
    buf.position(0);
    buf.limit(0);
    buf.mark();
    ret = buf.compact();
    assertSame(ret, buf);
    assertEquals(buf.position(), 0);
    assertEquals(buf.limit(), buf.capacity());
    assertContentLikeTestData1(buf, 0, 0.0, buf.capacity());
    try {
        buf.reset();
        // $NON-NLS-1$
        fail("Should throw Exception");
    } catch (InvalidMarkException e) {
    // expected
    }
    // case: normal
    assertTrue(buf.capacity() > 5);
    buf.position(1);
    buf.limit(5);
    buf.mark();
    ret = buf.compact();
    assertSame(ret, buf);
    assertEquals(buf.position(), 4);
    assertEquals(buf.limit(), buf.capacity());
    assertContentLikeTestData1(buf, 0, 1.0, 4);
    try {
        buf.reset();
        // $NON-NLS-1$
        fail("Should throw Exception");
    } catch (InvalidMarkException e) {
    // expected
    }
}
Also used : DoubleBuffer(java.nio.DoubleBuffer) InvalidMarkException(java.nio.InvalidMarkException)

Example 88 with DoubleBuffer

use of java.nio.DoubleBuffer in project j2objc by google.

the class DoubleBufferTest method testPutdoubleArray.

/*
     * Class under test for java.nio.DoubleBuffer put(double[])
     */
public void testPutdoubleArray() {
    double[] array = new double[1];
    buf.clear();
    for (int i = 0; i < buf.capacity(); i++) {
        assertEquals(buf.position(), i);
        array[0] = (double) i;
        DoubleBuffer ret = buf.put(array);
        assertEquals(buf.get(i), (double) i, 0.0);
        assertSame(ret, buf);
    }
    try {
        buf.put(array);
        // $NON-NLS-1$
        fail("Should throw Exception");
    } catch (BufferOverflowException e) {
    // expected
    }
}
Also used : DoubleBuffer(java.nio.DoubleBuffer) BufferOverflowException(java.nio.BufferOverflowException)

Example 89 with DoubleBuffer

use of java.nio.DoubleBuffer in project j2objc by google.

the class BufferTest method testBuffersIndependentLimit.

private void testBuffersIndependentLimit(ByteBuffer b) {
    CharBuffer c = b.asCharBuffer();
    b.limit(b.capacity());
    c.put(1, (char) 1);
    b.limit(0);
    c.put(1, (char) 1);
    b.limit(b.capacity());
    ShortBuffer s = b.asShortBuffer();
    b.limit(b.capacity());
    s.put(1, (short) 1);
    b.limit(0);
    s.put(1, (short) 1);
    b.limit(b.capacity());
    IntBuffer i = b.asIntBuffer();
    i.put(1, (int) 1);
    b.limit(0);
    i.put(1, (int) 1);
    b.limit(b.capacity());
    LongBuffer l = b.asLongBuffer();
    l.put(1, (long) 1);
    b.limit(0);
    l.put(1, (long) 1);
    b.limit(b.capacity());
    FloatBuffer f = b.asFloatBuffer();
    f.put(1, (float) 1);
    b.limit(0);
    f.put(1, (float) 1);
    b.limit(b.capacity());
    DoubleBuffer d = b.asDoubleBuffer();
    d.put(1, (double) 1);
    b.limit(0);
    d.put(1, (double) 1);
}
Also used : DoubleBuffer(java.nio.DoubleBuffer) LongBuffer(java.nio.LongBuffer) IntBuffer(java.nio.IntBuffer) CharBuffer(java.nio.CharBuffer) FloatBuffer(java.nio.FloatBuffer) ShortBuffer(java.nio.ShortBuffer)

Example 90 with DoubleBuffer

use of java.nio.DoubleBuffer in project jna by java-native-access.

the class PointerBufferTest method testDoubleBufferPut.

public void testDoubleBufferPut() {
    final double MAGIC = 1234.5678;
    Memory m = new Memory(8);
    ByteBuffer buf = m.getByteBuffer(0, m.size()).order(ByteOrder.nativeOrder());
    DoubleBuffer db = buf.asDoubleBuffer();
    db.put(MAGIC).flip();
    assertEquals("Int not written to memory", MAGIC, m.getDouble(0), 0d);
}
Also used : DoubleBuffer(java.nio.DoubleBuffer) ByteBuffer(java.nio.ByteBuffer)

Aggregations

DoubleBuffer (java.nio.DoubleBuffer)162 ByteBuffer (java.nio.ByteBuffer)39 FloatBuffer (java.nio.FloatBuffer)26 IntBuffer (java.nio.IntBuffer)25 ShortBuffer (java.nio.ShortBuffer)22 LongBuffer (java.nio.LongBuffer)14 CharBuffer (java.nio.CharBuffer)11 BufferOverflowException (java.nio.BufferOverflowException)8 IOException (java.io.IOException)5 BufferUnderflowException (java.nio.BufferUnderflowException)5 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 ServerDenseDoubleRow (com.tencent.angel.ps.impl.matrix.ServerDenseDoubleRow)4 Test (org.junit.Test)4 InvalidMarkException (java.nio.InvalidMarkException)3 Random (java.util.Random)3 BytePointer (org.bytedeco.javacpp.BytePointer)3 DoublePointer (org.bytedeco.javacpp.DoublePointer)3 FloatPointer (org.bytedeco.javacpp.FloatPointer)3 IntPointer (org.bytedeco.javacpp.IntPointer)3