Code example for DatagramChannel

Methods: configureBlocking, connect, isConnected, read

0
 
    public void testReadByteBuffer_bufNull() throws IOException { 
        ByteBuffer readBuf = ByteBuffer.allocateDirect(0);
        InetSocketAddress ipAddr = localAddr1;
        try { 
            this.channel1.read(readBuf);
            fail("should throw NotYetConnectedException");
        } catch (NotYetConnectedException e) {
            // correct 
        } 
        this.channel1.connect(ipAddr);
        assertTrue(this.channel1.isConnected());
        try { 
            channel1.read((ByteBuffer) null);
            fail("should throw NPE");
        } catch (NullPointerException e) {
            // correct 
        } 
        this.channel1.configureBlocking(false);
        // note : blocking-mode will make the read process endless! 
        assertEquals(0, this.channel1.read(readBuf));
        datagramSocket1.close();
    } 
 
    /* 
     * Test method for 'DatagramChannelImpl.read(ByteBuffer[], int, int)'