Initial load
diff --git a/test/java/io/BufferedInputStream/CloseStream.java b/test/java/io/BufferedInputStream/CloseStream.java
new file mode 100644
index 0000000..0f7b341
--- /dev/null
+++ b/test/java/io/BufferedInputStream/CloseStream.java
@@ -0,0 +1,73 @@
+/*
+ * 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 4072173
+ @summary Test BufferdInputStream close method */
+
+import java.io.*;
+
+/**
+ * This class tests to see if BufferedInputStream closes
+ * properly
+ */
+
+public class CloseStream {
+
+ public static void main( String argv[] ) throws Exception {
+ BufferedInputStream in = new BufferedInputStream(new MyInputStream());
+
+ in.read();
+ in.close();
+
+ try {
+ in.read(); // IOException should be thrown here
+ throw new RuntimeException("No exception during read on closed stream");
+ }
+ catch (IOException e) {
+ System.err.println("Test passed: IOException is thrown");
+ }
+ }
+}
+
+class MyInputStream extends InputStream {
+
+ public MyInputStream() {
+ }
+
+ public void close() throws IOException {
+ if (status == OPEN) {
+ status = CLOSED;
+ } else throw new IOException();
+ }
+
+ public int read() throws IOException {
+ if (status == CLOSED)
+ throw new IOException();
+ return (byte)'a';
+ }
+
+ private final int OPEN = 1;
+ private final int CLOSED = 2;
+ private int status = OPEN;
+}
diff --git a/test/java/io/BufferedInputStream/CountUpdate.java b/test/java/io/BufferedInputStream/CountUpdate.java
new file mode 100644
index 0000000..babfb20
--- /dev/null
+++ b/test/java/io/BufferedInputStream/CountUpdate.java
@@ -0,0 +1,104 @@
+/*
+ * 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 4054043
+ * @summary Test bufferedinputstream when stream is interrupted
+ *
+ */
+
+import java.io.*;
+
+/**
+ * This class tests to see if bufferinputstream updates count
+ * when the stream is interrupted and restarted
+ * It was adapted from a test class provided in the bug report
+ *
+ */
+
+public class CountUpdate {
+
+ public static void main(String[] args) throws Exception {
+ BufferBreaker breaker = new BufferBreaker();
+ BufferedInputStream in = new BufferedInputStream(breaker, 1000);
+
+ byte b[] = new byte[100];
+ int total = 0;
+
+ for (int i=0; i<5; i++) {
+
+ if (i>0) breaker.breakIt = true;
+ try {
+ int n = in.read(b);
+ total += n;
+ //System.out.print("read "+n+" bytes: [");
+ //System.out.write(b, 0, n);
+ //System.out.println("]");
+ }
+ catch (IOException e) {
+ //System.out.println(e);
+ }
+ }
+
+ if (total>7)
+ throw new RuntimeException(
+ "BufferedInputStream did not reset count.");
+ }
+}
+
+class BufferBreaker extends InputStream {
+ public boolean breakIt = false;
+
+ public int read() {
+ return 'x';
+ }
+
+ public static final byte[] buffer = {(byte)'a',
+ (byte)'b',
+ (byte)'c',
+ (byte)'d',
+ (byte)'e',
+ (byte)'f',
+ (byte)'g'};
+
+ public int read(byte b[]) throws IOException {
+ return read(b, 0, b.length);
+ }
+
+ public int read(byte b[], int off, int len) throws IOException {
+ if (breakIt) throw new IOException("BREAK");
+ if (len > buffer.length) len = buffer.length;
+ System.arraycopy(buffer, 0, b, off, len);
+ return len;
+ }
+
+ public long skip(long n) {
+ return 0;
+ }
+
+ public int available() {
+ return 0;
+ }
+
+}
diff --git a/test/java/io/BufferedInputStream/Fill.java b/test/java/io/BufferedInputStream/Fill.java
new file mode 100644
index 0000000..034269e
--- /dev/null
+++ b/test/java/io/BufferedInputStream/Fill.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright 1998-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 4090383
+ @summary Ensure that BufferedInputStream's read method will fill the target
+ array whenever possible
+ */
+
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.BufferedInputStream;
+
+
+public class Fill {
+
+ /**
+ * A simple InputStream that is always ready but may read fewer than the
+ * requested number of bytes
+ */
+ static class Source extends InputStream {
+
+ int shortFall;
+ byte next = 0;
+
+ Source(int shortFall) {
+ this.shortFall = shortFall;
+ }
+
+ public int read() throws IOException {
+ return next++;
+ }
+
+ public int read(byte[] buf, int off, int len) throws IOException {
+ int n = len - shortFall;
+ for (int i = off; i < n; i++)
+ buf[i] = next++;
+ return n;
+ }
+
+ public int available() {
+ return Integer.MAX_VALUE;
+ }
+
+ public void close() throws IOException {
+ }
+
+ }
+
+ /**
+ * Test BufferedInputStream with an underlying source that always reads
+ * shortFall fewer bytes than requested
+ */
+ static void go(int shortFall) throws Exception {
+
+ InputStream r = new BufferedInputStream(new Source(shortFall), 10);
+ byte[] buf = new byte[8];
+
+ int n1 = r.read(buf);
+ int n2 = r.read(buf);
+ System.err.println("Shortfall " + shortFall
+ + ": Read " + n1 + ", then " + n2 + " bytes");
+ if (n1 != buf.length)
+ throw new Exception("First read returned " + n1);
+ if (n2 != buf.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/BufferedInputStream/ReadAfterClose.java b/test/java/io/BufferedInputStream/ReadAfterClose.java
new file mode 100644
index 0000000..09f7e59
--- /dev/null
+++ b/test/java/io/BufferedInputStream/ReadAfterClose.java
@@ -0,0 +1,57 @@
+/*
+ * 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 4143651
+ @summary Test if I/O methods will check if the stream
+ has been closed.
+*/
+
+
+
+import java.io.*;
+
+public class ReadAfterClose {
+ static void testRead(InputStream in) throws Exception {
+ in.close();
+ byte[] buf = new byte[2];
+
+ try {
+ in.read(buf, 0, 1);
+ throw new Exception("Should not allow read on a closed stream");
+ } catch (IOException e) {
+ }
+
+ try {
+ in.read(buf, 0, 0);
+ throw new Exception("Should not allow read on a closed stream");
+ } catch (IOException e) {
+ }
+ }
+
+ public static void main(String argv[]) throws Exception {
+ BufferedInputStream bis = new BufferedInputStream
+ (new ByteArrayInputStream(new byte[32]));
+ testRead(bis);
+ }
+}
diff --git a/test/java/io/BufferedInputStream/ReadZeroBytes.java b/test/java/io/BufferedInputStream/ReadZeroBytes.java
new file mode 100644
index 0000000..55b634f
--- /dev/null
+++ b/test/java/io/BufferedInputStream/ReadZeroBytes.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 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 5041041
+ * @summary Test BufferedInputStream read of zero byte array
+ */
+
+import java.io.*;
+
+/**
+ * This class tests to see if BufferedInputStream of zero length array
+ * invokes the read method or not. Invoking read could block which is
+ * incompatible behavior for zero length array.
+ */
+public class ReadZeroBytes {
+
+ public static void main( String argv[] ) throws Exception {
+ BufferedInputStream in = new BufferedInputStream(
+ new ThrowingInputStream());
+ in.read(new byte[0], 0, 0);
+ }
+}
+
+class ThrowingInputStream extends InputStream {
+
+ public ThrowingInputStream() {
+ }
+ public int read() throws IOException {
+ return 0;
+ }
+ public int read(byte[] b, int off, int len) throws IOException {
+ throw new RuntimeException("Read invoked for len == 0");
+ }
+}
diff --git a/test/java/io/BufferedInputStream/SkipTest.java b/test/java/io/BufferedInputStream/SkipTest.java
new file mode 100644
index 0000000..2b20216
--- /dev/null
+++ b/test/java/io/BufferedInputStream/SkipTest.java
@@ -0,0 +1,97 @@
+/*
+ * 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 1.1 98/01/12
+ * @bug 4022294
+ * @summary Test bufferedinputstream for data loss during skip
+ *
+ */
+
+import java.io.*;
+import java.util.*;
+
+/**
+ * This class tests to see if bufferinputstream can be reset
+ * to recover data that was skipped over when the buffer did
+ * not contain all the bytes to be skipped
+ */
+public class SkipTest {
+
+ public static void main(String[] args) throws Exception {
+ long skipped = 0;
+
+ // Create a tiny buffered stream so it can be easily
+ // set up to contain only some of the bytes to skip
+ DataSupplier source = new DataSupplier();
+ BufferedInputStream in = new BufferedInputStream(source, 4);
+
+ // Set up data to be skipped and recovered
+ // the skip must be longer than the buffer size
+ in.mark(30);
+ while (skipped < 15) {
+ skipped += in.skip(15-skipped);
+ }
+ int nextint = in.read();
+ in.reset();
+
+ // Resume reading and see if data was lost
+ nextint = in.read();
+
+ if (nextint != 'a')
+ throw new RuntimeException("BufferedInputStream skip lost data");
+ }
+}
+
+
+class DataSupplier extends InputStream {
+
+ private int aposition=0;
+
+ public int read() {
+ return 'x';
+ }
+
+ public long skip(long n) {
+ aposition += (int) n;
+ return n;
+ }
+
+ public static final byte[] buffer = {(byte)'a',(byte)'b',(byte)'c',
+(byte)'d',(byte)'e',(byte)'f',(byte)'g',(byte)'h',(byte)'i',
+(byte)'j',(byte)'k',(byte)'l',(byte)'m',(byte)'n',(byte)'o',
+(byte)'p',(byte)'q',(byte)'r',(byte)'s',(byte)'t',(byte)'u',
+(byte)'v',(byte)'w',(byte)'x',(byte)'y',(byte)'z'
+ };
+
+ public int read(byte b[]) throws IOException {
+ return read(b, 0, b.length);
+ }
+
+ public int read(byte b[], int off, int len) throws IOException {
+ if (len > buffer.length) len = buffer.length;
+ System.arraycopy(buffer, aposition, b, off, len);
+ return len;
+ }
+
+}