Code example for ClosedChannelException

    // -1 will be returned if there is nothing to read; higher-level methods like readInt 
    // or readFully (from RandomAccessFile) will throw EOFException but this should not 
    public int read(byte[] buff, int offset, int length) throws IOException
        if (buffer == null)
            throw new ClosedChannelException();
        if (length == 0)
            return 0; 
        if (isEOF()) 
            return -1; 
        if (current >= bufferOffset + buffer.length || validBufferBytes == -1)
        assert current >= bufferOffset && current < bufferOffset + validBufferBytes
                : String.format("File (%s), current offset %d, buffer offset %d, buffer limit %d",
Stop searching for code, let great code find you!  Add Codota to your java IDE