Code example for DatagramChannel

Methods: close, configureBlocking, connect, isConnected, read

0
     * Test method for 'DatagramChannelImpl.read(ByteBuffer)' 
     */ 
    public void testReadByteBuffer() throws IOException { 
        ByteBuffer readBuf = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
        try { 
            this.channel1.read(readBuf);
            fail("should throw NotYetConnectedException");
        } catch (NotYetConnectedException e) {
            // correct 
        } 
        this.channel1.connect(localAddr1);
        assertTrue(this.channel1.isConnected());
        this.channel1.configureBlocking(false);
        // note : blocking-mode will make the read process endless! 
        assertEquals(0, this.channel1.read(readBuf));
        this.channel1.close();
        try { 
            this.channel1.read(readBuf);
            fail("Should throw ClosedChannelException");
        } catch (ClosedChannelException e) {
            // OK. 
        } 
    }