Initial load
diff --git a/test/java/io/OutputStreamWriter/BoundsCheck.java b/test/java/io/OutputStreamWriter/BoundsCheck.java
new file mode 100644
index 0000000..341ba63
--- /dev/null
+++ b/test/java/io/OutputStreamWriter/BoundsCheck.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 1999 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 4221901
+ * @summary Ensure that negative offset or negative len parameter for
+ * write(String str, int off, int len) throws
+ * IndexOutOfBoundsException.
+ */
+
+import java.io.*;
+
+public class BoundsCheck {
+ public static void main(String args[]) throws Exception {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ OutputStreamWriter osw = new OutputStreamWriter(bos);
+ String data = "Data to be written";
+ char cdata[] = {'a', 'b', 'c', 'd', 'a', 'b', 'c', 'd'};
+
+ boolean caughtException = false;
+ try {
+ osw.write(data, -3, 5);
+ throw new RuntimeException("Test failed for negative offset");
+ } catch (IndexOutOfBoundsException e){ }
+
+ try {
+ osw.write(data, 3, -5);
+ throw new RuntimeException("Test failed for negative length");
+ } catch (IndexOutOfBoundsException e){ }
+
+ try {
+ osw.write(data, 3, 75);
+ throw new RuntimeException("Test failed for len+off > str.length");
+ } catch (IndexOutOfBoundsException e){ }
+
+ try {
+ osw.write(cdata, -3, 5);
+ throw new RuntimeException("Test failed for negative offset");
+ } catch (IndexOutOfBoundsException e){ }
+
+ try {
+ osw.write(cdata, 3, -5);
+ throw new RuntimeException("Test failed for negative length");
+ } catch (IndexOutOfBoundsException e){ }
+
+ try {
+ osw.write(cdata, 3, 75);
+ throw new RuntimeException("Test failed for len+off > str.length");
+ } catch (IndexOutOfBoundsException e){ }
+ }
+}
diff --git a/test/java/io/OutputStreamWriter/Encode.java b/test/java/io/OutputStreamWriter/Encode.java
new file mode 100644
index 0000000..7e71ca1
--- /dev/null
+++ b/test/java/io/OutputStreamWriter/Encode.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2003 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 4802209
+ * @summary check that the right utf-8 encoder is used
+ */
+
+import java.io.*;
+import java.net.*;
+
+public class Encode implements Runnable {
+ public static void main(String args[]) throws Exception {
+ new Encode();
+ }
+
+ Encode() throws Exception {
+ ss = new ServerSocket(0);
+ (new Thread(this)).start();
+ String toEncode = "\uD800\uDC00 \uD801\uDC01 ";
+ String enc1 = URLEncoder.encode(toEncode, "UTF-8");
+ byte bytes[] = {};
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+ InputStreamReader reader = new InputStreamReader( bais, "8859_1");
+ String url = "http://localhost:" + Integer.toString(ss.getLocalPort()) +
+ "/missing.nothtml";
+ HttpURLConnection uc = (HttpURLConnection)new URL(url).openConnection();
+ uc.connect();
+ String enc2 = URLEncoder.encode(toEncode, "UTF-8");
+ if (!enc1.equals(enc2))
+ throw new RuntimeException("test failed");
+ uc.disconnect();
+ }
+
+ ServerSocket ss;
+
+ public void run() {
+ try {
+ Socket s = ss.accept();
+ BufferedReader in = new BufferedReader(
+ new InputStreamReader(s.getInputStream()));
+ String req = in.readLine();
+ PrintStream out = new PrintStream(new BufferedOutputStream(
+ s.getOutputStream()));
+ out.print("HTTP/1.1 403 Forbidden\r\n");
+ out.print("\r\n");
+ out.flush();
+ s.close();
+ ss.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/test/java/io/OutputStreamWriter/NullCreate.java b/test/java/io/OutputStreamWriter/NullCreate.java
new file mode 100644
index 0000000..668c111
--- /dev/null
+++ b/test/java/io/OutputStreamWriter/NullCreate.java
@@ -0,0 +1,45 @@
+/*
+ * 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 4149935
+ * @summary Create with a null stream should throw an exception
+ */
+
+import java.io.*;
+
+public class NullCreate {
+
+ public static void main(String args[])
+ {
+ try{
+ OutputStreamWriter osw = new OutputStreamWriter(null);
+ } catch (NullPointerException e){
+ // No problem - null create argument caught
+ return;
+ }
+ throw new RuntimeException("Create with null did not throw an error");
+ }
+
+}
diff --git a/test/java/io/OutputStreamWriter/TestWrite.java b/test/java/io/OutputStreamWriter/TestWrite.java
new file mode 100644
index 0000000..f5dd5dd
--- /dev/null
+++ b/test/java/io/OutputStreamWriter/TestWrite.java
@@ -0,0 +1,56 @@
+/*
+ * 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 4066847 4147276 4131647
+ * @summary Check for flush of output buffer before concluding it is too small
+ */
+
+import java.io.*;
+
+public class TestWrite {
+
+ public static void main(String args[])
+ throws Exception
+ {
+ ByteArrayOutputStream bos;
+ OutputStreamWriter osw;
+ byte[] array;
+
+ try{
+ bos = new ByteArrayOutputStream();
+ osw = new OutputStreamWriter(bos, "EUCJIS");
+ osw.write('a');
+ for(int count = 0; count < 10000; ++count)
+ osw.write('\u3042'); // Hiragana
+ osw.close();
+ array = bos.toByteArray();
+ } catch (UnsupportedEncodingException e){
+ System.err.println("Unsupported encoding - EUCJIS. ext "
+ + " may not be properly installed. ext is "
+ + " required for the test to run properly ");
+ throw new Exception("Environment is incorrect");
+ }
+ }
+}
diff --git a/test/java/io/OutputStreamWriter/WriteAfterClose.java b/test/java/io/OutputStreamWriter/WriteAfterClose.java
new file mode 100644
index 0000000..a9bfcd6
--- /dev/null
+++ b/test/java/io/OutputStreamWriter/WriteAfterClose.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright 1998-2005 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 4143651 5085148
+ *
+ * @summary Test if Writer methods will check if the stream
+ * has been closed.
+ */
+
+import java.io.*;
+
+public class WriteAfterClose {
+
+ static boolean failed = false;
+
+ static void testWrite(Writer wtr) throws Exception {
+
+ // These tests could be tighted to only check for a particular
+ // kind of exception, but in 1.2beta4 StringWriter and
+ // other writers throw RuntimeExceptions
+ char[] cbuf = new char[2];
+ wtr.close();
+ System.out.println("Class " + wtr.getClass().getName());
+
+ try {
+ wtr.write('a');
+ System.out.println("FAILED: Allows char write on a closed stream");
+ failed = true;
+ } catch (Exception e) {
+ }
+
+ try {
+ wtr.write(cbuf, 0, 1);
+ System.out.println("FAILED: Allows buffer write on a closed stream");
+ failed = true;
+ } catch (Exception e) {
+ }
+
+ try {
+ wtr.write(cbuf, 0, 0);
+ System.out.println("FAILED: Allows empty write on a closed stream");
+ failed = true;
+ } catch (Exception e) {
+ }
+
+ try {
+ wtr.write("a");
+ System.out.println("FAILED: Allows string write on a closed stream");
+ failed = true;
+ } catch (Exception e) {
+ }
+
+ try {
+ wtr.write("a", 0, 1);
+ System.out.println("FALIED: Allows string buf write on a closed stream");
+ failed = true;
+ } catch (Exception e) {
+ }
+
+ try {
+ wtr.flush();
+ System.out.println("FAILED: Allows flushing writer on a closed stream");
+ failed = true;
+ } catch (Exception e) {
+ }
+
+ wtr.close();
+ }
+
+ public static void main(String argv[]) throws Exception {
+ StringWriter sw = new StringWriter();
+ testWrite(new BufferedWriter(sw));
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ OutputStreamWriter osw = new OutputStreamWriter(bos);
+ testWrite(osw);
+
+ File f = new File(System.getProperty("test.dir", "."),
+ "NewFile");
+ f.createNewFile();
+ f.deleteOnExit();
+ FileWriter fr = new FileWriter(f);
+ testWrite(fr);
+
+ if (failed) {
+ throw new Exception("The test failed because one of the"
+ + " writer operation{s} failed. Check the messages");
+ }
+ }
+}