use of java.io.RandomAccessFile in project j2objc by google.
the class OldRandomAccessFileTest method test_readFully$B_writeBytesLjava_lang_String.
/**
* java.io.RandomAccessFile#writeBytes(java.lang.String)
* java.io.RandomAccessFile#readFully(byte[])
*/
public void test_readFully$B_writeBytesLjava_lang_String() throws IOException {
byte[] buf = new byte[testLength];
RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
raf.writeBytes(testString);
raf.seek(0);
try {
raf.readFully(null);
fail("Test 1: NullPointerException expected.");
} catch (NullPointerException e) {
// Expected.
}
raf.readFully(buf);
assertEquals("Test 2: Incorrect bytes written or read;", testString, new String(buf));
try {
raf.readFully(buf);
fail("Test 3: EOFException expected.");
} catch (EOFException e) {
// Expected.
}
raf.close();
try {
raf.writeBytes("Already closed.");
fail("Test 4: IOException expected.");
} catch (IOException e) {
// Expected.
}
try {
raf.readFully(buf);
fail("Test 5: IOException expected.");
} catch (IOException e) {
// Expected.
}
}
use of java.io.RandomAccessFile in project j2objc by google.
the class OldRandomAccessFileTest method test_seekJ.
/**
* java.io.RandomAccessFile#seek(long)
*/
public void test_seekJ() throws IOException {
// Test for method void java.io.RandomAccessFile.seek(long)
RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
try {
raf.seek(-1);
fail("Test 1: IOException expected.");
} catch (IOException e) {
// Expected.
}
raf.write(testString.getBytes(), 0, testLength);
raf.seek(12);
assertEquals("Test 3: Seek failed to set file pointer.", 12, raf.getFilePointer());
raf.close();
try {
raf.seek(1);
fail("Test 4: IOException expected.");
} catch (IOException e) {
// Expected.
}
}
use of java.io.RandomAccessFile in project j2objc by google.
the class OldRandomAccessFileTest method test_ConstructorLjava_io_FileLjava_lang_String.
/**
* java.io.RandomAccessFile#RandomAccessFile(java.io.File,
* java.lang.String)
*/
public void test_ConstructorLjava_io_FileLjava_lang_String() throws Exception {
RandomAccessFile raf = null;
File tmpFile = new File(fileName);
try {
raf = new java.io.RandomAccessFile(tmpFile, "r");
fail("Test 1: FileNotFoundException expected.");
} catch (FileNotFoundException e) {
// Expected.
} catch (IllegalArgumentException e) {
fail("Test 2: Unexpected IllegalArgumentException: " + e.getMessage());
}
tmpFile.createNewFile();
try {
// Checking the remaining valid mode parameters.
try {
raf = new java.io.RandomAccessFile(tmpFile, "rwd");
} catch (IllegalArgumentException e) {
fail("Test 3: Unexpected IllegalArgumentException: " + e.getMessage());
}
raf.close();
try {
raf = new java.io.RandomAccessFile(tmpFile, "rws");
} catch (IllegalArgumentException e) {
fail("Test 4: Unexpected IllegalArgumentException: " + e.getMessage());
}
raf.close();
try {
raf = new java.io.RandomAccessFile(tmpFile, "rw");
} catch (IllegalArgumentException e) {
fail("Test 5: Unexpected IllegalArgumentException: " + e.getMessage());
}
raf.close();
// Checking an invalid mode parameter.
try {
raf = new java.io.RandomAccessFile(tmpFile, "i");
fail("Test 6: IllegalArgumentException expected.");
} catch (IllegalArgumentException e) {
// Expected.
}
} finally {
if (raf != null)
raf.close();
tmpFile.delete();
}
}
use of java.io.RandomAccessFile in project j2objc by google.
the class OldRandomAccessFileTest method test_readUnsignedShort.
/**
* java.io.RandomAccessFile#readUnsignedShort()
*/
public void test_readUnsignedShort() throws IOException {
RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
raf.writeShort(-1);
raf.seek(0);
assertEquals("Test 1: Incorrect value written or read;", 65535, raf.readUnsignedShort());
try {
raf.readUnsignedShort();
fail("Test 2: EOFException expected.");
} catch (EOFException e) {
// Expected.
}
raf.close();
try {
raf.readUnsignedShort();
fail("Test 3: IOException expected.");
} catch (IOException e) {
// Expected.
}
}
use of java.io.RandomAccessFile in project j2objc by google.
the class OldRandomAccessFileTest method test_skipBytesI.
/**
* java.io.RandomAccessFile#skipBytes(int)
*/
public void test_skipBytesI() throws IOException {
byte[] buf = new byte[5];
RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
raf.writeBytes("HelloWorld");
raf.seek(0);
assertTrue("Test 1: Nothing should be skipped if parameter is less than zero", raf.skipBytes(-1) == 0);
assertEquals("Test 4: Incorrect number of bytes skipped; ", 5, raf.skipBytes(5));
raf.readFully(buf);
assertEquals("Test 3: Failed to skip bytes.", "World", new String(buf, 0, 5));
raf.seek(0);
assertEquals("Test 4: Incorrect number of bytes skipped; ", 10, raf.skipBytes(20));
raf.close();
try {
raf.skipBytes(1);
fail("Test 5: IOException expected.");
} catch (IOException e) {
// Expected.
}
}
Aggregations