FileDocCategorySizeDatePackage
SerializationSizeTestFrame.javaAPI DocExample2691Thu Nov 08 00:23:48 GMT 2001com.ora.rmibook.chapter7.valueobjects

SerializationSizeTestFrame

public class SerializationSizeTestFrame extends ExitingFrame

Fields Summary
Constructors Summary
public SerializationSizeTestFrame()

    
Methods Summary
protected voidbuildGUI()

        JPanel contentPane = new JPanel(new BorderLayout());
        JTextArea center = new JTextArea();

        center.setText("The first serialized copy of Money is " + computeSizeOfMoney()
            + " bytes long. \n The second is only " + computeSizeOfSecondMoney()
            + " bytes long. \n Two ints only consume " + +computeSizeOfTwoInts());
        contentPane.add(center, BorderLayout.CENTER);
        setContentPane(contentPane);
        setSize(300, 100);
    
private intcomputeSizeOfMoney()

        ByteArrayOutputStream resultStream;

        resultStream = new ByteArrayOutputStream();
        try {
            ObjectOutputStream objectOutputStream = new sun.rmi.server.MarshalOutputStream(resultStream);
            Money money = new Money(50);

            objectOutputStream.writeObject(money);
            objectOutputStream.flush();
            return resultStream.size();
        } catch (Exception e) {
        }
        return 0;
    
private intcomputeSizeOfSecondMoney()

        ByteArrayOutputStream resultStream;

        resultStream = new ByteArrayOutputStream();
        try {
            ObjectOutputStream objectOutputStream = new sun.rmi.server.MarshalOutputStream(resultStream);
            Money money = new Money(50);
            Money money2 = new Money(510);

            objectOutputStream.writeObject(money);
            objectOutputStream.flush();
            int intermediateSize = resultStream.size();

            objectOutputStream.writeObject(money2);
            objectOutputStream.flush();
            return resultStream.size() - intermediateSize;
        } catch (Exception e) {
        }
        return 0;
    
private intcomputeSizeOfTwoInts()

        ByteArrayOutputStream resultStream;

        resultStream = new ByteArrayOutputStream();
        try {
            ObjectOutputStream objectOutputStream = new sun.rmi.server.MarshalOutputStream(resultStream);

            objectOutputStream.writeInt(50);
            objectOutputStream.writeInt(50);
            objectOutputStream.flush();
            return resultStream.size();
        } catch (Exception e) {
        }
        return 0;