Initial load
diff --git a/test/java/io/BufferedReader/BigMark.java b/test/java/io/BufferedReader/BigMark.java
new file mode 100644
index 0000000..c4207d9
--- /dev/null
+++ b/test/java/io/BufferedReader/BigMark.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 1997-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
+ @summary BufferedReader should throw an OutOfMemoryError when the
+ read-ahead limit is very large
+ @bug 6350733
+*/
+
+import java.io.*;
+
+
+public class BigMark {
+
+ public static void main(String[] args) throws IOException {
+ String line;
+ int i = 0;
+ String dir = System.getProperty("test.src", ".");
+ BufferedReader br
+ = new BufferedReader(new FileReader(new File(dir, "BigMark.java")), 100);
+
+ br.mark(200);
+ line = br.readLine();
+ System.err.println(i + ": " + line);
+ i++;
+
+ try {
+ // BR.fill() call to new char[Integer.MAX_VALUE] should succeed
+ br.mark(Integer.MAX_VALUE);
+ line = br.readLine();
+ } catch (OutOfMemoryError x) {
+ x.printStackTrace();
+ throw x;
+ }
+ System.out.println("OutOfMemoryError not thrown as expected");
+ }
+
+}
diff --git a/test/java/io/BufferedReader/EOL.java b/test/java/io/BufferedReader/EOL.java
new file mode 100644
index 0000000..d6bda3a
--- /dev/null
+++ b/test/java/io/BufferedReader/EOL.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 1997 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 4072575
+ @summary Test all the EOL delimiters accepted by BufferedReader
+*/
+
+import java.io.*;
+
+public class EOL {
+
+ public static void main(String[] args) throws IOException {
+ Reader sr = new StringReader("one\rtwo\r\nthree\nfour\r");
+ BufferedReader br = new BufferedReader(sr);
+ for (int i = 0;; i++) {
+ String l = br.readLine();
+ if (l == null) {
+ if (i != 4)
+ throw new RuntimeException("Expected 4 lines, got " + i);
+ break;
+ }
+ System.err.println(i + ": " + l);
+ }
+ }
+
+}
diff --git a/test/java/io/BufferedReader/Fill.java b/test/java/io/BufferedReader/Fill.java
new file mode 100644
index 0000000..224349e
--- /dev/null
+++ b/test/java/io/BufferedReader/Fill.java
@@ -0,0 +1,91 @@
+/*
+ * 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 4090383
+ @summary Ensure that BufferedReader's read method will fill the target array
+ whenever possible
+ */
+
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.BufferedReader;
+
+
+public class Fill {
+
+ /**
+ * A simple Reader that is always ready but may read fewer than the
+ * requested number of characters
+ */
+ static class Source extends Reader {
+
+ int shortFall;
+ char next = 0;
+
+ Source(int shortFall) {
+ this.shortFall = shortFall;
+ }
+
+ public int read(char[] cbuf, int off, int len) throws IOException {
+ int n = len - shortFall;
+ for (int i = off; i < n; i++)
+ cbuf[i] = next++;
+ return n;
+ }
+
+ public boolean ready() {
+ return true;
+ }
+
+ public void close() throws IOException {
+ }
+
+ }
+
+ /**
+ * Test BufferedReader with an underlying source that always reads
+ * shortFall fewer characters than requested
+ */
+ static void go(int shortFall) throws Exception {
+
+ Reader r = new BufferedReader(new Source(shortFall), 10);
+ char[] cbuf = new char[8];
+
+ int n1 = r.read(cbuf);
+ int n2 = r.read(cbuf);
+ System.err.println("Shortfall " + shortFall
+ + ": Read " + n1 + ", then " + n2 + " chars");
+ if (n1 != cbuf.length)
+ throw new Exception("First read returned " + n1);
+ if (n2 != cbuf.length)
+ throw new Exception("Second read returned " + n2);
+
+ }
+
+ public static void main(String[] args) throws Exception {
+ for (int i = 0; i < 8; i++) go(i);
+ }
+
+}
diff --git a/test/java/io/BufferedReader/MarkedFillAtEOF.java b/test/java/io/BufferedReader/MarkedFillAtEOF.java
new file mode 100644
index 0000000..1cee476
--- /dev/null
+++ b/test/java/io/BufferedReader/MarkedFillAtEOF.java
@@ -0,0 +1,52 @@
+/*
+ * 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 4069687
+ @summary Test if fill() will behave correctly at EOF
+ when mark is set.
+*/
+
+import java.io.*;
+
+public class MarkedFillAtEOF {
+
+ public static void main(String[] args) throws Exception {
+ BufferedReader r = new BufferedReader(new StringReader("12"));
+ int count = 0;
+
+ r.read();
+ r.mark(2);
+ // trigger the call to fill()
+ while (r.read() != -1);
+ r.reset();
+
+ // now should only read 1 character
+ while (r.read() != -1) {
+ count++;
+ }
+ if (count != 1) {
+ throw new Exception("Expect 1 character, but got " + count);
+ }
+ }
+}
diff --git a/test/java/io/BufferedReader/ReadLine.java b/test/java/io/BufferedReader/ReadLine.java
new file mode 100644
index 0000000..0b66668
--- /dev/null
+++ b/test/java/io/BufferedReader/ReadLine.java
@@ -0,0 +1,147 @@
+/*
+ * 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 4151072
+ * @summary Ensure that BufferedReader's methods handle the new line character
+ * following the carriage return correctly after a readLine
+ * operation that resulted in reading a line terminated by a
+ * carriage return (\r).
+ */
+import java.io.*;
+
+public class ReadLine {
+
+ public static void main(String[] args) throws IOException {
+ // Make sure that the reader does not wait for additional characters to
+ // be read after reading a new line.
+ BufferedReader reader;
+ String[][] strings = {
+ {"CR/LF\r\n", "CR/LF"},
+ {"LF-Only\n", "LF-Only"},
+ {"CR-Only\r", "CR-Only"},
+ {"CR/LF line\r\nMore data", "More data"}
+ };
+
+ // test 0 "CR/LF\r\n"
+ // test 1 "LF-Only\n"
+ // test 2 "CR-Only\r"
+ for (int i = 0; i < 3; i++) {
+ reader = new BufferedReader(new
+ BoundedReader(strings[i][0]), strings[i][0].length());
+ if (!reader.readLine().equals(strings[i][1]))
+ throw new RuntimeException("Read incorrect text");
+ }
+
+
+ // Now test the mark and reset operations. Consider two cases.
+ // 1. For lines ending with CR only.
+ markResetTest("Lot of textual data\rMore textual data\n",
+ "More textual data");
+
+ // 2. Now for lines ending with CR/LF
+ markResetTest("Lot of textual data\r\nMore textual data\n",
+ "More textual data");
+
+ // 3. Now for lines ending with LF only
+ markResetTest("Lot of textual data\nMore textual data\n",
+ "More textual data");
+
+ // Need to ensure behavior of read() after a readLine() read of a CR/LF
+ // terminated line.
+ // 1. For lines ending with CR/LF only.
+
+ // uses "CR/LF line\r\nMore data"
+ reader = new BufferedReader(new
+ BoundedReader(strings[3][0]), strings[3][0].length());
+ reader.readLine();
+ if (reader.read() != 'M')
+ throw new RuntimeException("Read() failed");
+
+
+ // Need to ensure that a read(char[], int, int) following a readLine()
+ // read of a CR/LF terminated line behaves correctly.
+
+ // uses "CR/LF line\r\nMore data"
+ reader = new BufferedReader(new
+ BoundedReader(strings[3][0]), strings[3][0].length());
+ reader.readLine();
+
+ char[] buf = new char[9];
+ reader.read(buf, 0, 9);
+ String newStr = new String(buf);
+ if (!newStr.equals(strings[3][1]))
+ throw new RuntimeException("Read(char[],int,int) failed");
+ }
+
+ static void markResetTest(String inputStr, String resetStr)
+ throws IOException {
+ BufferedReader reader = new BufferedReader(new
+ BoundedReader(inputStr), inputStr.length());
+ System.out.println("> " + reader.readLine());
+ reader.mark(30);
+ System.out.println("......Marking stream .....");
+ String str = reader.readLine();
+ System.out.println("> " + str);
+ reader.reset();
+ String newStr = reader.readLine();
+ System.out.println("reset> " + newStr);
+
+ // Make sure that the reset point was set correctly.
+ if (!newStr.equals(resetStr))
+ throw new RuntimeException("Mark/Reset failed");
+ }
+
+
+ private static class BoundedReader extends Reader{
+
+ private char[] content;
+ private int limit;
+ private int pos = 0;
+
+ public BoundedReader(String content) {
+ this.limit = content.length();
+ this.content = new char[limit];
+ content.getChars(0, limit, this.content, 0);
+ }
+
+ public int read() throws IOException {
+ if (pos >= limit)
+ throw new RuntimeException("Read past limit");
+ return content[pos++];
+ }
+
+ public int read(char[] buf, int offset, int length)
+ throws IOException
+ {
+ int oldPos = pos;
+ for (int i = offset; i < length; i++) {
+ buf[i] = (char)read();
+ }
+ return (pos - oldPos);
+ }
+
+ public void close() {}
+ }
+
+}
diff --git a/test/java/io/BufferedReader/ReadLineSync.java b/test/java/io/BufferedReader/ReadLineSync.java
new file mode 100644
index 0000000..0b85fab
--- /dev/null
+++ b/test/java/io/BufferedReader/ReadLineSync.java
@@ -0,0 +1,130 @@
+/*
+ * Copyright 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 5073414
+ * @summary Ensure that there is no race condition in BufferedReader.readLine()
+ * when a line is terminated by '\r\n' is read by multiple threads.
+ */
+
+import java.io.*;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+public class ReadLineSync {
+
+ public static int lineCount = 0;
+
+ public static void main( String[] args ) throws Exception {
+
+ String dir = System.getProperty(".", ".");
+ File f = new File(dir, "test.txt");
+ createFile(f);
+ f.deleteOnExit();
+
+ BufferedReader reader = new BufferedReader(
+ new FileReader(f));
+ int threadCount = 2;
+
+ ExecutorService es = Executors.newFixedThreadPool(threadCount);
+
+ for (int i=0; i < threadCount; i++)
+ es.execute(new BufferedReaderConsumer(reader));
+
+ // Wait for the tasks to complete
+ es.shutdown();
+ while (!es.awaitTermination(60, TimeUnit.SECONDS));
+ }
+
+ static class BufferedReaderConsumer extends Thread {
+ BufferedReader reader;
+
+ public BufferedReaderConsumer( BufferedReader reader ) {
+ this.reader = reader;
+ }
+
+ public void run() {
+ try {
+ String record = reader.readLine();
+
+ if ( record == null ) {
+ // if the first thread is too fast the second will hit
+ // this which is ok
+ System.out.println( "File already finished" );
+ return;
+ }
+
+ if ( record.length() == 0 ) {
+ // usually it comes out here indicating the first read
+ // done by the second thread to run failed
+ System.out.println("Empty string on first read." +
+ Thread.currentThread().getName() );
+ }
+
+ while ( record != null ) {
+ lineCount++;
+
+ // Verify the token count
+ if ( record.length() == 0 ) {
+ // very occasionally it will fall over here
+ throw new Exception( "Invalid tokens with string '" +
+ record + "' on line " + lineCount );
+ }
+ record = reader.readLine();
+ }
+ }
+ catch ( Exception e ) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+
+ // Create a relatively big file
+
+ private static void createFile(File f) throws IOException {
+ BufferedWriter w = new BufferedWriter(
+ new FileWriter(f));
+ int count = 10000;
+ while (count > 0) {
+
+ w.write("abcd \r\n");
+ w.write("efg \r\n");
+ w.write("hijk \r\n");
+ w.write("lmnop \r\n");
+ w.write("qrstuv \r\n");
+ w.write("wxy and z \r\n");
+ w.write("now you \r\n");
+ w.write("know your \r\n");
+ w.write("abc \r\n");
+ w.write("next time \r\n");
+ w.write("want you \r\n");
+ w.write("sing with me \r\n");
+
+ count--;
+ }
+ w.close();
+ }
+}
diff --git a/test/java/io/BufferedReader/Ready.java b/test/java/io/BufferedReader/Ready.java
new file mode 100644
index 0000000..391351d
--- /dev/null
+++ b/test/java/io/BufferedReader/Ready.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2000 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 4329985
+ * @summary Ensure that BufferedReader's ready() method handles the new line
+ * character following the carriage return correctly and returns the right
+ * value so that a read operation after a ready() does not block unnecessarily.
+ */
+import java.io.*;
+
+public class Ready {
+
+ public static void main(String[] args) throws IOException {
+ BufferedReader reader;
+ String[] strings = {
+ "LF-Only\n",
+ "LF-Only\n",
+ "CR/LF\r\n",
+ "CR/LF\r\n",
+ "CR-Only\r",
+ "CR-Only\r",
+ "CR/LF line\r\nMore data.\r\n",
+ "CR/LF line\r\nMore data.\r\n"
+ };
+
+ // The buffer sizes are chosen such that the boundary conditions are
+ // tested.
+ int[] bufsizes = { 7, 8, 6, 5, 7, 8, 11, 10};
+
+ for (int i = 0; i < strings.length; i++) {
+ reader = new BufferedReader(new BoundedReader(strings[i]),
+ bufsizes[i]);
+ while (reader.ready()) {
+ String str = reader.readLine();
+ System.out.println("read>>" + str);
+ }
+ }
+ }
+
+
+
+ private static class BoundedReader extends Reader{
+
+ private char[] content;
+ private int limit;
+ private int pos = 0;
+
+ public BoundedReader(String content) {
+ this.limit = content.length();
+ this.content = new char[limit];
+ content.getChars(0, limit, this.content, 0);
+ }
+
+ public int read() throws IOException {
+ if (pos >= limit)
+ throw new RuntimeException("Hit infinite wait condition");
+ return content[pos++];
+ }
+
+ public int read(char[] buf, int offset, int length)
+ throws IOException
+ {
+ if (pos >= limit)
+ throw new RuntimeException("Hit infinite wait condition");
+ int oldPos = pos;
+ int readlen = (length > (limit - pos)) ? (limit - pos) : length;
+ for (int i = offset; i < readlen; i++) {
+ buf[i] = (char)read();
+ }
+
+ return (pos - oldPos);
+ }
+
+ public void close() {}
+
+ public boolean ready() {
+ if (pos < limit)
+ return true;
+ else
+ return false;
+ }
+ }
+
+}
diff --git a/test/java/io/BufferedReader/SkipNegative.java b/test/java/io/BufferedReader/SkipNegative.java
new file mode 100644
index 0000000..1b40723
--- /dev/null
+++ b/test/java/io/BufferedReader/SkipNegative.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 4152453
+ @summary Skip must throw an exception for negative args
+*/
+
+
+
+import java.io.*;
+
+public class SkipNegative {
+ public static void main(String argv[]) throws Exception {
+ char[] cbuf = "testString".toCharArray();
+ CharArrayReader CAR = new CharArrayReader(cbuf);
+ BufferedReader BR = new BufferedReader(CAR);
+ long nchars = -1L;
+ try {
+ long actual = BR.skip(nchars);
+ } catch(IllegalArgumentException e){
+ // Negative argument caught
+ return;
+ }
+ throw new Exception("Skip should not accept negative values");
+ }
+}