package bugIdeas;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class Ideas_2011_06_16 {

    static int firstByte(File f) throws IOException {
        FileInputStream fs;

        try {
            fs = new FileInputStream(f);
        } catch (FileNotFoundException e) {
            return -1;
        }
        try {
            return fs.read();
        } catch (IOException e) {
            return -2;
        } finally {
            fs.close();
        }

    }

}

@@ -12,16 +12,48 @@
 Ideas;%0A%0A
+import java.io.DataInputStream;%0A
 import j
@@ -197,16 +197,1502 @@
 6_16 %7B%0A%0A
+    public static byte%5B%5D getByteFile(String byteFileName, int n) %7B%0A        File f = new File(byteFileName);%0A%0A        if (!(f.exists() && f.isFile() && f.canRead() && f.length() == n))%0A            return null;%0A%0A        FileInputStream fs;%0A%0A        try %7B%0A            fs = new FileInputStream(f);%0A        %7D catch (FileNotFoundException e) %7B%0A            return null;%0A        %7D%0A%0A        byte%5B%5D bytes = new byte%5Bn%5D;%0A%0A        int numBytesRead = 0;%0A%0A        try %7B%0A            numBytesRead = fs.read(bytes);%0A            fs.close();%0A        %7D catch (IOException e) %7B%0A            return null;%0A        %7D%0A%0A        if (numBytesRead != n)%0A            return null;%0A%0A        return bytes;%0A%0A    %7D // end getByteFile%0A%0A    public static byte%5B%5D getByteFileFixed(String byteFileName, int n) %7B%0A        File f = new File(byteFileName);%0A%0A        if (!(f.exists() && f.isFile() && f.canRead() && f.length() == n))%0A            return null;%0A%0A        DataInputStream ds;%0A%0A        try %7B%0A            ds = new DataInputStream(new FileInputStream(f));%0A        %7D catch (FileNotFoundException e) %7B%0A            return null;%0A        %7D%0A%0A        try %7B%0A            byte%5B%5D bytes = new byte%5Bn%5D;%0A            ds.readFully(bytes);%0A            return bytes;%0A        %7D catch (IOException e) %7B%0A            return null;%0A        %7D finally %7B%0A            try %7B%0A                ds.close();%0A            %7D catch (IOException e) %7B%0A                assert true; // nothing to do at this point%0A            %7D%0A        %7D%0A%0A    %7D // end getByteFile%0A%0A
     stat

add test case showing fixed version of code