// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
package fastser;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class TestCus extends Test {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        long t1 = System.currentTimeMillis();
        DataOutputStream dos = new DataOutputStream(new FileOutputStream("C:\\sercus.dat"));
        for(int i = 0; i < N; i++) {
            SomeData o = new SomeData(IV + i, XV, SV);
            dos.writeInt(o.getIv());
            dos.writeDouble(o.getXv());
            dos.writeUTF(o.getSv());
        }
        dos.close();
        DataInputStream dis = new DataInputStream(new FileInputStream("C:\\sercus.dat"));
        for(int i = 0; i < N; i++) {
            SomeData o2 = new SomeData();
            o2.setIv(dis.readInt());
            o2.setXv(dis.readDouble());
            o2.setSv(dis.readUTF());
            if((o2.getIv() != IV + i) || (o2.getXv() != XV) || !o2.getSv().equals(SV)) {
                throw new RuntimeException("Data corruption");
            }
        }
        dis.close();
        long t2 = System.currentTimeMillis();
        System.out.println(t2 - t1);
    }
}
