Package java.nio

Examples of java.nio.LongBuffer.order()


        assertNotSame(buf, readonly);
        assertTrue(readonly.isReadOnly());
        assertEquals(buf.position(), readonly.position());
        assertEquals(buf.limit(), readonly.limit());
        assertEquals(buf.isDirect(), readonly.isDirect());
        assertEquals(buf.order(), readonly.order());
        assertContentEquals(buf, readonly);

        // readonly's position, mark, and limit should be independent to buf
        readonly.reset();
        assertEquals(readonly.position(), 0);


        assertNotSame(buf, duplicate);
        assertEquals(buf.position(), duplicate.position());
        assertEquals(buf.limit(), duplicate.limit());
        assertEquals(buf.isReadOnly(), duplicate.isReadOnly());
        assertEquals(buf.isDirect(), duplicate.isDirect());
        assertEquals(buf.order(), duplicate.order());
        assertContentEquals(buf, duplicate);

        // duplicate's position, mark, and limit should be independent to buf
        duplicate.reset();
        assertEquals(duplicate.position(), 0);

        buf.limit(buf.capacity() - 1);

        LongBuffer 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();

        // 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())));

TOP
Copyright © 2018 www.massapi.com. 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.