Search in sources :

Example 26 with ReadOnlyBufferException

use of java.nio.ReadOnlyBufferException in project robovm by robovm.

the class ByteBufferTest method testPutByteBuffer.

/*
     * Class under test for java.nio.ByteBuffer put(java.nio.ByteBuffer)
     */
public void testPutByteBuffer() {
    ByteBuffer other = ByteBuffer.allocate(buf.capacity());
    if (buf.isReadOnly()) {
        try {
            buf.clear();
            buf.put(other);
            //$NON-NLS-1$
            fail("Should throw Exception");
        } catch (ReadOnlyBufferException e) {
        // expected
        }
        try {
            buf.clear();
            buf.put((ByteBuffer) null);
            //$NON-NLS-1$
            fail("Should throw Exception");
        } catch (ReadOnlyBufferException e) {
        // expected
        }
        return;
    }
    try {
        buf.put(buf);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (IllegalArgumentException e) {
    // expected
    }
    try {
        buf.put(ByteBuffer.allocate(buf.capacity() + 1));
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (BufferOverflowException e) {
    // expected
    }
    try {
        buf.put((ByteBuffer) null);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (NullPointerException e) {
    // expected
    }
    loadTestData2(other);
    other.clear();
    buf.clear();
    ByteBuffer ret = buf.put(other);
    assertEquals(other.position(), other.capacity());
    assertEquals(buf.position(), buf.capacity());
    assertContentEquals(other, buf);
    assertSame(ret, buf);
}
Also used : ReadOnlyBufferException(java.nio.ReadOnlyBufferException) BufferOverflowException(java.nio.BufferOverflowException) ByteBuffer(java.nio.ByteBuffer)

Example 27 with ReadOnlyBufferException

use of java.nio.ReadOnlyBufferException in project robovm by robovm.

the class ByteBufferTest method testPutbyte.

/*
     * Class under test for java.nio.ByteBuffer put(byte)
     */
public void testPutbyte() {
    if (buf.isReadOnly()) {
        try {
            buf.clear();
            buf.put((byte) 0);
            //$NON-NLS-1$
            fail("Should throw Exception");
        } catch (ReadOnlyBufferException e) {
        // expected
        }
        return;
    }
    buf.clear();
    for (int i = 0; i < buf.capacity(); i++) {
        assertEquals(buf.position(), i);
        ByteBuffer ret = buf.put((byte) i);
        assertEquals(buf.get(i), (byte) i);
        assertSame(ret, buf);
    }
    try {
        buf.put((byte) 0);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (BufferOverflowException e) {
    // expected
    }
}
Also used : ReadOnlyBufferException(java.nio.ReadOnlyBufferException) BufferOverflowException(java.nio.BufferOverflowException) ByteBuffer(java.nio.ByteBuffer)

Example 28 with ReadOnlyBufferException

use of java.nio.ReadOnlyBufferException in project robovm by robovm.

the class ByteBufferTest method testCompact.

public void testCompact() {
    if (buf.isReadOnly()) {
        try {
            buf.compact();
            //$NON-NLS-1$
            fail("Should throw Exception");
        } catch (ReadOnlyBufferException e) {
        // expected
        }
        return;
    }
    // case: buffer is full
    buf.clear();
    buf.mark();
    loadTestData1(buf);
    ByteBuffer ret = buf.compact();
    assertSame(ret, buf);
    assertEquals(buf.position(), buf.capacity());
    assertEquals(buf.limit(), buf.capacity());
    assertContentLikeTestData1(buf, 0, (byte) 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, (byte) 0, buf.capacity());
    try {
        buf.reset();
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (InvalidMarkException e) {
    // expected
    }
    // case: normal
    assertTrue(buf.capacity() > SMALL_TEST_LENGTH);
    buf.position(1);
    buf.limit(SMALL_TEST_LENGTH);
    buf.mark();
    ret = buf.compact();
    assertSame(ret, buf);
    assertEquals(buf.position(), 4);
    assertEquals(buf.limit(), buf.capacity());
    assertContentLikeTestData1(buf, 0, (byte) 1, 4);
    try {
        buf.reset();
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (InvalidMarkException e) {
    // expected
    }
}
Also used : ReadOnlyBufferException(java.nio.ReadOnlyBufferException) ByteBuffer(java.nio.ByteBuffer) InvalidMarkException(java.nio.InvalidMarkException)

Example 29 with ReadOnlyBufferException

use of java.nio.ReadOnlyBufferException in project robovm by robovm.

the class CharBufferTest method testReadOnlyMap.

public void testReadOnlyMap() throws IOException {
    CharBuffer cb = CharBuffer.wrap("ABCDE").asReadOnlyBuffer();
    CharSequence cs = "String";
    try {
        cb.append('A');
        fail("should throw ReadOnlyBufferException.");
    } catch (ReadOnlyBufferException ex) {
    // expected;
    }
    try {
        cb.append(cs);
        fail("should throw ReadOnlyBufferException.");
    } catch (ReadOnlyBufferException ex) {
    // expected;
    }
    try {
        cb.append(cs, 1, 2);
        fail("should throw ReadOnlyBufferException.");
    } catch (ReadOnlyBufferException ex) {
    // expected;
    }
    cb.append(cs, 1, 1);
}
Also used : ReadOnlyBufferException(java.nio.ReadOnlyBufferException) CharBuffer(java.nio.CharBuffer)

Example 30 with ReadOnlyBufferException

use of java.nio.ReadOnlyBufferException in project robovm by robovm.

the class ReadOnlyCharBufferTest method testPutCharBuffer.

public void testPutCharBuffer() {
    CharBuffer other = CharBuffer.allocate(1);
    try {
        buf.put(other);
        //$NON-NLS-1$
        fail("Should throw ReadOnlyBufferException");
    } catch (ReadOnlyBufferException e) {
    // expected
    }
    try {
        buf.put((CharBuffer) null);
        //$NON-NLS-1$
        fail("Should throw ReadOnlyBufferException");
    } catch (ReadOnlyBufferException e) {
    // expected
    }
    try {
        buf.put(buf);
        //$NON-NLS-1$
        fail("Should throw ReadOnlyBufferException");
    } catch (ReadOnlyBufferException e) {
    // expected
    }
}
Also used : ReadOnlyBufferException(java.nio.ReadOnlyBufferException) CharBuffer(java.nio.CharBuffer)

Aggregations

ReadOnlyBufferException (java.nio.ReadOnlyBufferException)35 ByteBuffer (java.nio.ByteBuffer)22 SSLException (javax.net.ssl.SSLException)10 IOException (java.io.IOException)7 SSLEngineResult (javax.net.ssl.SSLEngineResult)7 SSLEngine (javax.net.ssl.SSLEngine)6 BufferOverflowException (java.nio.BufferOverflowException)5 KeyManagementException (java.security.KeyManagementException)5 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 CharBuffer (java.nio.CharBuffer)4 KnownFailure (dalvik.annotation.KnownFailure)3 BufferUnderflowException (java.nio.BufferUnderflowException)3 ByteBuf (io.netty.buffer.ByteBuf)2 MappedByteBuffer (java.nio.MappedByteBuffer)2 AlgorithmParameterSpec (java.security.spec.AlgorithmParameterSpec)2 Cipher (javax.crypto.Cipher)2 ShortBufferException (javax.crypto.ShortBufferException)2 IvParameterSpec (javax.crypto.spec.IvParameterSpec)2 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)2 SSLPeerUnverifiedException (javax.net.ssl.SSLPeerUnverifiedException)2