lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dmitry Serebrennikov <dmit...@earthlink.net>
Subject Re: FSInputStream strangeness
Date Sun, 21 Sep 2003 05:56:43 GMT
Here's a quick program to demonstrate what I mean:

    private void demo_FSInputStreamBug(FSDirectory fsdir, String file)
    throws IOException
    {
        // Setup the test file - we need more than 1024 bytes
        OutputStream os = fsdir.createFile(file);
        for(int i=0; i<2000; i++) {
            os.writeByte((byte) i);
        }
        os.close();
       
        InputStream in = fsdir.openFile(file);
       
        // This read primes the buffer in InputStream
        byte b = in.readByte();
       
        // Close the file
        in.close();
       
        // ERROR: this call should fail, but succeeds because the buffer
        // is still filled
        b = in.readByte();

        // ERROR: this call should fail, but succeeds for some reason as 
well
        in.seek(1099);
       
        try {
            // OK: this call correctly fails. We are now past the 1024 
internal
            // buffer, so an actual IO is attempted, which fails
            b = in.readByte();
        } catch (IOException e) {
        }
    }



Mime
View raw message