Code example for DatagramChannel

Methods: configureBlocking, connect, isConnected, write

0
    public void testWriteByteBuffer_NonBlock_BufNull() throws IOException { 
        ByteBuffer writeBuf = ByteBuffer.allocateDirect(0);
        InetSocketAddress ipAddr = localAddr1;
 
        // non block mode 
        this.channel1.configureBlocking(false);
 
        try { 
            this.channel1.write((ByteBuffer) null);
            fail("Should throw NPE.");
        } catch (NullPointerException e) {
            // correct 
        } 
        this.channel1.connect(ipAddr);
        assertTrue(this.channel1.isConnected());
        try { 
            this.channel1.write((ByteBuffer) null);
            fail("Should throw NPE.");
        } catch (NullPointerException e) {
            // correct 
        } 
        assertEquals(0, this.channel1.write(writeBuf));
        datagramSocket1.close();
        try { 
            this.channel1.write((ByteBuffer) null);
            fail("Should throw NPE.");
        } catch (NullPointerException e) {
            // correct 
        } 
    }