Initial load
diff --git a/test/java/io/FileOutputStream/FileOpen.sh b/test/java/io/FileOutputStream/FileOpen.sh
new file mode 100644
index 0000000..d3989c1
--- /dev/null
+++ b/test/java/io/FileOutputStream/FileOpen.sh
@@ -0,0 +1,76 @@
+#!/bin/sh
+
+#
+# Copyright 2006 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 6364894
+# @run shell FileOpen.sh
+# @summary Test to ensure that opening of hidden Vs non-hidden,
+# read/write Vs read-only files for writing works as expected.
+
+
+# We use a TMP directory on a local disk because this test
+# requires that the file to be tested be present on the local disk,
+# not on a samba mounted drive or on a drive that is mapped.
+# The cmd 'attrib' works only on the local files.
+TMP="C:\TEMP"
+hfile=${TMP}"\random_file1.txt"
+ATTRIB=${SystemRoot}"\system32\attrib.exe"
+
+OS=`uname -s`
+case "$OS" in
+ Windows_* )
+ if [ ! -d ${TMP} ] ; then
+ echo "Could not find the directory-" ${TMP} "- passing test"
+ exit 0;
+ fi
+ ${TESTJAVA}/bin/javac -d . ${TESTSRC}\\FileOpenPos.java
+ ${TESTJAVA}/bin/javac -d . ${TESTSRC}\\FileOpenNeg.java
+
+ echo "Opening Writable Normal File.."
+ ${TESTJAVA}/bin/java FileOpenPos ${hfile}
+
+ echo "Opening Writable Hidden File.."
+ ${ATTRIB} +h ${hfile}
+ ${TESTJAVA}/bin/java FileOpenNeg ${hfile}
+
+ echo "Opening Read-Only Normal File.."
+ ${ATTRIB} -h ${hfile}
+ ${ATTRIB} +r ${hfile}
+ ${TESTJAVA}/bin/java FileOpenNeg ${hfile}
+
+ echo "Opening Read-Only Hidden File.."
+ ${ATTRIB} +h ${hfile}
+ ${TESTJAVA}/bin/java FileOpenNeg ${hfile}
+
+ rm -f ${hfile}
+ exit
+ ;;
+
+ * )
+ echo "This test is not intended for this OS - passing test"
+ exit 0
+ ;;
+esac
diff --git a/test/java/io/FileOutputStream/FileOpenNeg.java b/test/java/io/FileOutputStream/FileOpenNeg.java
new file mode 100644
index 0000000..ca1221a
--- /dev/null
+++ b/test/java/io/FileOutputStream/FileOpenNeg.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2006 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.
+ */
+
+import java.io.*;
+
+public class FileOpenNeg {
+
+ public static void main( String[] args) throws Exception {
+ boolean openForWrite = true;
+
+ File f = new File(args[0]);
+ try {
+ FileOutputStream fs = new FileOutputStream(f);
+ fs.write(1);
+ fs.close();
+ } catch( IOException e ) {
+ System.out.println("Caught the Exception as expected");
+ e.printStackTrace(System.out);
+ openForWrite = false;
+ }
+ if (openForWrite && !f.canWrite()) {
+ throw new Exception("Able to open READ-ONLY file for WRITING!");
+ }
+ }
+}
diff --git a/test/java/io/FileOutputStream/FileOpenPos.java b/test/java/io/FileOutputStream/FileOpenPos.java
new file mode 100644
index 0000000..39cf26c
--- /dev/null
+++ b/test/java/io/FileOutputStream/FileOpenPos.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2006 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.
+ */
+
+import java.io.*;
+
+public class FileOpenPos {
+
+ public static void main( String[] args)
+ throws IOException {
+ File f = new File(args[0]);
+ FileOutputStream fs = new FileOutputStream(f);
+ fs.write(1);
+ fs.close();
+ System.out.println("Can Write ?" + f.canWrite());
+ System.out.println("The File was successfully opened");
+ }
+}
diff --git a/test/java/io/FileOutputStream/FinalizeShdCallClose.java b/test/java/io/FileOutputStream/FinalizeShdCallClose.java
new file mode 100644
index 0000000..d3442ba
--- /dev/null
+++ b/test/java/io/FileOutputStream/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 FOS.finalize() invokes the close() method as per
+ * the specification.
+ */
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+public class FinalizeShdCallClose {
+
+ static final String FILE_NAME = "empty.txt";
+
+ public static class MyStream extends FileOutputStream {
+ 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/FileOutputStream/ManyFiles.java b/test/java/io/FileOutputStream/ManyFiles.java
new file mode 100644
index 0000000..bd2fce8
--- /dev/null
+++ b/test/java/io/FileOutputStream/ManyFiles.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2003-2004 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 4189011 5019303
+ * @summary Test opening over 2048 files
+ * @run main/timeout=300 ManyFiles
+ */
+
+import java.io.*;
+import java.util.*;
+
+public class ManyFiles {
+ static int count;
+ static List files = new ArrayList();
+ static List streams = new ArrayList();
+ static int NUM_FILES = 2050;
+
+ public static void main(String args[]) throws Exception {
+ // Linux does not yet allow opening this many files; Solaris
+ // 8 requires an explicit allocation of more file descriptors
+ // to succeed. Since this test is written to check for a
+ // Windows capability it is much simpler to only run it
+ // on that platform.
+ String osName = System.getProperty("os.name");
+ if (osName.startsWith("Linux")||osName.startsWith("SunOS"))
+ return;
+
+ for (int n = 0; n < NUM_FILES; n++) {
+ File f = new File("file" + count++);
+ files.add(f);
+ streams.add(new FileOutputStream(f));
+ }
+
+ Iterator i = streams.iterator();
+ while(i.hasNext()) {
+ FileOutputStream fos = (FileOutputStream)i.next();
+ fos.close();
+ }
+
+ i = files.iterator();
+ while(i.hasNext()) {
+ File f = (File)i.next();
+ f.delete();
+ }
+ }
+}
diff --git a/test/java/io/FileOutputStream/OpsAfterClose.java b/test/java/io/FileOutputStream/OpsAfterClose.java
new file mode 100644
index 0000000..8ea0866
--- /dev/null
+++ b/test/java/io/FileOutputStream/OpsAfterClose.java
@@ -0,0 +1,103 @@
+/**
+ * @test
+ * @bug 6359397
+ * @summary Test if FileOutputStream methods will check if the stream
+ * has been closed.
+ */
+
+import java.io.*;
+
+public enum OpsAfterClose {
+
+ WRITE { boolean check(FileOutputStream r) {
+ try {
+ r.write(1);
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true;
+ }
+ return false;
+ } },
+
+ WRITE_BUF { boolean check(FileOutputStream r) {
+ try {
+ byte buf[] = new byte[2];
+ r.write(buf);
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true;
+ }
+ return false;
+ } },
+ WRITE_BUF_OFF { boolean check(FileOutputStream r) {
+ try {
+ byte buf[] = new byte[2];
+ int len = 1;
+ r.write(buf, 0, len);
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true;
+ }
+ return false;
+ } },
+ GET_CHANNEL { boolean check(FileOutputStream r) {
+ r.getChannel();
+ return true;
+ } },
+ GET_FD { boolean check(FileOutputStream r) {
+ try {
+ r.getFD();
+ return true;
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return false;
+ }
+ } },
+ CLOSE { boolean check(FileOutputStream r) {
+ try {
+ r.close();
+ return true; // No Exceptin thrown on Windows
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true; // Exception thrown on solaris and linux
+ }
+ } };
+
+ abstract boolean check(FileOutputStream 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();
+
+ FileOutputStream fis = new FileOutputStream(f);
+ if (testFileOutputStream(fis)) {
+ throw new Exception("Test failed for some of the operation{s}" +
+ " on FileOutputStream, check the messages");
+ }
+ }
+
+ private static boolean testFileOutputStream(FileOutputStream 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 FileOutputStream:" + r);
+ }
+ return failed;
+ }
+}