package filer;



import java.io.*;





public class NewVersion

{	static void readshow(String filename)

	{  	try

  		{	ObjectInputStream in = new ObjectInputStream(new FileInputStream(filename));

  			Object newf = in.readObject();

  			System.out.println(newf);

  			System.out.println(newf.getClass().getName());

  		} 

  		catch (ClassNotFoundException e)

  		{	System.out.println("Illegal Class def");

  		}

  		catch(StreamCorruptedException sc)

  		{	System.out.println("Stream corrupted");

  		}

  		catch(IOException io)

  		{	System.out.println("IO exception reading");

  		}

  		catch(Throwable tr)

  		{	tr.printStackTrace();

  		}

  		finally

  		{ 	try 

 			{	System.out.println("finally");

 				System.out.flush();

 				System.err.flush();

 				System.in.read(); // prevent console window from going away

			} catch (java.io.IOException e) {}

  		}

	}

	

	public static void updateFileForNewVersion(String filenameIn, String filenameOut)

	{  	try

  		{	ObjectInputStream in = new ObjectInputStream(new FileInputStream(filenameIn));

  			Versionable f = (Versionable)in.readObject();

  			Object f2 = f.newVersion(null); //This is the version transfomation

	  		try

	  		{	ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream (filenameOut));

	  			out.writeObject(f2);

	  		}

	  		catch (IOException io)

	  		{	System.out.println("cant open output file for new version");

	  		}

  			

  		} 

  		catch (ClassNotFoundException e)

  		{	System.out.println("Illegal Class def");

  		}

  		catch(StreamCorruptedException sc)

  		{	System.out.println("Stream corrupted");

  		}

  		catch(IOException io)

  		{	System.out.println("IO exception in transform");

  		}

  		finally

  		{ 	try 

 			{	System.in.read(); // prevent console window from going away

			} catch (java.io.IOException e) {}

  		}



	}



	public static void main (String [] args)

	{	System.out.println( "Hello World!" );

		readshow("test6.dat");

		updateFileForNewVersion(args[0], args[1]);

		readshow("test7.dat");

  		try 

 		{	System.out.flush();

 			System.err.flush();

 			System.in.read(); // prevent console window from going away

 			System.in.read(); // prevent console window from going away

		} catch (java.io.IOException e) {}



	}

}