1 9 package org.ozoneDB.tools; 10 11 import org.ozoneDB.DxLib.DxObject; 12 import org.ozoneDB.io.stream.ResolvingObjectInputStream; 13 14 import java.io.*; 15 16 17 public class Statistics extends Object { 18 static String dir = File.separator + "stats"; 19 public static String clusp = new String ( "clusp" ); 20 21 22 public static void main( String [] args ) { 23 try { 24 String odbdir = args[0].toString(); 25 System.out.println( "ODB3X statistics" ); 26 System.out.println( "----------------" ); 27 printLastOID( odbdir ); 28 printStats( odbdir ); 29 } catch (Exception e) { 30 System.out.println( "\nusage: java Statistics <dir>" ); 31 System.exit( 1 ); 32 } 33 } 34 35 36 public static void printLastOID( String odbdir ) { 37 } 51 52 53 public static void printStats( String odbdir ) { 54 System.out.print( "\nClusterSpace stats:" ); 55 System.out.println( readClusterStats( odbdir ) ); 56 } 57 58 59 public static void writeStats( DxObject cs, String path, String file ) { 60 try { 61 File f = new File( path + dir ); 62 if (!f.exists()) { 63 f.mkdir(); 64 } 65 f = new File( path + dir, file ); 66 FileOutputStream fo = new FileOutputStream( f ); 67 ObjectOutputStream os = new ObjectOutputStream( fo ); 68 os.writeObject( cs ); 69 os.close(); 70 } catch (Exception e) { 71 System.out.println( e ); 72 } 73 } 74 75 76 public static DxObject readStats( String path, String file ) { 77 try { 78 File f = new File( path + dir, file ); 79 FileInputStream fi = new FileInputStream( f ); 80 ObjectInputStream is = new ResolvingObjectInputStream( fi ); 81 DxObject obj = (DxObject)is.readObject(); 82 fi.close(); 83 return obj; 84 } catch (FileNotFoundException e) { 85 } catch (Exception e) { 87 System.out.println( e ); 88 } 89 return null; 90 } 91 92 93 public static void writeClusterStats( ClusterStats cs, String path ) { 94 writeStats( cs, path, clusp ); 95 } 96 97 98 public static ClusterStats readClusterStats( String path ) { 99 ClusterStats cs = (ClusterStats)Statistics.readStats( path, clusp ); 100 if (cs == null) { 101 cs = new ClusterStats(); 102 writeClusterStats( cs, path ); 103 } 104 return cs; 105 } 106 } 107 | Popular Tags |