Code example for SocketTimeoutException

0
                throw new SocketException("SocketChannel not connected on some reason");
            } 
            return true; 
        } 
        //log.debug("Spent " + (System.currentTimeMillis() - start)); 
        throw new SocketTimeoutException("Failed to connect to " + remote.toString());
    } 
 
    @Override 
    public int read(ByteBuffer dst) throws IOException {
        int bytesRead = 0;
        while (selector.select(readTimeout) > 0) {
            selector.selectedKeys().remove(channelKey);
            int cnt = socketChannel.read(dst);
            if (cnt < 1) {
                if (bytesRead < 1) {
                    bytesRead = -1;
                } 
                //log.info("Bytes read: "+bytesRead); 
                return bytesRead;
            } else {