Initial load
diff --git a/test/java/io/RandomAccessFile/Close.java b/test/java/io/RandomAccessFile/Close.java
new file mode 100644
index 0000000..0126660
--- /dev/null
+++ b/test/java/io/RandomAccessFile/Close.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2002 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 4710771
+ * @summary Test RandomAccessFile.close
+ */
+
+import java.io.*;
+import java.nio.channels.*;
+
+public class Close {
+ public static void main(String[] args) throws Exception {
+ File f = File.createTempFile("blah", null);
+ f.deleteOnExit();
+ RandomAccessFile raf = new RandomAccessFile(f, "r");
+ FileChannel channel = raf.getChannel();
+ raf.close();
+ if (channel.isOpen()) {
+ throw new RuntimeException("Channel not closed");
+ }
+ }
+}
diff --git a/test/java/io/RandomAccessFile/EOF.java b/test/java/io/RandomAccessFile/EOF.java
new file mode 100644
index 0000000..86a96ff
--- /dev/null
+++ b/test/java/io/RandomAccessFile/EOF.java
@@ -0,0 +1,46 @@
+/*
+ * 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 4017497
+ @summary Check that read returns -1 on EOF, as specified
+ */
+
+import java.io.*;
+
+public class EOF {
+
+ public static void main(String[] args) throws IOException {
+ byte buf[] = new byte[100];
+ int n;
+ String dir = System.getProperty("test.src", ".");
+ RandomAccessFile raf = new RandomAccessFile(new File(dir, "EOF.java"), "r");
+ for (;;) {
+ n = raf.read(buf, 0, buf.length);
+ if (n <= 0) break;
+ }
+ if (n != -1)
+ throw new RuntimeException("Expected -1 for EOF, got " + n);
+ }
+
+}
diff --git a/test/java/io/RandomAccessFile/OpenSync.java b/test/java/io/RandomAccessFile/OpenSync.java
new file mode 100644
index 0000000..f925b97
--- /dev/null
+++ b/test/java/io/RandomAccessFile/OpenSync.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2001 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 Unit test for RandomAccessFile open-sync modes
+ */
+
+import java.io.*;
+
+
+public class OpenSync {
+
+ static PrintStream log = System.err;
+
+ public static void main(String[] args) throws Exception {
+
+ File blah = File.createTempFile("OpenSync", null);
+ blah.deleteOnExit();
+
+ String[] badModes = { "d", "s", "rd", "rs", "rwx", "foo" };
+ for (int i = 0; i < badModes.length; i++) {
+ String mode = badModes[i];
+ try {
+ new RandomAccessFile(blah, mode);
+ } catch (IllegalArgumentException x) {
+ log.println("Mode \"" + mode +"\": Thrown as expected: "
+ + x.getClass().getName());
+ log.println(" " + x.getMessage());
+ continue;
+ }
+ throw new Exception("Exception not thrown for illegal mode "
+ + mode);
+ }
+
+ new RandomAccessFile(blah, "rw").close();
+ new RandomAccessFile(blah, "r").close();
+
+ String hi = "Hello, world!";
+ RandomAccessFile raf = new RandomAccessFile(blah, "rws");
+ raf.writeUTF(hi);
+ raf.close();
+
+ raf = new RandomAccessFile(blah, "rwd");
+ if (!raf.readUTF().equals(hi))
+ throw new Exception("File content mismatch");
+ raf.close();
+
+ }
+
+}
diff --git a/test/java/io/RandomAccessFile/OpsAfterClose.java b/test/java/io/RandomAccessFile/OpsAfterClose.java
new file mode 100644
index 0000000..d1f2b4c
--- /dev/null
+++ b/test/java/io/RandomAccessFile/OpsAfterClose.java
@@ -0,0 +1,158 @@
+/**
+ * @test
+ * @bug 6359397
+ * @summary Test if RandomAccessFile methods will check if the stream
+ * has been closed.
+ */
+
+import java.io.*;
+
+public enum OpsAfterClose {
+
+ READ { boolean check(RandomAccessFile r) {
+ try {
+ r.read();
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true;
+ }
+ return false;
+ } },
+
+ READ_BUF { boolean check(RandomAccessFile r) {
+ try {
+ byte buf[] = new byte[2];
+ int len = 1;
+ r.read(buf, 0, len);
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true;
+ }
+ return false;
+ } },
+ GET_CHANNEL { boolean check(RandomAccessFile r) {
+ r.getChannel();
+ return true;
+ } },
+ GET_FD { boolean check(RandomAccessFile r) {
+ try {
+ r.getFD();
+ return true;
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return false;
+ }
+ } },
+ GET_FILE_PTR { boolean check(RandomAccessFile r) {
+ try {
+ r.getFilePointer();
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true;
+ }
+ return false;
+ } },
+ GET_LENGTH { boolean check(RandomAccessFile r) {
+ try {
+ r.length();
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true;
+ }
+ return false;
+ } },
+ SEEK { boolean check(RandomAccessFile r) {
+ try {
+ r.seek(1);
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true;
+ }
+ return false;
+ } },
+ SET_LENGTH { boolean check(RandomAccessFile r) {
+ try {
+ r.setLength(1);
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true;
+ }
+ return false;
+ } },
+ SKIP_BYTES { boolean check(RandomAccessFile r) {
+ try {
+ r.skipBytes(1);
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true;
+ }
+ return false;
+ } },
+ WRITE { boolean check(RandomAccessFile r) {
+ try {
+ r.write(1);
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true;
+ }
+ return false;
+ } },
+ WRITE_BUF { boolean check(RandomAccessFile r) {
+ try {
+ byte buf[] = new byte[2];
+ int len = 1;
+ r.write(buf, 0, len);
+ } catch (IOException io) {
+ System.out.print("Excep Msg: "+ io.getMessage() + ", ");
+ return true;
+ }
+ return false;
+ } },
+ CLOSE { boolean check(RandomAccessFile r) {
+ try {
+ r.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
+ }
+ } };
+
+ abstract boolean check(RandomAccessFile r);
+
+ public static void main(String args[]) throws Exception {
+
+ boolean failed = false;
+
+ File f = new File(System.getProperty("test.dir", "."),
+ "raf.txt");
+ f.createNewFile();
+ f.deleteOnExit();
+
+ RandomAccessFile raf = new RandomAccessFile(f, "rw");
+ if (testRandomAccessFile(raf)) {
+ throw new Exception("Test failed for some of the operation{s}" +
+ " on RandomAccessFile, check the messages");
+ }
+ }
+
+ private static boolean testRandomAccessFile(RandomAccessFile r)
+ throws Exception {
+ r.close();
+ boolean failed = false;
+ boolean result;
+ System.out.println("Testing File:" + r);
+ for (OpsAfterClose op : OpsAfterClose.values()) {
+ result = op.check(r);
+ if (!result) {
+ failed = true;
+ }
+ System.out.println(op + ":" + result);
+ }
+ if (failed) {
+ System.out.println("Test failed for the failed operation{s}" +
+ " above for the RandomAccessFile:" + r);
+ }
+ return failed;
+ }
+}
diff --git a/test/java/io/RandomAccessFile/ParameterCheck.java b/test/java/io/RandomAccessFile/ParameterCheck.java
new file mode 100644
index 0000000..6b01c49
--- /dev/null
+++ b/test/java/io/RandomAccessFile/ParameterCheck.java
@@ -0,0 +1,156 @@
+/*
+ * 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 4030253 4030278 4030243
+ @summary Test for correct parameter checking in read(byte[], int, int),
+ readFully(byte[], int, int) and write(byte[], int, int) of RandomAccessFile
+ */
+
+import java.io.*;
+
+public class ParameterCheck {
+
+ static int off[] = {-1, -1, 0, 0, 33, 33, 0, 32,
+ 32, 4, 1, 0, -1, Integer.MAX_VALUE, 1};
+ static int len[] = {-1, 0, -1, 33, 0, 4, 32,
+ 0, 4, 16, 31, 0, Integer.MAX_VALUE,
+ Integer.MAX_VALUE, Integer.MAX_VALUE};
+ static boolean results[] = { false, false, false, false, false, false,
+ true, true, false, true, true, true, false,
+ false, false };
+ static int numBad = 0;
+
+ private static void doTest(String method) throws Exception {
+ File fn = new File("x.ParameterCheck");
+
+ try {
+ byte b[] = new byte[32];
+ int numCases = off.length;
+ int[] got = new int[numCases];
+ int numGood = 0;
+ FileOutputStream fout = new FileOutputStream(fn);
+ for (int i = 0; i < 32; i++) {
+ fout.write(i);
+ }
+ fout.close();
+ RandomAccessFile raf = new RandomAccessFile(fn , "rw");
+
+ System.err.println("-----------------------------" +
+ "-----------------------------");
+ System.err.println("\nRandomAccessFile." + method +
+ "\nTotal test cases = " + (off.length+1));
+ System.err.println("-----------------------------" +
+ "-----------------------------");
+ for(int i = 0; i < numCases; i++) {
+ try {
+ if (method.equals("readFully")) {
+ raf.readFully(b , off[i] , len[i]);
+ }
+ if (method.equals("read")) {
+ raf.read(b , off[i] , len[i]);
+ }
+ if (method.equals("write")) {
+ raf.write(b , off[i] , len[i]);
+ }
+ raf.seek(0);
+ } catch(IndexOutOfBoundsException aiobe) {
+ if (results[i]) {
+ printErr(method , numGood,
+ i, "java.lang.IndexOutOfBoundsException");
+ } else {
+ numGood++;
+ }
+ continue;
+ } catch(OutOfMemoryError ome) {
+ printErr(method, numGood,
+ i, "java.lang.OutOfMemoryError");
+ continue;
+ }
+
+ if (results[i]) {
+ numGood++;
+ }
+ else {
+ printErr(method, numGood,
+ i, "No java.lang.IndexOutOfBoundsException");
+ }
+
+ }
+
+ raf.seek(0);
+ boolean thrown = false;
+ try {
+ if (method.equals("readFully")) {
+ raf.readFully(null, 1, 2);
+ }
+ if (method.equals("read")) {
+ raf.read(null, 1, 2);
+ }
+ if (method.equals("write")) {
+ raf.write(null, 1, 2);
+ }
+
+ } catch(NullPointerException npe) {
+ numGood++;
+ thrown = true;
+ }
+ if (!thrown) {
+ printErr(method, numGood, -1,
+ "no NullPointerException for null b");
+ }
+
+ System.err.println("\nTotal passed = " + numGood);
+ System.err.println("-----------------------------" +
+ "-----------------------------");
+ } finally {
+ fn.delete();
+ }
+
+ }
+
+ private static void printErr(String method, int numGood,
+ int i, String expStr) {
+ numBad++;
+ System.err.println("\nNumber passed so far = " + numGood +
+ "\nUnexpected " + expStr);
+ if ( i < 0 ) {
+ System.err.println("for case : b = null");
+ } else {
+ System.err.println("for case : b.length = " + 32 +
+ " off = " + off[i] +
+ " len = " + len[i]);
+ }
+ }
+
+ public static void main(String argv[]) throws Exception{
+ doTest("read");
+ doTest("readFully");
+ doTest("write");
+
+ if (numBad > 0) {
+ throw new RuntimeException("Failed " + numBad + " tests");
+ }
+ }
+}
diff --git a/test/java/io/RandomAccessFile/ReadLine.java b/test/java/io/RandomAccessFile/ReadLine.java
new file mode 100644
index 0000000..2af58ba
--- /dev/null
+++ b/test/java/io/RandomAccessFile/ReadLine.java
@@ -0,0 +1,60 @@
+/*
+ * 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 1238814
+ @summary check for correct implementation of RandomAccessFile.readLine
+ */
+
+import java.io.*;
+
+public class ReadLine {
+
+ public static void main(String args[]) throws Exception {
+ File fn = new File("x.ReadLine");
+ RandomAccessFile raf = new RandomAccessFile(fn,"rw");
+ String line;
+ int ctr = 1;
+ String expected;
+
+ raf.writeBytes
+ ("ln1\rln2\r\nln3\nln4\rln5\r\nln6\n\rln8\r\rln10\n\nln12\r\r\nln14");
+ raf.seek(0);
+
+ while ((line=raf.readLine()) != null) {
+ if ((ctr == 7) || (ctr == 9) ||
+ (ctr == 11) || (ctr == 13)) {
+ expected = "";
+ } else {
+ expected = "ln" + ctr;
+ }
+ if (!line.equals(expected)) {
+ throw new Exception("Expected \"" + expected + "\"" +
+ ", read \"" + line + "\"");
+ }
+ ctr++;
+ }
+ System.err.println("Successfully completed test!");
+ }
+
+}
diff --git a/test/java/io/RandomAccessFile/ReadWritePrimitives.java b/test/java/io/RandomAccessFile/ReadWritePrimitives.java
new file mode 100644
index 0000000..2fafcba
--- /dev/null
+++ b/test/java/io/RandomAccessFile/ReadWritePrimitives.java
@@ -0,0 +1,152 @@
+/*
+ * 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 4092350
+ @summary Verify that reads and writes of primitives are correct
+ */
+
+// The bug mentioned is actually a performance bug that prompted
+// changes in the methods to write primitives
+import java.io.*;
+
+import java.io.*;
+
+public class ReadWritePrimitives {
+
+ public static void main(String args[]) throws IOException {
+ long start, finish;
+ start = System.currentTimeMillis();
+ testShort();
+ finish = System.currentTimeMillis();
+ // System.err.println("Time taken="+(finish-start));
+ start = System.currentTimeMillis();
+ testChar();
+ finish = System.currentTimeMillis();
+ // System.err.println("Time taken="+(finish-start));
+ start = System.currentTimeMillis();
+ testInt();
+ finish = System.currentTimeMillis();
+ // System.err.println("Time taken="+(finish-start));
+ start = System.currentTimeMillis();
+ testLong();
+ finish = System.currentTimeMillis();
+ // System.err.println("Time taken="+(finish-start));
+ }
+
+ private static void testShort() throws IOException {
+ File fh = new File(System.getProperty("test.dir", "."),
+ "x.ReadWriteGenerated");
+ RandomAccessFile f = new RandomAccessFile(fh,"rw");
+ for(int i = 0; i < 10000; i++){
+ f.writeShort((short)i);
+ }
+ f.writeShort((short)65535);
+ f.close();
+ f = new RandomAccessFile(fh,"r");
+ for(int i = 0; i < 10000; i++) {
+ short r = f.readShort();
+ if (r != ((short)i)) {
+ System.err.println("An error occurred. Read:" + r
+ + " i:" + ((short)i));
+ throw new IOException("Bad read from a writeShort");
+ }
+ }
+ short rmax = f.readShort();
+ if (rmax != ((short)65535)) {
+ System.err.println("An error occurred. Read:" + rmax);
+ throw new IOException("Bad read from a writeShort");
+ }
+ f.close();
+ }
+
+ private static void testChar() throws IOException {
+ File fh = new File(System.getProperty("test.dir", "."),
+ "x.ReadWriteGenerated");
+ RandomAccessFile f = new RandomAccessFile(fh,"rw");
+ for(int i = 0; i < 10000; i++){
+ f.writeChar((char)i);
+ }
+ f.close();
+ f = new RandomAccessFile(fh,"r");
+ for(int i = 0; i < 10000; i++) {
+ char r = f.readChar();
+ if (r != ((char)i)){
+ System.err.println("An error occurred. Read:" + r
+ + " i:" + ((char) i));
+ throw new IOException("Bad read from a writeChar");
+ }
+ }
+ f.close();
+ }
+
+
+ private static void testInt() throws IOException {
+ File fh = new File(System.getProperty("test.dir", "."),
+ "x.ReadWriteGenerated");
+ RandomAccessFile f = new RandomAccessFile(fh,"rw");
+ for(int i = 0; i < 10000; i++){
+ f.writeInt((short)i);
+ }
+ f.writeInt(Integer.MAX_VALUE);
+ f.close();
+ f = new RandomAccessFile(fh, "r");
+ for(int i = 0; i < 10000; i++) {
+ int r = f.readInt();
+ if (r != i){
+ System.err.println("An error occurred. Read:" + r
+ + " i:" + i);
+ throw new IOException("Bad read from a writeInt");
+ }
+ }
+ int rmax = f.readInt();
+ if (rmax != Integer.MAX_VALUE){
+ System.err.println("An error occurred. Read:" + rmax);
+ throw new IOException("Bad read from a writeInt");
+ }
+ f.close();
+ }
+
+ private static void testLong() throws IOException {
+ File fh = new File(System.getProperty("test.dir", "."),
+ "x.ReadWriteGenerated");
+ RandomAccessFile f = new RandomAccessFile(fh,"rw");
+ for(int i = 0; i < 10000; i++){
+ f.writeLong(123456789L * (long)i);
+ }
+ f.close();
+ f = new RandomAccessFile(fh,"r");
+ for(int i = 0; i < 10000; i++){
+ long r = f.readLong();
+ if (r != (((long) i) * 123456789L) ) {
+ System.err.println("An error occurred. Read:" + r
+ + " i" + ((long) i));
+
+ throw new IOException("Bad read from a writeInt");
+ }
+ }
+ f.close();
+
+ }
+
+}
diff --git a/test/java/io/RandomAccessFile/Seek.java b/test/java/io/RandomAccessFile/Seek.java
new file mode 100644
index 0000000..72dcbbf
--- /dev/null
+++ b/test/java/io/RandomAccessFile/Seek.java
@@ -0,0 +1,49 @@
+/*
+ * 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 4140804
+ @summary Test if seek will throw exception given a
+ negative offset.
+*/
+
+
+
+import java.io.*;
+
+public class Seek
+{
+ public static void main(String argv[]) throws Exception
+ {
+ String dir = System.getProperty("test.src", ".");
+ RandomAccessFile raf = new RandomAccessFile
+ (new File(dir, "Seek.java"), "r");
+
+ try {
+ raf.seek(-10);
+ throw new Exception
+ ("Should have thrown an IOException when seek offset is < 0");
+ } catch (IOException e) {
+ }
+ }
+}
diff --git a/test/java/io/RandomAccessFile/SetLength.java b/test/java/io/RandomAccessFile/SetLength.java
new file mode 100644
index 0000000..fdf1497
--- /dev/null
+++ b/test/java/io/RandomAccessFile/SetLength.java
@@ -0,0 +1,82 @@
+/*
+ * 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
+ @summary General tests of the setLength method -- Should migrate to 1.2 JCK
+ */
+
+import java.io.*;
+
+
+public class SetLength {
+
+ static void fail(String s) {
+ throw new RuntimeException(s);
+ }
+
+ static void go(File fn, int max) throws IOException {
+ int chunk = max / 4;
+ long i;
+ RandomAccessFile f;
+
+ f = new RandomAccessFile(fn, "rw");
+ f.setLength(2 * chunk);
+ if (f.length() != 2 * chunk) fail("Length not increased to " + (2 * chunk));
+ if ((i = f.getFilePointer()) != 0) fail("File pointer shifted to " + i);
+ byte[] buf = new byte[max];
+ f.write(buf);
+ if (f.length() != max) fail("Write didn't work");
+ if (f.getFilePointer() != max) fail("File pointer inconsistent");
+ f.setLength(3 * chunk);
+ if (f.length() != 3 * chunk) fail("Length not reduced to " + 3 * chunk);
+ if (f.getFilePointer() != 3 * chunk) fail("File pointer not shifted to " + (3 * chunk));
+ f.seek(1 * chunk);
+ if (f.getFilePointer() != 1 * chunk) fail("File pointer not shifted to " + (1 * chunk));
+ f.setLength(2 * chunk);
+ if (f.length() != 2 * chunk) fail("Length not reduced to " + (2 * chunk));
+ if (f.getFilePointer() != 1 * chunk) fail("File pointer not shifted to " + (1 * chunk));
+ f.close();
+ }
+
+ public static void main(String[] args) throws IOException {
+ File fn = new File("x.SetLength");
+ try {
+ go(fn, 20);
+ fn.delete();
+ go(fn, 64 * 1024);
+ RandomAccessFile f = new RandomAccessFile(fn, "r");
+ boolean thrown = false;
+ try {
+ f.setLength(3);
+ } catch (IOException x) {
+ thrown = true;
+ }
+ if (!thrown) fail("setLength succeeded on a file opened read-only");
+ f.close();
+ }
+ finally {
+ fn.delete();
+ }
+ }
+
+}
diff --git a/test/java/io/RandomAccessFile/WriteBytesChars.java b/test/java/io/RandomAccessFile/WriteBytesChars.java
new file mode 100644
index 0000000..0440222
--- /dev/null
+++ b/test/java/io/RandomAccessFile/WriteBytesChars.java
@@ -0,0 +1,77 @@
+/*
+ * 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 4074388
+ @summary Check for correct implementation of RandomAccessFile.writeBytes
+ and writeChars.
+ */
+
+import java.io.*;
+
+public class WriteBytesChars {
+
+ public static void main(String args[]) throws Exception {
+ String towrite;
+ char[] buf = new char[80];
+ byte[] b = new byte[80];
+ File fn = new File("x.WriteBytesChars");
+
+ try{
+ RandomAccessFile raf = new RandomAccessFile(fn , "rw");;
+ for (int i = 0; i < 80; i++) {
+ buf[i] = 'a';
+ }
+ towrite = new String(buf);
+
+ raf.writeBytes(towrite);
+ raf.seek(0);
+ raf.read(b);
+
+ System.out.println("RandomAccessFile.writeBytes");
+ if (towrite.equals(new String(b))) {
+ System.err.println("Test succeeded.");
+ } else {
+ throw new
+ RuntimeException("RandomAccessFile.writeBytes, wrong result");
+ }
+
+ raf.seek(0);
+ raf.writeChars(towrite);
+ raf.seek(0);
+ for (int i = 0; i < 80; i++) {
+ buf[i] = raf.readChar();
+ }
+
+ System.out.println("RandomAccessFile.writeChars");
+ if (towrite.equals(new String(buf))) {
+ System.err.println("Test succeeded.");
+ } else {
+ throw new
+ RuntimeException("RandomAccessFile.writeChars, wrong result");
+ }
+ } finally {
+ fn.delete();
+ }
+ }
+}
diff --git a/test/java/io/RandomAccessFile/WriteUTF.java b/test/java/io/RandomAccessFile/WriteUTF.java
new file mode 100644
index 0000000..dd51822
--- /dev/null
+++ b/test/java/io/RandomAccessFile/WriteUTF.java
@@ -0,0 +1,61 @@
+/*
+ * 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 4018515
+ @summary Make sure that writeUTF throws a UTFDataFormatException when the
+ output string is too long
+ */
+
+import java.io.*;
+
+
+public class WriteUTF {
+
+ public static void main(String[] args) throws IOException {
+
+ RandomAccessFile f;
+ File fn = new File("x.WriteUTF");
+
+ String s = "\uffff";
+ for (int i = 0; i < 16; i++)
+ s += s;
+ System.err.println("String length " + s.length());
+
+ try {
+ f = new RandomAccessFile(fn, "rw");
+ try {
+ f.writeUTF(s);
+ }
+ catch (UTFDataFormatException x) {
+ return;
+ }
+ throw new RuntimeException("UTFDataFormatException not thrown");
+ }
+ finally {
+ fn.delete();
+ }
+
+ }
+
+}
diff --git a/test/java/io/RandomAccessFile/skipBytes/SkipBytes.java b/test/java/io/RandomAccessFile/skipBytes/SkipBytes.java
new file mode 100644
index 0000000..4ae5bdf
--- /dev/null
+++ b/test/java/io/RandomAccessFile/skipBytes/SkipBytes.java
@@ -0,0 +1,110 @@
+/*
+ * 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 4027717
+ @summary Check for correct implementation of RandomAccessFile.skipBytes
+ */
+
+
+import java.io.*;
+
+public class SkipBytes{
+
+
+ /*
+ * doTest attempts to skip num_to_skip bytes in raf starting from position 0.
+ * It also does a read after the skip to check if EOF has been reached
+ * correctly or incorrectly.
+ */
+
+
+ private static void doTest(RandomAccessFile raf, int start, int num_to_skip)
+ throws Exception
+ {
+
+ raf.seek(start);
+
+ long cur_ptr = raf.getFilePointer();
+ int length = (int) raf.length();
+ System.err.println("\nCurrent pointer = " + cur_ptr + " length = " +
+ length + " num_to_skip = " + num_to_skip);
+
+ //Do the Skip test
+ int num_skipped = raf.skipBytes(num_to_skip);
+ System.err.println("After skipBytes -- no. skipped = " + num_skipped);
+
+ // if num_to_skip is negative do the negative skip test
+ if (num_to_skip <= 0) {
+ if (num_skipped != 0){
+ System.err.println("Negative Skip Test Failed");
+ throw new RuntimeException("Negative Skip Test Failed");
+ }
+ else {
+ System.err.println("Negative Skip Test Succeeded");
+ }
+ }
+
+ cur_ptr = raf.getFilePointer();
+ System.err.println("Current pointer = " + cur_ptr);
+
+ // Check if skip has gone beyond EOF.
+ if (cur_ptr > length) {
+ System.err.println("Past EOF Skip Test Failed");
+ throw new RuntimeException("Past EOF Skip Test Failed");
+ }
+ else {
+ System.err.println("Past EOF Skip Test Succeeded");
+ }
+
+ // do read test
+ int byte_read = raf.read();
+ if ( (cur_ptr == length) &&
+ (byte_read != -1) ) {
+ System.err.println("byte_read = " + byte_read +
+ " Read Test Failed ......");
+ throw new RuntimeException("Read Test Failed");
+ }
+ else {
+ System.err.println("byte_read = " + byte_read +
+ " Read Test Succeeded");
+ }
+
+ }
+
+ public static void main(String[] args) throws Exception {
+
+ RandomAccessFile raf = new RandomAccessFile("input.txt" , "rw");
+ int length = (int)raf.length();
+
+ doTest(raf , 0 , 2*length);
+ doTest(raf , 0 , length);
+ doTest(raf , 0 , length/2);
+ doTest(raf , length/2 , -2);
+ doTest(raf , length , 0);
+ doTest(raf , 0 , -1);
+
+ }
+
+}
diff --git a/test/java/io/RandomAccessFile/skipBytes/input.txt b/test/java/io/RandomAccessFile/skipBytes/input.txt
new file mode 100644
index 0000000..a502418
--- /dev/null
+++ b/test/java/io/RandomAccessFile/skipBytes/input.txt
@@ -0,0 +1,3 @@
+foo
+goo
+moo