Code example for Buffer

Methods: capacity, limit, position

0
 * Tests for some buffers from the java.nio package. 
 */ 
public class OldAndroidNIOTest extends TestCase {
 
    void checkBuffer(Buffer b) {
        assertTrue(0 <= b.position());
        assertTrue(b.position() <= b.limit());
        assertTrue(b.limit() <= b.capacity());
    } 
 
    public void testNIO_byte_array() throws Exception { 
        // Test byte array-based buffer 
        byteBufferTest(ByteBuffer.allocate(12));
    } 
 
    public void testNIO_direct() throws Exception { 
        // Test native heap-allocated buffer 
        byteBufferTest(ByteBuffer.allocateDirect(12));
    } 
 
    public void testNIO_short_array() throws Exception {