mirror of
https://github.com/corda/corda.git
synced 2025-01-03 19:54:13 +00:00
verify file contents in FileOutput test
This commit is contained in:
parent
be1ba2ccf8
commit
7eabe13921
@ -1,7 +1,8 @@
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public class FileOutput {
|
||||
|
||||
/**
|
||||
@ -9,6 +10,7 @@ public class FileOutput {
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void main(String[] args) throws IOException {
|
||||
try {
|
||||
FileOutputStream f = new FileOutputStream("test.txt");
|
||||
f.write("Hello world!\n".getBytes());
|
||||
f.close();
|
||||
@ -17,7 +19,22 @@ public class FileOutput {
|
||||
f2.write("Hello world again!".getBytes());
|
||||
f2.close();
|
||||
|
||||
FileInputStream in = new FileInputStream("test.txt");
|
||||
byte[] buffer = new byte[256];
|
||||
int c;
|
||||
int offset = 0;
|
||||
while ((c = in.read(buffer, offset, buffer.length - offset)) != -1) {
|
||||
offset += c;
|
||||
}
|
||||
|
||||
if (! "Hello world!\nHello world again!".equals
|
||||
(new String(buffer, 0, offset)))
|
||||
{
|
||||
throw new RuntimeException();
|
||||
}
|
||||
} finally {
|
||||
new File("test.txt").delete();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user