Initial load
diff --git a/test/java/io/InputStream/OpsAfterClose.java b/test/java/io/InputStream/OpsAfterClose.java
new file mode 100644
index 0000000..aed993d
--- /dev/null
+++ b/test/java/io/InputStream/OpsAfterClose.java
@@ -0,0 +1,263 @@
+/*
+ * 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 4181483
+ * @summary Test if InputStream methods will check if the stream
+ * has been closed.
+ */
+
+import java.io.*;
+
+public enum OpsAfterClose {
+
+ READ { boolean check(InputStream is) {
+ try {
+ int read = is.read();
+ System.out.println("read returns: " + read);
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true;
+ }
+ return false;
+ } },
+
+ READ_BUF { boolean check(InputStream is) {
+ try {
+ byte buf[] = new byte[2];
+ int read = is.read(buf);
+ System.out.println("read(buf) returns: " + read);
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true;
+ }
+ return false;
+ } },
+ READ_BUF_OFF { boolean check(InputStream is) {
+ try {
+ byte buf[] = new byte[2];
+ int len = 1;
+ int read = is.read(buf, 0, len);
+ System.out.println("read(buf, 0, len) returns: " + read);
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true;
+ }
+ return false;
+ } },
+ AVAILABLE { boolean check(InputStream is) {
+ try {
+ int avail = is.available();
+ System.out.println("available() returns: " + avail);
+ return false;
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true;
+ }
+ } },
+ SKIP { boolean check(InputStream is) {
+ try {
+ long skipped = is.skip(1);
+ System.out.println("skip() returns: " + skipped);
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true;
+ }
+ return false;
+ } },
+ MARK { boolean check(InputStream is) {
+ is.mark(20);
+ return true;
+ } },
+ RESET { boolean check(InputStream is) {
+ try {
+ is.reset();
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true;
+ }
+ return false;
+ } },
+ MARK_SUPPORTED { boolean check(InputStream is) {
+ is.markSupported();
+ return true;
+ } },
+ CLOSE { boolean check(InputStream is) {
+ try {
+ is.close();
+ return true; // No Exception thrown on windows for FileInputStream
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true; // Exception thrown on solaris and linux for FileInputStream
+ }
+ } };
+
+ abstract boolean check(InputStream is);
+
+ 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 (testInputStream(fis)) {
+ failed = true;
+ }
+ if (testFileInputStream(fis)) {
+ failed = true;
+ }
+
+ BufferedInputStream bs = new BufferedInputStream(
+ new FileInputStream(f));
+ if (testInputStream(bs)) {
+ failed = true;
+ }
+
+ DataInputStream dis = new DataInputStream(
+ new FileInputStream(f));
+ if (testInputStream(dis)) {
+ failed = true;
+ }
+
+ PushbackInputStream pbis = new PushbackInputStream(
+ new ByteArrayInputStream(new byte[20]));
+ if (testInputStream(pbis)) {
+ failed = true;
+ }
+
+ if (testPushbackInputStream(pbis)) {
+ failed = true;
+ }
+
+ PipedInputStream pis = new PipedInputStream(new PipedOutputStream());
+ if (testInputStream(pis)) {
+ failed = true;
+ }
+
+ /**
+ * The SequenceInputStream and ObjectInputStream does not throw IOException
+
+ SequenceInputStream sqis = new SequenceInputStream(
+ new FileInputStream(f),
+ new PipedInputStream(new PipedOutputStream())
+ );
+ if (testInputStream(sqis)) {
+ failed = true;
+ }
+
+ String serStr = "abc";
+ ObjectOutputStream oos = new ObjectOutputStream(
+ new FileOutputStream(f));
+ oos.writeObject(serStr);
+ oos.close();
+
+ ObjectInputStream ois = new ObjectInputStream(
+ new FileInputStream(f));
+ if (testInputStream(ois)) {
+ failed = true;
+ }
+
+ */
+
+ if (failed) {
+ throw new Exception(
+ "Some Op for some Stream failed, check the failed status above");
+ }
+ }
+
+ private static boolean testInputStream(InputStream is)
+ throws Exception {
+ is.close();
+ boolean failed = false;
+ boolean result;
+ System.out.println("Testing :" + is);
+ for (OpsAfterClose op : OpsAfterClose.values()) {
+
+ if (op.equals(AVAILABLE) && (is instanceof PipedInputStream)) {
+ // skip the test as available() returns 0
+ continue;
+ }
+
+ result = op.check(is);
+ if (!result) {
+ failed = true;
+ }
+ System.out.println(op + ":" + result);
+ }
+ if (failed) {
+ System.out.println("Test failed for the failed operation{s}" +
+ " above for :" + is);
+ }
+ return failed;
+ }
+
+ private static boolean testPushbackInputStream(PushbackInputStream pis)
+ throws Exception {
+ boolean failed = false;
+ try {
+ pis.unread(1);
+ System.out.println("Test failed for unread(int):" + pis);
+ failed = true;
+ } catch (IOException io) {
+ System.out.println("UNREAD(int):true");
+ }
+
+ byte buf[] = new byte[2];
+ try {
+ pis.unread(buf, 0, 2);
+ System.out.println("Test failed for unread(buf, offset, len):" +
+ pis);
+ failed = true;
+ } catch (IOException io) {
+ System.out.println("UNREAD(buf, offset, len):true");
+ }
+ try {
+ pis.unread(buf);
+ System.out.println("Test failed for unread(char[] buf):" + pis);
+ failed = true;
+ } catch (IOException io) {
+ System.out.println("UNREAD(buf):true");
+ }
+ return failed;
+ }
+
+ private static boolean testFileInputStream(FileInputStream fis)
+ throws Exception {
+ boolean failed = false;
+ try {
+ fis.getFD();
+ System.out.println("GetFD: true");
+ } catch (IOException io) {
+ System.out.println("GetFD: false");
+ failed = true;
+ }
+ fis.getChannel();
+ System.out.println("GetChannel: true");
+ return failed;
+ }
+}
diff --git a/test/java/io/InputStream/ReadParams.java b/test/java/io/InputStream/ReadParams.java
new file mode 100644
index 0000000..30ee9cb
--- /dev/null
+++ b/test/java/io/InputStream/ReadParams.java
@@ -0,0 +1,225 @@
+/*
+ * Copyright 1998-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 4008296 4008293 4190090 4193729
+ * @summary Check for correct handling of parameters to
+ * XXXXInputStream.read(b, off, len).
+ *
+ */
+
+import java.io.*;
+import java.util.zip.ZipInputStream;
+import java.util.zip.InflaterInputStream;
+import java.util.zip.DeflaterOutputStream;
+
+public class ReadParams {
+
+ /* check for correct handling of different values of off and len */
+ public static void doTest(InputStream in) throws Exception {
+
+ int off[] = {-1, -1, 0, 0, 33, 33, 0, 32, 32, 4, 1, 0, -1,
+ Integer.MAX_VALUE, 1, Integer.MIN_VALUE,
+ Integer.MIN_VALUE, 1};
+ int len[] = {-1, 0, -1, 33, 0, 4, 32, 0, 4, 16, 31, 0,
+ Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE,
+ 1, -1, Integer.MIN_VALUE};
+ boolean results[] = { false, false, false, false, false, false,
+ true, true, false, true, true, true, false,
+ false, false, false, false, false};
+ int numCases = off.length;
+ byte b[] = new byte[32];
+ int numBad = 0;
+
+ for(int i = 0; i < numCases; i++) {
+ try {
+ in.read(b , off[i] , len[i]);
+ } catch (IndexOutOfBoundsException aiobe) {
+ if (results[i]) {
+ System.err.println("Error:IndexOutOfBoundsException thrown"+
+ " for read(b, " + off[i] + " " + len[i] +
+ " ) on " + in + "\nb.length = 32");
+ numBad++;
+ } else {
+ /* System.err.println("PassE: " + off[i] + " " + len[i]); */
+ }
+ continue;
+ } catch (OutOfMemoryError ome) {
+ System.err.println("Error: OutOfMemoryError in read(b, " +
+ off[i] + " " + len[i] + " ) on " + in +
+ "\nb.length = 32");
+ numBad++;
+ continue;
+ }
+ if (!results[i]) {
+ System.err.println("Error:No IndexOutOfBoundsException thrown"+
+ " for read(b, " + off[i] + " " + len[i] +
+ " ) on " + in + "\nb.length = 32");
+ numBad++;
+ } else {
+ /* System.err.println("Pass: " + off[i] + " " + len[i]); */
+ }
+ }
+
+ if (numBad > 0) {
+ throw new RuntimeException(in + " Failed " + numBad + " cases");
+ } else {
+ System.err.println("Successfully completed bounds tests on " + in);
+ }
+ }
+
+ /* check for correct handling of null b */
+ public static void doTest1(InputStream in) throws Exception {
+ byte b[] = null;
+ try {
+ in.read(b, 0, 32);
+ } catch (NullPointerException npe) {
+ System.err.println("SuccessFully completed null b test on " + in);
+ return;
+ }
+ throw new RuntimeException(in + " Failed null b test");
+ }
+
+ public static void main(String args[]) throws Exception{
+ /* initialise stuff */
+ File fn = new File("x.ReadBounds");
+ FileOutputStream fout = new FileOutputStream(fn);
+ for (int i = 0; i < 32; i++) {
+ fout.write(i);
+ }
+ fout.close();
+
+ byte b[] = new byte[64];
+ for(int i = 0; i < 64; i++) {
+ b[i] = 1;
+ }
+
+ /* test all input streams */
+ FileInputStream fis = new FileInputStream(fn);
+ doTest(fis);
+ doTest1(fis);
+ fis.close();
+
+ BufferedInputStream bis =
+ new BufferedInputStream(new MyInputStream(1024));
+ doTest(bis);
+ doTest1(bis);
+ bis.close();
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(b);
+ doTest(bais);
+ doTest1(bais);
+ bais.close();
+
+ FileOutputStream fos = new FileOutputStream(fn);
+ ObjectOutputStream oos = new ObjectOutputStream(fos);
+ oos.writeInt(12345);
+ oos.writeObject("Today");
+ oos.writeObject(new Integer(32));
+ ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fn));
+ doTest(ois);
+ doTest1(ois);
+ ois.close();
+
+ DataInputStream dis = new DataInputStream(new MyInputStream(1024));
+ doTest(dis);
+ doTest1(dis);
+ dis.close();
+
+ LineNumberInputStream lis =
+ new LineNumberInputStream(new MyInputStream(1024));
+ doTest(lis);
+ doTest1(lis);
+ lis.close();
+
+ PipedOutputStream pos = new PipedOutputStream();
+ PipedInputStream pis = new PipedInputStream();
+ pos.connect(pis);
+ pos.write(b, 0, 64);
+ doTest(pis);
+ doTest1(pis);
+ pis.close();
+
+ PushbackInputStream pbis =
+ new PushbackInputStream(new MyInputStream(1024));
+ doTest(pbis);
+ doTest1(pbis);
+ pbis.close();
+
+ StringBufferInputStream sbis =
+ new StringBufferInputStream(new String(b));
+ doTest(sbis);
+ doTest1(sbis);
+ sbis.close();
+
+ SequenceInputStream sis =
+ new SequenceInputStream(new MyInputStream(1024),
+ new MyInputStream(1024));
+ doTest(sis);
+ doTest1(sis);
+ sis.close();
+
+ ZipInputStream zis = new ZipInputStream(new FileInputStream(fn));
+ doTest(zis);
+ doTest1(zis);
+ zis.close();
+
+ byte[] data = new byte[256];
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ DeflaterOutputStream dos = new DeflaterOutputStream(bos);
+ dos.write(data, 0, data.length);
+ dos.close();
+ InflaterInputStream ifs = new InflaterInputStream
+ (new ByteArrayInputStream(bos.toByteArray()));
+ doTest(ifs);
+ doTest1(ifs);
+ ifs.close();
+
+ /* cleanup */
+ fn.delete();
+ }
+}
+
+/* An InputStream class used in the above tests */
+class MyInputStream extends InputStream {
+
+ private int readctr = 0;
+ private long endoffile;
+
+ public MyInputStream(long endoffile) {
+ this.endoffile = endoffile;
+ }
+
+ public int read() {
+ if (readctr == endoffile) {
+ return -1;
+ }
+ else {
+ readctr++;
+ return 0;
+ }
+ }
+
+ public int available() { return 0; }
+}
diff --git a/test/java/io/InputStream/Skip.java b/test/java/io/InputStream/Skip.java
new file mode 100644
index 0000000..07be724
--- /dev/null
+++ b/test/java/io/InputStream/Skip.java
@@ -0,0 +1,126 @@
+/*
+ * 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 4016710
+ @summary check for correct implementation of InputStream.skip
+ */
+
+import java.io.*;
+
+
+public class Skip{
+
+ private static void dotest(InputStream in , int curpos ,
+ long total , long toskip , long expected)
+ throws Exception
+ {
+
+ try {
+
+ System.err.println("\n\nCurrently at pos = " + curpos +
+ "\nTotal bytes in the Stream = " + total +
+ "\nNumber of bytes to skip = " + toskip +
+ "\nNumber of bytes that should be skipped = " +
+ expected);
+
+ long skipped = in.skip(toskip);
+
+ System.err.println("actual number skipped: "+ skipped);
+
+ if ((skipped < 0) || (skipped > expected)) {
+ throw new RuntimeException("Unexpected number of bytes skipped");
+ }
+
+ } catch (IOException e) {
+ System.err.println("IOException is thrown - possible result");
+ } catch (Throwable e) {
+ throw new RuntimeException("Unexpected "+e+" is thrown!");
+ }
+
+ }
+
+ public static void main( String argv[] ) throws Exception {
+
+ MyInputStream in = new MyInputStream(11);
+
+ /* test for negative skip */
+ dotest(in, 0, 11, -23, 0);
+
+ /* check for skip beyond EOF starting from before EOF */
+ dotest(in, 0, 11, 20, 11);
+
+ /* check for skip after EOF */
+ dotest(in, -1, 11, 20, 0);
+
+ in = new MyInputStream(9000);
+ /* check for skip equal to the read chunk size in InputStream.java */
+ dotest(in, 0, 9000, 2048, 2048);
+
+ /* check for skip greater than the read chunk size in InputStream.java */
+ dotest(in, 2048, 9000, 5000, 5000);
+
+ /* check for skip beyond EOF starting from before EOF */
+ dotest(in, 7048, 9000, 5000, 1952);
+
+ in = new MyInputStream(5000);
+
+ /* check for multiple chunk reads */
+ dotest(in, 0, 5000, 6000, 5000);
+
+ /*
+ * check for skip larger than Integer.MAX_VALUE
+ * (Takes about 2 hrs on a sparc ultra-1)
+ * long total = (long)Integer.MAX_VALUE + (long)10;
+ * long toskip = total - (long)6;
+ * in = new MyInputStream(total);
+ * dotest(in, 0, total, toskip, toskip);
+ */
+
+ }
+
+}
+
+class MyInputStream extends InputStream {
+
+ private int readctr = 0;
+ private long endoffile;
+
+ public MyInputStream(long endoffile) {
+ this.endoffile = endoffile;
+ }
+
+ public int read() {
+
+ if (readctr == endoffile) {
+ return -1;
+ }
+ else {
+ readctr++;
+ return 0;
+ }
+ }
+
+ public int available() { return 0; }
+}