📄 inputlog.java
字号:
/* * (C) 2001 by Argonne National Laboratory * See COPYRIGHT in top-level directory. *//* * @author Anthony Chan */package logformat.slog2.input;import java.util.Comparator;import java.util.Iterator;import java.util.SortedSet;import java.util.TreeSet;import java.util.Map;import java.io.*;import base.io.MixedRandomAccessFile;import base.io.MixedDataInputStream;import base.io.MixedDataIO;import base.drawable.TimeBoundingBox;import base.drawable.Drawable;import logformat.slog2.*;public class InputLog{ public static final int ITERATE_ALL = 0; public static final int ITERATE_ARROWS = 1; public static final int ITERATE_STATES = 2; private MixedRandomAccessFile rand_file; private ByteArrayInputStream bary_ins; private MixedDataInputStream data_ins; private Header filehdr; private TreeDir treedir; private CategoryMap objdefs; private LineIDMapList lineIDmaps; private byte[] buffer; private String full_pathname; public InputLog( String filename ) { full_pathname = filename; rand_file = null; try { rand_file = new MixedRandomAccessFile( full_pathname, "r" ); // } catch ( FileNotFoundException ferr ) { } catch ( IOException ferr ) { System.err.println( "InputLog: Non-recoverable IOException! " + "Exiting ..." ); ferr.printStackTrace(); System.exit( 1 ); } buffer = null; bary_ins = null; data_ins = null; } // Used by Jumpshot4 to add extra titles to Timeline/Legend windows public String getPathnameSuffix() { String file_sep = System.getProperty( "file.separator" ); int start_idx = full_pathname.lastIndexOf( file_sep ); if ( start_idx > 0 ) return full_pathname.substring( start_idx + 1 ); else return full_pathname; } public String getLineIDMapName( int view_ID ) { if ( lineIDmaps != null ) if ( view_ID >= 0 && view_ID < lineIDmaps.size() ) { LineIDMap lineIDmap = (LineIDMap) lineIDmaps.get( view_ID ); return lineIDmap.getTitle(); } else return null; else return null; } /* isSLOG2() has to be called before getCompatibleHeader() or initialize() */ public boolean isSLOG2() { try { rand_file.seek( 0 ); filehdr = new Header( rand_file ); } catch ( IOException ioerr ) { System.err.println( "InputLog: Non-recoverable IOException! " + "Exiting ..." ); ioerr.printStackTrace(); System.exit( 1 ); } return filehdr != null && filehdr.isSLOG2(); } public String getCompatibleHeader() { return filehdr.getCompatibleVersionMessage(); } public static void stdoutConfirmation() { byte[] str_bytes = new byte[ 10 ]; System.out.print( "Do you still want the program to continue ? " + "y/yes to continue : " ); try { System.in.read( str_bytes ); } catch ( IOException ioerr ) { System.err.println( "InputLog: Non-recoverable IOException! " + "Exiting ..." ); ioerr.printStackTrace(); System.exit( 1 ); } String in_str = ( new String( str_bytes ) ).trim(); if ( in_str.equals( "y" ) || in_str.equals( "yes" ) ) System.out.println( "Program continues...." ); else { System.out.println( "Program is terminating!..." ); System.exit( 1 ); } } public void initialize() { buffer = new byte[ filehdr.getMaxBufferByteSize() ]; readTreeDir(); readCategoryMap(); readLineIDMapList(); } public FileBlockPtr getFileBlockPtrToTreeRoot() { return filehdr.blockptr2treeroot; } public int getTreeLeafByteSize() { return filehdr.getTreeLeafByteSize(); } public short getNumChildrenPerNode() { return filehdr.getNumChildrenPerNode(); } public short getMaxTreeDepth() { return filehdr.getMaxTreeDepth(); }/* private void readHeader() { try { rand_file.seek( 0 ); filehdr = new Header( rand_file ); } catch ( IOException ioerr ) { System.err.println( "InputLog: Non-recoverable IOException! " + "Exiting ..." ); ioerr.printStackTrace(); System.exit( 1 ); } if ( ! filehdr.isVersionCompatible() ) { byte[] str_bytes = new byte[ 10 ]; System.out.print( "Do you still want the program to continue ? " + "y/yes to continue : " ); try { System.in.read( str_bytes ); } catch ( IOException ioerr ) { System.err.println( "InputLog: Non-recoverable IOException! " + "Exiting ..." ); ioerr.printStackTrace(); System.exit( 1 ); } String in_str = ( new String( str_bytes ) ).trim(); if ( in_str.equals( "y" ) || in_str.equals( "yes" ) ) System.out.println( "Program continues...." ); else { System.out.println( "Program is terminating!..." ); System.exit( 1 ); } } }*/ /* The returned String of readFilePart() is the error message. If readFilePart() returns without error, the returned value is null */ private String readFilePart( final FileBlockPtr blockptr, final String filepartname, MixedDataIO filepart ) { String err_str; if ( blockptr.isNULL() ) { err_str = "The file block pointer to the " + filepartname + " " + "is NOT initialized!, can't read it."; return err_str; } if ( blockptr.getBlockSize() > filehdr.getMaxBufferByteSize() ) { err_str = "Oops! Unexpected Error: " + "The block size of the " + filepartname + " is " + "too big to read into buffer for processing."; return err_str; } long blk_fptr = blockptr.getFilePointer(); int blk_size = blockptr.getBlockSize(); try { rand_file.seek( blk_fptr ); rand_file.readFully( buffer, 0, blk_size ); bary_ins = new ByteArrayInputStream( buffer, 0, blk_size ); data_ins = new MixedDataInputStream( bary_ins ); filepart.readObject( data_ins ); data_ins.close(); } catch ( IOException ioerr ) { System.err.println( "InputLog: Non-recoverable IOException! " + "Exiting ..." ); ioerr.printStackTrace(); System.exit( 1 ); } return null; } private void readLineIDMapList() { String err_str; lineIDmaps = new LineIDMapList(); err_str = readFilePart( filehdr.blockptr2lineIDmaps, "LineIDMapList", lineIDmaps ); if ( err_str != null ) { System.err.println( err_str ); System.exit( 1 ); } } public LineIDMapList getLineIDMapList() { return lineIDmaps; } private void readTreeDir() { String err_str; treedir = new TreeDir(); err_str = readFilePart( filehdr.blockptr2treedir, "Tree Directory", treedir ); if ( err_str != null ) { System.err.println( err_str ); System.exit( 1 ); } } public TreeDir getTreeDir() { return treedir; } private void readCategoryMap() { String err_str; objdefs = new CategoryMap(); err_str = readFilePart( filehdr.blockptr2categories, "CategoryMap", objdefs ); if ( err_str != null ) { System.err.println( err_str ); System.exit( 1 ); } } public CategoryMap getCategoryMap() { return objdefs; }/* public TreeNode readTreeNode( final FileBlockPtr blockptr ) { String err_str;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -