/* * [Dump.java] * * Summary: Debugging tool to dump out a snippet ser file to see the tokens. * * Copyright: (c) 2004-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.0 2004-05-15 */ package com.mindprod.jprep; import com.mindprod.common18.EIO; import com.mindprod.jdisplay.Footprint; import com.mindprod.jdisplayaux.WaysToRender; import com.mindprod.jtokens.Token; import java.io.File; import java.io.IOException; import java.io.ObjectInputStream; import static com.mindprod.jdisplay.Geometry.DEFAULT_MAX_HEIGHT_PX; import static com.mindprod.jdisplay.Geometry.DEFAULT_MAX_WIDTH_PX; import static java.lang.System.*; /** * Debugging tool to dump out a snippet ser file to see the tokens. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2004-05-15 * @since 2004-05-15 */ public final class Dump { /** * array of token to dump */ private static Token[] tokens; /** * debugging dump of all tokens */ private static void dump() { for ( Token t : tokens ) { out.println( t ); } } /** * @param args filename of snippet, without lead snippet/ser or trailing .ser. Current directory must be the snippet * dir, not the corresponding documents directory , not the ser directory. * * @throws ClassNotFoundException this is just a debug tool * @throws IOException this is just a debug tool */ public static void main( String[] args ) throws IOException, ClassNotFoundException { final String filename = args[ 0 ]; boolean quick = false; if ( args.length > 1 ) { quick = args[ 1 ].equalsIgnoreCase( "/q" ); } // O P E N // relative to current snippet dir. final ObjectInputStream ois = EIO.getObjectInputStream( new File( "ser/" + filename + ".ser" ), 4 * 1024, true ); final long expectedVersion = Footprint.serialVersionUID; final long fileVersion = ( Long ) ois.readObject(); if ( fileVersion != expectedVersion ) { err.println( "\007Stale " + filename + ". Version " + fileVersion + " should be " + expectedVersion ); } out.println( filename ); Footprint footprint = ( Footprint ) ois.readObject(); tokens = ( Token[] ) ois.readObject(); // calculate field not in serial version footprint = WaysToRender.bestFit( footprint, DEFAULT_MAX_WIDTH_PX, DEFAULT_MAX_HEIGHT_PX ); out.println( footprint ); // C L O S E ois.close(); if ( !quick ) { dump(); } } } // end dump