001package edu.pdx.cs410J.net;
002
003import java.io.*;
004
005/**
006 * This class demonstrates serialization support for referential
007 * integrity by deserializing a graph of <code>GraphNode</code>s.
008 */
009public class ReadGraphNodes {
010
011  /**
012   * Reads a graph of <code>GraphNode</code>s from a file whose name is
013   * specified on the command line.
014   */ 
015  public static void main(String[] args) {
016    String fileName = args[0];
017
018    try {
019      FileInputStream fis = new FileInputStream(fileName);
020      ObjectInputStream in = new ObjectInputStream(fis);
021      GraphNode root = (GraphNode) in.readObject();
022      System.out.println("Graph has " + root.traverse() + " nodes");
023
024    } catch (ClassNotFoundException ex) {
025      System.err.println("** No class: " + ex);
026      System.exit(1);
027
028    } catch (IOException ex) {
029      System.err.println("** IOException: " + ex);
030      System.exit(1);
031    }
032  }
033
034}