0N/A/**
0N/A * @test
0N/A * @bug 6359397
0N/A * @summary Test if FileInputStream methods will check if the stream
0N/A * has been closed.
0N/A */
0N/A
0N/Aimport java.io.*;
0N/A
0N/Apublic enum OpsAfterClose {
0N/A
0N/A READ { boolean check(FileInputStream r) {
0N/A try {
0N/A r.read();
0N/A } catch (IOException io) {
0N/A System.out.print("Excep Msg: "+ io.getMessage() + ", ");
0N/A return true;
0N/A }
0N/A return false;
0N/A } },
0N/A
0N/A READ_BUF { boolean check(FileInputStream r) {
0N/A try {
0N/A byte buf[] = new byte[2];
0N/A r.read(buf);
0N/A } catch (IOException io) {
0N/A System.out.print("Excep Msg: "+ io.getMessage() + ", ");
0N/A return true;
0N/A }
0N/A return false;
0N/A } },
0N/A READ_BUF_OFF { boolean check(FileInputStream r) {
0N/A try {
0N/A byte buf[] = new byte[2];
0N/A int len = 1;
0N/A r.read(buf, 0, len);
0N/A } catch (IOException io) {
0N/A System.out.print("Excep Msg: "+ io.getMessage() + ", ");
0N/A return true;
0N/A }
0N/A return false;
0N/A } },
0N/A GET_CHANNEL { boolean check(FileInputStream r) {
0N/A r.getChannel();
0N/A return true;
0N/A } },
0N/A GET_FD { boolean check(FileInputStream r) {
0N/A try {
0N/A r.getFD();
0N/A return true;
0N/A } catch (IOException io) {
0N/A System.out.print("Excep Msg: "+ io.getMessage() + ", ");
0N/A return false;
0N/A }
0N/A } },
0N/A SKIP { boolean check(FileInputStream r) {
0N/A try {
0N/A r.skip(1);
0N/A } catch (IOException io) {
0N/A System.out.print("Excep Msg: "+ io.getMessage() + ", ");
0N/A return true;
0N/A }
0N/A return false;
0N/A } },
0N/A CLOSE { boolean check(FileInputStream r) {
0N/A try {
0N/A r.close();
0N/A return true; // No Exception thrown on windows
0N/A } catch (IOException io) {
0N/A System.out.print("Excep Msg: "+ io.getMessage() + ", ");
0N/A return true; // Exception thrown on solaris and linux
0N/A }
0N/A } };
0N/A
0N/A abstract boolean check(FileInputStream r);
0N/A
0N/A public static void main(String args[]) throws Exception {
0N/A
0N/A boolean failed = false;
0N/A
0N/A File f = new File(System.getProperty("test.dir", "."),
0N/A "f.txt");
0N/A f.createNewFile();
0N/A f.deleteOnExit();
0N/A
0N/A FileInputStream fis = new FileInputStream(f);
0N/A if (testFileInputStream(fis)) {
0N/A throw new Exception("Test failed for some of the operation{s}" +
0N/A " on FileInputStream, check the messages");
0N/A }
0N/A }
0N/A
0N/A private static boolean testFileInputStream(FileInputStream r)
0N/A throws Exception {
0N/A r.close();
0N/A boolean failed = false;
0N/A boolean result;
0N/A System.out.println("Testing File:" + r);
0N/A for (OpsAfterClose op : OpsAfterClose.values()) {
0N/A result = op.check(r);
0N/A if (!result) {
0N/A failed = true;
0N/A }
0N/A System.out.println(op + ":" + result);
0N/A }
0N/A if (failed) {
0N/A System.out.println("Test failed for the failed operation{s}" +
0N/A " above for the FileInputStream:" + r);
0N/A }
0N/A return failed;
0N/A }
0N/A}