Code example for DatagramChannel

Methods: configureBlocking, connect, isConnected, write

0
    // Test for write() 
    // ------------------------------------------------------------------- 
 
    private void connectWriteBuf(InetSocketAddress ipAddr, ByteBuffer buf)
            throws IOException { 
        this.channel1.connect(ipAddr);
        assertTrue(this.channel1.isConnected());
        assertEquals(CAPACITY_NORMAL, this.channel1.write(buf));
        assertEquals(0, this.channel1.write(buf));
    } 
 
    private void noconnectWrite(ByteBuffer buf) throws IOException {
        try { 
            this.channel1.write(buf);
            fail("should throw NotYetConnectedException");
        } catch (NotYetConnectedException e) {
            // correct 
        } 
    } 
 
    /* 
     * Test method for 'DatagramChannelImpl.write(ByteBuffer)' 
     */ 
    public void testWriteByteBuffer_Block() throws IOException { 
        ByteBuffer writeBuf = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
        connectWriteBuf(localAddr1, writeBuf);
    } 
 
    public void testWriteByteBuffer_NonBlock() throws IOException { 
        ByteBuffer writeBuf = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
        this.channel1.configureBlocking(false);
        connectWriteBuf(localAddr1, writeBuf);
    } 
 
    public void testWriteByteBuffer_Block_closed() throws IOException { 
        ByteBuffer writeBuf = ByteBuffer.allocateDirect(CAPACITY_NORMAL);