All Packages  Class Hierarchy  Previous  Next  Index

Serial Examples

Serial 1 - No description available.

Serial 2 - No description available.


Serial1 Example Code

// Copyright(c) 1997 ObjectSpace, Inc.

import COM.objectspace.jgl.*;
import java.io.*;
import java.util.*;

public class Serial1
  {
  static public void write()
    {
    try
      {
      // create a map of acronyms
      HashMap map = new HashMap();
      map.add( "FAQ", "Frequently Asked Questions" );
      map.add( "OMG", "Object Management Group" );
      map.add( "ORB", "Object Request Broker" );

      // save map to a file
      ObjectOutput s =  new ObjectOutputStream( new FileOutputStream( "Serial1.bin" ) );
      s.writeObject( map );
      }
    catch ( IOException e )
      {
      System.out.println( "caught: " + e );
      }
    }

  static public void read()
    {
    try
      {
      // read map from file
      ObjectInputStream s = new ObjectInputStream( new FileInputStream( "Serial1.bin" ) );
      HashMap map = (HashMap)s.readObject();
      System.out.println( "ORB means " + map.get( "ORB" ) );
      System.out.println( "FAQ means " + map.get( "FAQ" ) );
      }
    catch ( IOException e1 )
      {
      System.out.println( "caught: " + e1 );
      }
    catch ( ClassNotFoundException e2 )
      {
      System.out.println( "caught: " + e2 );
      }
    }

  public static void main( String args[] )
    {
    write();
    read();
    }
  }

Serial1 Example Output

ORB means Object Request Broker
FAQ means Frequently Asked Questions

Serial2 Example Code

// Copyright(c) 1997 ObjectSpace, Inc.

import COM.objectspace.jgl.*;
import java.io.*;
import java.util.*;

public class Serial2
  {
  static public void write()
    {
    try
      {
      // create a list of names
      DList names = new DList();
      names.add( "Peter Parker" );
      names.add( "Frank Castle" );
      names.add( "Logan" );
      names.add( "Steve Rogers" );

      // save names to a file
      ObjectOutput s =  new ObjectOutputStream( new FileOutputStream( "Serial2.bin" ) );
      s.writeObject( names );

      // search for some particular entries
      ForwardIterator wolverine = names.find( "Logan" );
      ForwardIterator hulk = names.find( "Bruce Banner" );

      // write the iterators to the file as well
      s.writeObject( wolverine );
      s.writeObject( hulk );
      }
    catch ( IOException e )
      {
      System.out.println( "caught: " + e );
      }
    }

  static public void read()
    {
    try
      {
      // read sequence and iterator from file
      ObjectInputStream s = new ObjectInputStream( new FileInputStream( "Serial2.bin" ) );
      DList names = (DList)s.readObject();
      ForwardIterator wolverine = (ForwardIterator)s.readObject();
      ForwardIterator hulk = (ForwardIterator)s.readObject();

      // check the iterators
      if ( wolverine.equals( names.end() ) )
        System.out.println( "Don't know who Wolverine is" );
      else
        System.out.println( "Wolverine is also known as " + wolverine.get() );
      if ( hulk.equals( names.end() ) )
        System.out.println( "Don't know who the Hulk is" );
      else
        System.out.println( "Hulk is also known as " + hulk.get() );
      }
    catch ( IOException e1 )
      {
      System.out.println( "caught: " + e1 );
      }
    catch ( ClassNotFoundException e2 )
      {
      System.out.println( "caught: " + e2 );
      }
    }

  public static void main( String args[] )
    {
    write();
    read();
    }
  }

Serial2 Example Output

Wolverine is also known as Logan
Don't know who the Hulk is

All Packages  Class Hierarchy  Previous  Next  Index