Initial load
diff --git a/test/java/io/DataInputStream/OpsAfterClose.java b/test/java/io/DataInputStream/OpsAfterClose.java
new file mode 100644
index 0000000..189fa76
--- /dev/null
+++ b/test/java/io/DataInputStream/OpsAfterClose.java
@@ -0,0 +1,276 @@
+/*
+ * 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 DataInputStream methods will check if the stream
+ * has been closed.
+ */
+
+import java.io.*;
+
+public enum OpsAfterClose {
+
+ READ { boolean check(DataInputStream 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(DataInputStream 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(DataInputStream 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(DataInputStream 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(DataInputStream 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(DataInputStream is) {
+ is.mark(20);
+ return true;
+ } },
+ RESET { boolean check(DataInputStream is) {
+ try {
+ is.reset();
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true;
+ }
+ return false;
+ } },
+ MARK_SUPPORTED { boolean check(DataInputStream is) {
+ is.markSupported();
+ return true;
+ } },
+ CLOSE { boolean check(DataInputStream is) {
+ try {
+ is.close();
+ return true; // No Exception thrown on windows
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true; // Exception thrown on solaris and linux
+ }
+ }},
+ READ_BYTE { boolean check(DataInputStream is) {
+ try {
+ is.readByte();
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true;
+ }
+ return false;
+ } },
+ READ_CHAR { boolean check(DataInputStream is) {
+ try {
+ is.readChar();
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true;
+ }
+ return false;
+ } },
+ READ_DOUBLE { boolean check(DataInputStream is) {
+ try {
+ is.readDouble();
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true;
+ }
+ return false;
+ } },
+
+ READ_FLOAT { boolean check(DataInputStream is) {
+ try {
+ is.readFloat();
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true;
+ }
+ return false;
+ } },
+ READ_INT { boolean check(DataInputStream is) {
+ try {
+ is.readInt();
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true;
+ }
+ return false;
+ } },
+ READ_LONG { boolean check(DataInputStream is) {
+ try {
+ is.readLong();
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true;
+ }
+ return false;
+ } },
+ READ_SHORT { boolean check(DataInputStream is) {
+ try {
+ is.readShort();
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true;
+ }
+ return false;
+ } },
+ READ_UnsignedByte { boolean check(DataInputStream is) {
+ try {
+ is.readUnsignedByte();
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true;
+ }
+ return false;
+ } },
+ READ_UnsignedShort { boolean check(DataInputStream is) {
+ try {
+ is.readUnsignedShort();
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true;
+ }
+ return false;
+ } },
+ READ_UTF { boolean check(DataInputStream is) {
+ try {
+ is.readUTF();
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true;
+ }
+ return false;
+ } },
+ SKIP_BYTES { boolean check(DataInputStream is) {
+ try {
+ is.skipBytes(1);
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true;
+ }
+ return false;
+ } },
+ READ_FULLY { boolean check(DataInputStream is) {
+ try {
+ is.readFully(new byte[1]);
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true;
+ }
+ return false;
+ } },
+ READ_FULLY_BUF { boolean check(DataInputStream is) {
+ try {
+ is.readFully(new byte[1], 0, 1);
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true;
+ }
+ return false;
+ } };
+
+
+ abstract boolean check(DataInputStream 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);
+
+ DataInputStream dis = new DataInputStream(
+ new FileInputStream(f));
+ if (testDataInputStream(dis)) {
+ failed = true;
+ }
+
+ }
+
+ private static boolean testDataInputStream(DataInputStream is)
+ throws Exception {
+ is.close();
+ boolean failed = false;
+ boolean result;
+ System.out.println("Testing :" + is);
+ for (OpsAfterClose op : OpsAfterClose.values()) {
+
+ 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;
+ }
+}
diff --git a/test/java/io/DataInputStream/ReadFully.java b/test/java/io/DataInputStream/ReadFully.java
new file mode 100644
index 0000000..be05f2b
--- /dev/null
+++ b/test/java/io/DataInputStream/ReadFully.java
@@ -0,0 +1,50 @@
+/*
+ * 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 4214513
+ * @summary Passing a negative length argument for readFully must throw
+ * IndexOutOfBoundsException.
+ */
+
+
+import java.io.*;
+public class ReadFully {
+ public static final void main(String[] args) throws Exception {
+ byte[] buffer = new byte[100];
+ File file = new File(System.getProperty("test.src"),
+ "ReadFully.java");
+ FileInputStream in = new FileInputStream(file);
+ DataInputStream dis = new DataInputStream(in);
+
+ boolean caughtException = false;
+ try {
+ dis.readFully(buffer, 0, -20);
+ } catch (IndexOutOfBoundsException ie) {
+ caughtException = true;
+ } finally {
+ if (!caughtException)
+ throw new RuntimeException("Test failed");
+ }
+ }
+}
diff --git a/test/java/io/DataInputStream/ReadLinePushback.java b/test/java/io/DataInputStream/ReadLinePushback.java
new file mode 100644
index 0000000..2ac54a8
--- /dev/null
+++ b/test/java/io/DataInputStream/ReadLinePushback.java
@@ -0,0 +1,50 @@
+/*
+ * 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 4093646
+ @summary Make sure readLine would not push back -1.
+ */
+
+import java.io.*;
+
+public class ReadLinePushback {
+
+ public static void main(String args[]) throws Exception {
+ PushbackInputStream pis = new PushbackInputStream
+ ((new StringBufferInputStream("\r")));
+ DataInputStream dis = new DataInputStream(pis);
+
+ String line = dis.readLine();
+ if (line == null) {
+ throw new Exception ("Got null, should return empty line");
+ }
+
+ int count = pis.available();
+
+ if (count != 0) {
+ throw new Exception ("Test failed: available() returns "
+ + count + "when the file is empty");
+ }
+ }
+}
diff --git a/test/java/io/DataInputStream/ReadUTF.java b/test/java/io/DataInputStream/ReadUTF.java
new file mode 100644
index 0000000..b3e22c4
--- /dev/null
+++ b/test/java/io/DataInputStream/ReadUTF.java
@@ -0,0 +1,86 @@
+/*
+ * 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 4806007
+ * @summary Checks for vague exceptions from writeUTF/readUTF
+ */
+
+import java.io.*;
+import java.util.*;
+
+public class ReadUTF {
+
+ private static Random generator = new Random();
+
+ private static final int TEST_ITERATIONS = 1000;
+
+ private static final int A_NUMBER_NEAR_65535 = 60000;
+
+ private static final int MAX_CORRUPTIONS_PER_CYCLE = 3;
+
+ public static final void main(String[] args) throws Exception {
+ for (int i=0; i<TEST_ITERATIONS; i++) {
+ try {
+ writeAndReadAString();
+ } catch (UTFDataFormatException utfdfe) {
+ if (utfdfe.getMessage() == null)
+ throw new RuntimeException("vague exception thrown");
+ } catch (EOFException eofe) {
+ // These are rare and beyond the scope of the test
+ }
+ }
+ }
+
+ private static void writeAndReadAString() throws Exception {
+ // Write out a string whose UTF-8 encoding is quite possibly
+ // longer than 65535 bytes
+ int length = generator.nextInt(A_NUMBER_NEAR_65535) + 1;
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ StringBuffer testBuffer = new StringBuffer();
+ for (int i=0; i<length; i++)
+ testBuffer.append((char)generator.nextInt());
+ String testString = testBuffer.toString();
+ DataOutputStream dos = new DataOutputStream(baos);
+ dos.writeUTF(testString);
+
+ // Corrupt the data to produce malformed characters
+ byte[] testBytes = baos.toByteArray();
+ int dataLength = testBytes.length;
+ int corruptions = generator.nextInt(MAX_CORRUPTIONS_PER_CYCLE);
+ for (int i=0; i<corruptions; i++) {
+ int index = generator.nextInt(dataLength);
+ testBytes[index] = (byte)generator.nextInt();
+ }
+
+ // Pay special attention to mangling the end to produce
+ // partial characters at end
+ testBytes[dataLength-1] = (byte)generator.nextInt();
+ testBytes[dataLength-2] = (byte)generator.nextInt();
+
+ // Attempt to decode the bytes back into a String
+ ByteArrayInputStream bais = new ByteArrayInputStream(testBytes);
+ DataInputStream dis = new DataInputStream(bais);
+ dis.readUTF();
+ }
+}
diff --git a/test/java/io/DataInputStream/SkipBytes.java b/test/java/io/DataInputStream/SkipBytes.java
new file mode 100644
index 0000000..a0c91a5
--- /dev/null
+++ b/test/java/io/DataInputStream/SkipBytes.java
@@ -0,0 +1,87 @@
+/*
+ * 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 4085938
+ @summary Check for the correct behaviour of DataInputStream.skipBytes
+ */
+
+import java.io.*;
+
+public class SkipBytes{
+
+ private static void dotest(DataInputStream dis, int pos, int total,
+ int toskip, int expected) {
+
+ try {
+ System.err.println("\n\nTotal bytes in the stream = " + total);
+ System.err.println("Currently at position = " + pos);
+ System.err.println("Bytes to skip = " + toskip);
+ System.err.println("Expected result = " + expected);
+ int skipped = dis.skipBytes(toskip);
+ System.err.println("Actual skipped = " + skipped);
+ if (skipped != expected) {
+ throw new RuntimeException
+ ("DataInputStream.skipBytes does not return expected value");
+ }
+ } catch(EOFException e){
+ throw new RuntimeException
+ ("DataInputStream.skipBytes throws unexpected EOFException");
+ } catch (IOException e) {
+ System.err.println("IOException is thrown - possible result");
+ }
+
+
+ }
+
+
+
+ public static void main(String args[]) throws Exception {
+
+ DataInputStream dis = new DataInputStream(new MyInputStream());
+ dotest(dis, 0, 11, -1, 0);
+ dotest(dis, 0, 11, 5, 5);
+ System.err.println("\n***CAUTION**** - may go into an infinite loop");
+ dotest(dis, 5, 11, 20, 6);
+ }
+}
+
+
+class MyInputStream extends InputStream {
+
+ private int readctr = 0;
+
+ public int read() {
+
+ if (readctr > 10){
+ return -1;
+ }
+ else{
+ readctr++;
+ return 0;
+ }
+
+ }
+
+ public int available() { return 0; }
+}