Initial load
diff --git a/test/java/io/FileInputStream/Available.java b/test/java/io/FileInputStream/Available.java
new file mode 100644
index 0000000..ae1b3a6
--- /dev/null
+++ b/test/java/io/FileInputStream/Available.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 1998 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4129479
+ * @summary Test if available would throw an IOException
+ * when the stream is closed.
+ */
+
+import java.io.*;
+
+public class Available {
+ public static void main(String args[]) throws Exception {
+ File file = new File(System.getProperty("test.src", "."),
+ "Available.java");
+ FileInputStream fis = new FileInputStream(file);
+ fis.close();
+ try {
+ fis.available();
+ throw new Exception
+ ("available should throw an exception after stream is closed");
+ }
+ catch (IOException e) {
+ }
+ }
+}
diff --git a/test/java/io/FileInputStream/FinalizeShdCallClose.java b/test/java/io/FileInputStream/FinalizeShdCallClose.java
new file mode 100644
index 0000000..2f74bcc
--- /dev/null
+++ b/test/java/io/FileInputStream/FinalizeShdCallClose.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ *
+ * @test
+ * @bug 6524062
+ * @summary Test to ensure that FIS.finalize() invokes the close() method as per
+ * the specification.
+ */
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+public class FinalizeShdCallClose {
+
+ static final String FILE_NAME = "empty.txt";
+
+ public static class MyStream extends FileInputStream {
+ private boolean closed = false;
+
+ public MyStream(String name) throws FileNotFoundException {
+ super(name);
+ }
+
+ public void finalize() {
+ try {
+ super.finalize();
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ }
+ }
+
+ public void close() {
+ try {
+ super.close();
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ }
+ closed = true;
+ }
+
+ public boolean isClosed() {
+ return closed;
+ }
+ }
+
+ /* standalone interface */
+ public static void main(String argv[]) throws Exception {
+
+ File inFile= new File(System.getProperty("test.dir", "."), FILE_NAME);
+ inFile.createNewFile();
+ inFile.deleteOnExit();
+
+ String name = inFile.getPath();
+ MyStream ms = null;
+ try {
+ ms = new MyStream(name);
+ } catch (FileNotFoundException e) {
+ System.out.println("Unexpected exception " + e);
+ throw(e);
+ }
+ ms.finalize();
+ if (!ms.isClosed()) {
+ throw new Exception("MyStream.close() method is not called");
+ }
+ System.out.println("OK");
+ }
+}
diff --git a/test/java/io/FileInputStream/LeadingSlash.java b/test/java/io/FileInputStream/LeadingSlash.java
new file mode 100644
index 0000000..07843cc
--- /dev/null
+++ b/test/java/io/FileInputStream/LeadingSlash.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2001 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4487368
+ * @summary Test, if FileInputStream can handle
+ * a leading slash in file name.
+ */
+
+import java.io.*;
+
+public class LeadingSlash {
+ public static void main (String args[]) throws Exception {
+ if (File.separatorChar == '\\') { // Windows
+ File file = null;
+ try {
+ file = File.createTempFile("bug", "4487368");
+ new FileInputStream("\\" + file.getPath());
+ new FileOutputStream("\\" + file.getPath());
+ } finally {
+ if (file != null)
+ file.delete();
+ }
+ }
+ }
+}
diff --git a/test/java/io/FileInputStream/OpenDir.java b/test/java/io/FileInputStream/OpenDir.java
new file mode 100644
index 0000000..987a886
--- /dev/null
+++ b/test/java/io/FileInputStream/OpenDir.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 1998 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4092350
+ * @summary Attempting to open a stream on a directory should fail on
+ * all platforms.
+ *
+ */
+
+import java.io.*;
+
+public class OpenDir {
+
+ public static void main(String args[]) throws Exception {
+ // Perform the same test for FileInputStream, FileOutputStream
+ // and RandomAccessFile.
+ FileInputStream fs = null;
+ // This test attempts to FileInputStream.open(".")
+ // This should fail since . is a directory.
+ try {
+ fs = new FileInputStream(".");
+ throw new
+ Exception("FileInputStream.open should not work on dirs");
+ } catch (IOException e) {
+ }
+
+ FileOutputStream fos = null;
+ try {
+ fos = new FileOutputStream(".");
+ throw new
+ Exception("FileOutputStream.open should'nt work on dirs");
+ } catch (IOException e) {
+ }
+
+ RandomAccessFile ras = null;
+ try {
+ ras = new RandomAccessFile(".","r");
+ throw new
+ Exception("RandomAccessFile.open should'nt work on dirs");
+ } catch (IOException e) {
+ }
+ }
+
+
+}
diff --git a/test/java/io/FileInputStream/OpsAfterClose.java b/test/java/io/FileInputStream/OpsAfterClose.java
new file mode 100644
index 0000000..2a4f700
--- /dev/null
+++ b/test/java/io/FileInputStream/OpsAfterClose.java
@@ -0,0 +1,112 @@
+/**
+ * @test
+ * @bug 6359397
+ * @summary Test if FileInputStream methods will check if the stream
+ * has been closed.
+ */
+
+import java.io.*;
+
+public enum OpsAfterClose {
+
+ READ { boolean check(FileInputStream r) {
+ try {
+ r.read();
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true;
+ }
+ return false;
+ } },
+
+ READ_BUF { boolean check(FileInputStream r) {
+ try {
+ byte buf[] = new byte[2];
+ r.read(buf);
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true;
+ }
+ return false;
+ } },
+ READ_BUF_OFF { boolean check(FileInputStream r) {
+ try {
+ byte buf[] = new byte[2];
+ int len = 1;
+ r.read(buf, 0, len);
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true;
+ }
+ return false;
+ } },
+ GET_CHANNEL { boolean check(FileInputStream r) {
+ r.getChannel();
+ return true;
+ } },
+ GET_FD { boolean check(FileInputStream r) {
+ try {
+ r.getFD();
+ return true;
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return false;
+ }
+ } },
+ SKIP { boolean check(FileInputStream r) {
+ try {
+ r.skip(1);
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true;
+ }
+ return false;
+ } },
+ CLOSE { boolean check(FileInputStream r) {
+ try {
+ r.close();
+ return true; // No Exception thrown on windows
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true; // Exception thrown on solaris and linux
+ }
+ } };
+
+ abstract boolean check(FileInputStream r);
+
+ public static void main(String args[]) throws Exception {
+
+ boolean failed = false;
+
+ File f = new File(System.getProperty("test.dir", "."),
+ "f.txt");
+ f.createNewFile();
+ f.deleteOnExit();
+
+ FileInputStream fis = new FileInputStream(f);
+ if (testFileInputStream(fis)) {
+ throw new Exception("Test failed for some of the operation{s}" +
+ " on FileInputStream, check the messages");
+ }
+ }
+
+ private static boolean testFileInputStream(FileInputStream r)
+ throws Exception {
+ r.close();
+ boolean failed = false;
+ boolean result;
+ System.out.println("Testing File:" + r);
+ for (OpsAfterClose op : OpsAfterClose.values()) {
+ result = op.check(r);
+ if (!result) {
+ failed = true;
+ }
+ System.out.println(op + ":" + result);
+ }
+ if (failed) {
+ System.out.println("Test failed for the failed operation{s}" +
+ " above for the FileInputStream:" + r);
+ }
+ return failed;
+ }
+}