Code example for SocketChannel

Methods: readsocket

0
    public abstract void setContextData(Object data);
 
    protected byte[] doRead(ByteBuffer buffer) throws IOException, ReadNotCompleteException
    {         
        SocketChannel socketChannel = stream_.getStream();
        int bytesRead = socketChannel.read(buffer);     
        if ( bytesRead == -1 && buffer.remaining() > 0 )
        {             
            throw new IOException("Reached an EOL or something bizzare occured. Reading from: " + socketChannel.socket().getInetAddress() + " BufferSizeRemaining: " + buffer.remaining());
        } 
        if ( buffer.remaining() == 0 )
        { 
            morphState(); 
        } 
        else 
        {             
            throw new ReadNotCompleteException("Specified number of bytes have not been read from the Socket Channel"); 
        } 
        return new byte[0]; 
    } 
Stop searching for code, let great code find you!  Add Codota to your java IDE