FileDocCategorySizeDatePackage
MoneyWriter.javaAPI DocExample1491Thu Nov 08 00:22:32 GMT 2001com.ora.rmibook.chapter10

MoneyWriter

public class MoneyWriter extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

        writeOne();
        writeMany();
    
private static voidwriteMany()

        try {
            System.out.println("Writing many instances");
            ArrayList listOfMoney = new ArrayList();

            for (int i = 0; i < 10000; i++) {
                ReallyEfficientMoney money = new ReallyEfficientMoney(i * 100);

                listOfMoney.add(money);
            }
            writeObject("C:\\temp\\foo2", listOfMoney);
        } catch (Exception e) {
        }
    
private static voidwriteObject(java.lang.String filename, java.lang.Object object)

        FileOutputStream fileOutputStream = new FileOutputStream(filename);
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
        long startTime = System.currentTimeMillis();

        objectOutputStream.writeObject(object);
        objectOutputStream.flush();
        objectOutputStream.close();
        System.out.println("Time: " + (System.currentTimeMillis() - startTime));
    
private static voidwriteOne()

        try {
            System.out.println("Writing one instance");
            ReallyEfficientMoney money = new ReallyEfficientMoney(1000);

            writeObject("C:\\temp\\foo", money);
        } catch (Exception e) {
        }