1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir import java.io.*; 29*cdf0e10cSrcweir import java.util.*; 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir public class pdbcomparison 32*cdf0e10cSrcweir { 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir private String LOGTAG ="LOGFILE"; 35*cdf0e10cSrcweir private String OUTTAG ="OUTFILE"; 36*cdf0e10cSrcweir private String LISTTAG ="LISTFILE"; 37*cdf0e10cSrcweir private String PDBTAG1 ="PDBNAME1"; 38*cdf0e10cSrcweir private String PDBTAG2 ="PDBNAME2"; 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir private String OUTFILE="pdbcomparison.out"; 41*cdf0e10cSrcweir private String LOGFILE="pdbcomparison.log"; 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir private String pdbarr1[]; 44*cdf0e10cSrcweir private String pdbarr2[]; 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir /** 48*cdf0e10cSrcweir * Default Constructor 49*cdf0e10cSrcweir * 50*cdf0e10cSrcweir * @param 51*cdf0e10cSrcweir * @return 52*cdf0e10cSrcweir * 53*cdf0e10cSrcweir */ 54*cdf0e10cSrcweir public void pdbcomparison() 55*cdf0e10cSrcweir { 56*cdf0e10cSrcweir } 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir /** 59*cdf0e10cSrcweir * Prints the command line arguments for this class 60*cdf0e10cSrcweir * 61*cdf0e10cSrcweir * @param 62*cdf0e10cSrcweir * 63*cdf0e10cSrcweir * @return void 64*cdf0e10cSrcweir * 65*cdf0e10cSrcweir */ 66*cdf0e10cSrcweir public void usage() 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir String str = new String(); 69*cdf0e10cSrcweir str += "********************************************************\n"; 70*cdf0e10cSrcweir str += " java pdbcomparison.java <propFile> \n"; 71*cdf0e10cSrcweir str += " where propFile is name of Property File...\n"; 72*cdf0e10cSrcweir str += "********************************************************\n"; 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir System.out.println(str); 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir } 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir /** 79*cdf0e10cSrcweir * This method, read the Property file and validates the 80*cdf0e10cSrcweir * entries in that file, and accordingly sets the log file 81*cdf0e10cSrcweir * output file and updates the array pdbarr1 and pdbarr2 with 82*cdf0e10cSrcweir * list of pdb's to be compared. 83*cdf0e10cSrcweir * 84*cdf0e10cSrcweir * @param propFile Property filename which list the log/outputfile/list/pdb 85*cdf0e10cSrcweir * names 86*cdf0e10cSrcweir * @return 87*cdf0e10cSrcweir * 88*cdf0e10cSrcweir */ 89*cdf0e10cSrcweir public void parsePropertyFile(String propFile) 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir Properties defaultProps = new Properties(); 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir try { 94*cdf0e10cSrcweir FileInputStream in = new FileInputStream(propFile); 95*cdf0e10cSrcweir defaultProps.load(in); 96*cdf0e10cSrcweir in.close(); 97*cdf0e10cSrcweir } catch (IOException e) { 98*cdf0e10cSrcweir System.out.println("Could not open Property File " + propFile); 99*cdf0e10cSrcweir return; 100*cdf0e10cSrcweir } 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir String logFile = defaultProps.getProperty(this.LOGTAG); 104*cdf0e10cSrcweir String outFile = defaultProps.getProperty(this.OUTTAG); 105*cdf0e10cSrcweir String listFile = defaultProps.getProperty(this.LISTTAG); 106*cdf0e10cSrcweir String pdbname1 = defaultProps.getProperty(this.PDBTAG1); 107*cdf0e10cSrcweir String pdbname2 = defaultProps.getProperty(this.PDBTAG2); 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir // validate all command line arguments 110*cdf0e10cSrcweir if ((listFile == null) && ((pdbname1 == null) || (pdbname2 == null))) 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir System.out.println("Missing listFile or missing pdb filenames in Property file " + propFile); 113*cdf0e10cSrcweir return; 114*cdf0e10cSrcweir } 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir if (logFile == null || logFile.length() == 0) 117*cdf0e10cSrcweir logFile = this.LOGFILE; 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir if (outFile == null || outFile.length() == 0) 120*cdf0e10cSrcweir outFile = this.LOGFILE; 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir // validate log and output files 124*cdf0e10cSrcweir if (! validateAndCreateFile(logFile)) return; 125*cdf0e10cSrcweir if (! validateAndCreateFile(outFile)) return; 126*cdf0e10cSrcweir LOGFILE = logFile; 127*cdf0e10cSrcweir OUTFILE = outFile; 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir System.out.println("Output is written to log file... " + LOGFILE); 130*cdf0e10cSrcweir if (listFile != null) 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir if (! checkFile(listFile)) return; 133*cdf0e10cSrcweir populatePDBArray(listFile); 134*cdf0e10cSrcweir } else { 135*cdf0e10cSrcweir if (! checkFile(pdbname1)) return; 136*cdf0e10cSrcweir if (! checkFile(pdbname2)) return; 137*cdf0e10cSrcweir populatePDBArray(pdbname1, pdbname2); 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir /** 142*cdf0e10cSrcweir * This method validates if the file passed exists. 143*cdf0e10cSrcweir * If it does , then it is moved to <filename>.bak and then creates a newFile. 144*cdf0e10cSrcweir * Also validates permissions to create. 145*cdf0e10cSrcweir * 146*cdf0e10cSrcweir * @param filename name of file to be created 147*cdf0e10cSrcweir * @return true, if file could be created 148*cdf0e10cSrcweir * false, if could not. 149*cdf0e10cSrcweir * 150*cdf0e10cSrcweir */ 151*cdf0e10cSrcweir private boolean validateAndCreateFile (String filename) 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir if (filename == null) return false; 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir File f = null; 156*cdf0e10cSrcweir try { 157*cdf0e10cSrcweir f = new File(filename); 158*cdf0e10cSrcweir } catch (NullPointerException e) { 159*cdf0e10cSrcweir System.out.println("Could not create a File object for file " + filename); 160*cdf0e10cSrcweir return false; 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir if (f.exists()) 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir String newFile = filename + ".bak"; 166*cdf0e10cSrcweir File newF=null; 167*cdf0e10cSrcweir try { 168*cdf0e10cSrcweir newF = new File(newFile); 169*cdf0e10cSrcweir } catch (Exception ex) { 170*cdf0e10cSrcweir System.out.println("Could not get File Object instance for " + newFile); 171*cdf0e10cSrcweir return false; 172*cdf0e10cSrcweir } 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir if (newF.exists()) 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir try { 177*cdf0e10cSrcweir newF.delete(); 178*cdf0e10cSrcweir } catch ( SecurityException se) { 179*cdf0e10cSrcweir System.out.println("Could not get delete " + newFile); 180*cdf0e10cSrcweir return false; 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir try { 185*cdf0e10cSrcweir if (! f.renameTo(newF)) 186*cdf0e10cSrcweir { 187*cdf0e10cSrcweir System.out.println("Could not rename " + filename + " to " + newFile ); 188*cdf0e10cSrcweir return false; 189*cdf0e10cSrcweir } 190*cdf0e10cSrcweir } catch (SecurityException s) { 191*cdf0e10cSrcweir System.out.println("SecurityException: " + s.toString()); 192*cdf0e10cSrcweir return false; 193*cdf0e10cSrcweir } catch (NullPointerException n) { 194*cdf0e10cSrcweir System.out.println("NullPointerException: " + n.toString()); 195*cdf0e10cSrcweir return false; 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir } else { 198*cdf0e10cSrcweir try { 199*cdf0e10cSrcweir if (! f.createNewFile()) 200*cdf0e10cSrcweir { 201*cdf0e10cSrcweir System.out.println("Could not create " + filename + " Check permissions.."); 202*cdf0e10cSrcweir return false; 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir } catch (IOException e) { 205*cdf0e10cSrcweir System.out.println("IOException: " + e.toString()); 206*cdf0e10cSrcweir return false; 207*cdf0e10cSrcweir } catch (SecurityException s) { 208*cdf0e10cSrcweir System.out.println("SecuriityException: " + s.toString() ); 209*cdf0e10cSrcweir return false; 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir } 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir return true; 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir /** 219*cdf0e10cSrcweir * This method validates if the file exists and is readable 220*cdf0e10cSrcweir * 221*cdf0e10cSrcweir * @param filename name of file to be created 222*cdf0e10cSrcweir * @return true, if file exists and is readable 223*cdf0e10cSrcweir * false, if not. 224*cdf0e10cSrcweir * 225*cdf0e10cSrcweir */ 226*cdf0e10cSrcweir private boolean checkFile(String filename) 227*cdf0e10cSrcweir { 228*cdf0e10cSrcweir if (filename == null) return false; 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir File f = null; 231*cdf0e10cSrcweir try { 232*cdf0e10cSrcweir f = new File(filename); 233*cdf0e10cSrcweir } catch (NullPointerException e) { 234*cdf0e10cSrcweir System.out.println("Could not create a File object for file " + filename); 235*cdf0e10cSrcweir return false; 236*cdf0e10cSrcweir } 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir if (! f.exists()) 239*cdf0e10cSrcweir { 240*cdf0e10cSrcweir System.out.println("File " + filename + " does not exist... "); 241*cdf0e10cSrcweir return false; 242*cdf0e10cSrcweir } 243*cdf0e10cSrcweir 244*cdf0e10cSrcweir if (! f.canRead()) 245*cdf0e10cSrcweir { 246*cdf0e10cSrcweir System.out.println("Cannot read file " + filename); 247*cdf0e10cSrcweir return false; 248*cdf0e10cSrcweir } 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir return true; 251*cdf0e10cSrcweir 252*cdf0e10cSrcweir } 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir /** 255*cdf0e10cSrcweir * This method populates the pdb arrays with the names of the pdbs to 256*cdf0e10cSrcweir * compare. Ths listFile lists a series of entries, wherein each 257*cdf0e10cSrcweir * line indicates the PDB names to be compared. 258*cdf0e10cSrcweir * <pdbname1>=<pdbname2> 259*cdf0e10cSrcweir * 260*cdf0e10cSrcweir * @param listFile name of the listfile 261*cdf0e10cSrcweir * @return 262*cdf0e10cSrcweir * 263*cdf0e10cSrcweir */ 264*cdf0e10cSrcweir private void populatePDBArray(String listFile) 265*cdf0e10cSrcweir { 266*cdf0e10cSrcweir // open ListFile and populate the PDB list to be compared 267*cdf0e10cSrcweir if (listFile != null) 268*cdf0e10cSrcweir { 269*cdf0e10cSrcweir Properties listProps = new Properties(); 270*cdf0e10cSrcweir try { 271*cdf0e10cSrcweir FileInputStream in = new FileInputStream(listFile); 272*cdf0e10cSrcweir listProps.load(in); 273*cdf0e10cSrcweir in.close(); 274*cdf0e10cSrcweir } catch (IOException ex) { 275*cdf0e10cSrcweir System.out.println("Could not open List File " + listFile); 276*cdf0e10cSrcweir return; 277*cdf0e10cSrcweir } 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir pdbarr1 = new String[listProps.size()]; 280*cdf0e10cSrcweir pdbarr2 = new String[listProps.size()]; 281*cdf0e10cSrcweir Enumeration e = listProps.keys(); 282*cdf0e10cSrcweir int j=0; 283*cdf0e10cSrcweir while (e.hasMoreElements()) 284*cdf0e10cSrcweir { 285*cdf0e10cSrcweir pdbarr1[j] = (String)e.nextElement(); 286*cdf0e10cSrcweir pdbarr2[j] = listProps.getProperty(pdbarr1[j]); 287*cdf0e10cSrcweir j++; 288*cdf0e10cSrcweir } 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir } 291*cdf0e10cSrcweir } 292*cdf0e10cSrcweir 293*cdf0e10cSrcweir /** 294*cdf0e10cSrcweir * This method populates the pdb arrays with the names of the pdbs to 295*cdf0e10cSrcweir * compare. 296*cdf0e10cSrcweir * 297*cdf0e10cSrcweir * @param pdbname1 Name of 2nd PDB file to be compared 298*cdf0e10cSrcweir * @param pdbname2 Name of 2nd PDB file to be compared 299*cdf0e10cSrcweir * @return 300*cdf0e10cSrcweir * 301*cdf0e10cSrcweir */ 302*cdf0e10cSrcweir private void populatePDBArray(String pdbname1, String pdbname2) 303*cdf0e10cSrcweir { 304*cdf0e10cSrcweir if (pdbname1 == null) return; 305*cdf0e10cSrcweir if (pdbname2 == null) return; 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir if ((pdbname1 != null) && (pdbname2 != null)) 308*cdf0e10cSrcweir { 309*cdf0e10cSrcweir pdbarr1 = new String[1]; 310*cdf0e10cSrcweir pdbarr2 = new String[1]; 311*cdf0e10cSrcweir 312*cdf0e10cSrcweir pdbarr1[0] = pdbname1; 313*cdf0e10cSrcweir pdbarr2[0] = pdbname2; 314*cdf0e10cSrcweir } 315*cdf0e10cSrcweir } 316*cdf0e10cSrcweir 317*cdf0e10cSrcweir /** 318*cdf0e10cSrcweir * This method populates the pdb arrays with the names of the pdbs to 319*cdf0e10cSrcweir * compare. 320*cdf0e10cSrcweir * 321*cdf0e10cSrcweir * @param arrayno Array number which corresponds to the pdb array 322*cdf0e10cSrcweir * containing list of pdbs 323*cdf0e10cSrcweir * If 1 then send pdbarr1, if 2 send pdbarr2 else null 324*cdf0e10cSrcweir * 325*cdf0e10cSrcweir * @return PDB string array containing list of PDB's 326*cdf0e10cSrcweir * 327*cdf0e10cSrcweir */ 328*cdf0e10cSrcweir private String[] getPDBArray(int arrayno) 329*cdf0e10cSrcweir { 330*cdf0e10cSrcweir if (arrayno == 1) return pdbarr1; 331*cdf0e10cSrcweir if (arrayno == 2) return pdbarr2; 332*cdf0e10cSrcweir 333*cdf0e10cSrcweir return null; 334*cdf0e10cSrcweir } 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir /** 337*cdf0e10cSrcweir * This method comares 2 PDB's and returns true if comparison is equal. 338*cdf0e10cSrcweir * It uses the PDB Decoder class to decode to a PDB structure and then 339*cdf0e10cSrcweir * does record comparison 340*cdf0e10cSrcweir * 341*cdf0e10cSrcweir * @param pdbname1 Name of one PDB file to be compared 342*cdf0e10cSrcweir * @param pdbname2 Name of other PDB file to be compared 343*cdf0e10cSrcweir * 344*cdf0e10cSrcweir * @return returns true if both PDB's are equal else returns false 345*cdf0e10cSrcweir * 346*cdf0e10cSrcweir */ 347*cdf0e10cSrcweir private boolean comparePDB(String pdbname1, String pdbname2) 348*cdf0e10cSrcweir { 349*cdf0e10cSrcweir PalmDB pdb1=null, pdb2=null; 350*cdf0e10cSrcweir PDBDecoder decoder = new PDBDecoder(); 351*cdf0e10cSrcweir try { 352*cdf0e10cSrcweir pdb1 = decoder.parse(pdbname1); 353*cdf0e10cSrcweir } catch (Exception e) { 354*cdf0e10cSrcweir System.out.println("Could not parse PDB " + pdbname1); 355*cdf0e10cSrcweir return false; 356*cdf0e10cSrcweir } 357*cdf0e10cSrcweir 358*cdf0e10cSrcweir try { 359*cdf0e10cSrcweir pdb2 = decoder.parse(pdbname2); 360*cdf0e10cSrcweir } catch (Exception e) { 361*cdf0e10cSrcweir System.out.println("Could not parse PDB " + pdbname2); 362*cdf0e10cSrcweir return false; 363*cdf0e10cSrcweir } 364*cdf0e10cSrcweir 365*cdf0e10cSrcweir if (pdb1.equals(pdb2)) { 366*cdf0e10cSrcweir writeToLog("PDB " + pdbname1 + " and PDB " + pdbname2 + " are equal"); 367*cdf0e10cSrcweir 368*cdf0e10cSrcweir return true; 369*cdf0e10cSrcweir } else { 370*cdf0e10cSrcweir writeToLog("PDB " + pdbname1 + " and PDB " + pdbname2 + " are not equal"); 371*cdf0e10cSrcweir return false; 372*cdf0e10cSrcweir } 373*cdf0e10cSrcweir } 374*cdf0e10cSrcweir 375*cdf0e10cSrcweir 376*cdf0e10cSrcweir 377*cdf0e10cSrcweir /** 378*cdf0e10cSrcweir * Write message to LOGFILE 379*cdf0e10cSrcweir * 380*cdf0e10cSrcweir * @param msg Message to be written to log file 381*cdf0e10cSrcweir * @return 382*cdf0e10cSrcweir * 383*cdf0e10cSrcweir */ 384*cdf0e10cSrcweir private void writeToLog(String msg) 385*cdf0e10cSrcweir { 386*cdf0e10cSrcweir if (msg == null) return; 387*cdf0e10cSrcweir 388*cdf0e10cSrcweir // Get Output Stream from Log file 389*cdf0e10cSrcweir RandomAccessFile raf=null; 390*cdf0e10cSrcweir try { 391*cdf0e10cSrcweir raf = new RandomAccessFile(LOGFILE, "rw"); 392*cdf0e10cSrcweir } catch (Exception e) { 393*cdf0e10cSrcweir System.out.println ("Could not open file " + LOGFILE); 394*cdf0e10cSrcweir return; 395*cdf0e10cSrcweir } 396*cdf0e10cSrcweir 397*cdf0e10cSrcweir try { 398*cdf0e10cSrcweir long len = raf.length(); 399*cdf0e10cSrcweir raf.seek(len); 400*cdf0e10cSrcweir raf.write(msg.getBytes()); 401*cdf0e10cSrcweir raf.write("\n".getBytes()); 402*cdf0e10cSrcweir } catch (IOException e) { 403*cdf0e10cSrcweir System.out.println("ERROR: Could not write to File " + LOGFILE); 404*cdf0e10cSrcweir return; 405*cdf0e10cSrcweir } 406*cdf0e10cSrcweir } 407*cdf0e10cSrcweir 408*cdf0e10cSrcweir /** 409*cdf0e10cSrcweir * Write status of comparison to OUTFILE 410*cdf0e10cSrcweir * 411*cdf0e10cSrcweir * @param status Indicates whether comparsion of PDB's PASSED or FAILED 412*cdf0e10cSrcweir * @param pdbname1 file name of pdb which was compared. 413*cdf0e10cSrcweir * @param pdbname2 file name of pdb which was compared. 414*cdf0e10cSrcweir * 415*cdf0e10cSrcweir * @return 416*cdf0e10cSrcweir * 417*cdf0e10cSrcweir */ 418*cdf0e10cSrcweir private void writeToOutputFile(String status, String pdbname1, String pdbname2) 419*cdf0e10cSrcweir { 420*cdf0e10cSrcweir if (status == null) return; 421*cdf0e10cSrcweir if (pdbname1 == null) return; 422*cdf0e10cSrcweir if (pdbname2 == null) return; 423*cdf0e10cSrcweir 424*cdf0e10cSrcweir String msg = pdbname1 + "=" + pdbname2 + ":" + status; 425*cdf0e10cSrcweir 426*cdf0e10cSrcweir // Get Output Stream from Log file 427*cdf0e10cSrcweir RandomAccessFile raf=null; 428*cdf0e10cSrcweir try { 429*cdf0e10cSrcweir raf = new RandomAccessFile(OUTFILE, "rw"); 430*cdf0e10cSrcweir } catch (Exception e) { 431*cdf0e10cSrcweir System.out.println ("Could not open file " + OUTFILE); 432*cdf0e10cSrcweir return; 433*cdf0e10cSrcweir } 434*cdf0e10cSrcweir 435*cdf0e10cSrcweir try { 436*cdf0e10cSrcweir long len = raf.length(); 437*cdf0e10cSrcweir raf.seek(len); 438*cdf0e10cSrcweir 439*cdf0e10cSrcweir raf.write(msg.getBytes()); 440*cdf0e10cSrcweir raf.write("\n".getBytes()); 441*cdf0e10cSrcweir } catch (IOException e) { 442*cdf0e10cSrcweir System.out.println("ERROR: Could not write to File " + OUTFILE); 443*cdf0e10cSrcweir return; 444*cdf0e10cSrcweir } 445*cdf0e10cSrcweir 446*cdf0e10cSrcweir try { 447*cdf0e10cSrcweir raf.close(); 448*cdf0e10cSrcweir } catch (Exception e) { 449*cdf0e10cSrcweir System.out.println("ERROR: Could not close File " + OUTFILE); 450*cdf0e10cSrcweir return; 451*cdf0e10cSrcweir } 452*cdf0e10cSrcweir 453*cdf0e10cSrcweir } 454*cdf0e10cSrcweir 455*cdf0e10cSrcweir 456*cdf0e10cSrcweir 457*cdf0e10cSrcweir /** 458*cdf0e10cSrcweir * Main starting block of execution 459*cdf0e10cSrcweir * 460*cdf0e10cSrcweir * @param command line args captured in an array of Strings 461*cdf0e10cSrcweir * @return 462*cdf0e10cSrcweir * 463*cdf0e10cSrcweir */ 464*cdf0e10cSrcweir public static void main(String args[]) 465*cdf0e10cSrcweir { 466*cdf0e10cSrcweir 467*cdf0e10cSrcweir Date startTime = new Date(); 468*cdf0e10cSrcweir pdbcomparison pdbcmp = new pdbcomparison(); 469*cdf0e10cSrcweir int nargs = args.length; 470*cdf0e10cSrcweir int status=0; 471*cdf0e10cSrcweir 472*cdf0e10cSrcweir if (nargs != 1) 473*cdf0e10cSrcweir { 474*cdf0e10cSrcweir System.out.println("Incorrect no. of arguments passed..."); 475*cdf0e10cSrcweir pdbcmp.usage(); 476*cdf0e10cSrcweir System.exit(-1); 477*cdf0e10cSrcweir 478*cdf0e10cSrcweir } 479*cdf0e10cSrcweir 480*cdf0e10cSrcweir String propFile = args[0]; 481*cdf0e10cSrcweir 482*cdf0e10cSrcweir File f=null; 483*cdf0e10cSrcweir try { 484*cdf0e10cSrcweir f = new File(propFile); 485*cdf0e10cSrcweir } catch (Exception e) { 486*cdf0e10cSrcweir System.out.println("Exception: Could not open file " + propFile); 487*cdf0e10cSrcweir System.exit(-1); 488*cdf0e10cSrcweir } 489*cdf0e10cSrcweir 490*cdf0e10cSrcweir if (! f.canRead()) { 491*cdf0e10cSrcweir System.out.println("Exception: " + propFile + " is not a file "); 492*cdf0e10cSrcweir System.exit(-1); 493*cdf0e10cSrcweir } 494*cdf0e10cSrcweir 495*cdf0e10cSrcweir if (! f.canRead()) { 496*cdf0e10cSrcweir System.out.println("Exception: Cannot open file for reading. Please check permissions "); 497*cdf0e10cSrcweir System.exit(-1); 498*cdf0e10cSrcweir } 499*cdf0e10cSrcweir 500*cdf0e10cSrcweir // parse Property file 501*cdf0e10cSrcweir pdbcmp.parsePropertyFile(propFile); 502*cdf0e10cSrcweir 503*cdf0e10cSrcweir String pdbarr1[] = pdbcmp.getPDBArray(1); 504*cdf0e10cSrcweir String pdbarr2[] = pdbcmp.getPDBArray(2); 505*cdf0e10cSrcweir if ( (pdbarr1 == null) || 506*cdf0e10cSrcweir (pdbarr2 == null) || 507*cdf0e10cSrcweir (pdbarr1.length == 0) || 508*cdf0e10cSrcweir (pdbarr1.length == 0)) 509*cdf0e10cSrcweir { 510*cdf0e10cSrcweir System.out.println("pdbArray is empty. No PDBS to compare... \n"); 511*cdf0e10cSrcweir System.exit(-1); 512*cdf0e10cSrcweir } 513*cdf0e10cSrcweir 514*cdf0e10cSrcweir 515*cdf0e10cSrcweir pdbcmp.writeToLog("************** Start *****************"); 516*cdf0e10cSrcweir pdbcmp.writeToLog("PDB Comparison: start time " + startTime); 517*cdf0e10cSrcweir for (int i=0; i<pdbarr1.length; i++) 518*cdf0e10cSrcweir { 519*cdf0e10cSrcweir Date pdb_startTime = new Date(); 520*cdf0e10cSrcweir pdbcmp.writeToLog("\n"); 521*cdf0e10cSrcweir pdbcmp.writeToLog("start time " + pdb_startTime); 522*cdf0e10cSrcweir boolean val = pdbcmp.comparePDB(pdbarr1[i], pdbarr2[i]); 523*cdf0e10cSrcweir Date pdb_endTime = new Date(); 524*cdf0e10cSrcweir pdbcmp.writeToLog("end time " + pdb_endTime); 525*cdf0e10cSrcweir 526*cdf0e10cSrcweir if (val) { 527*cdf0e10cSrcweir pdbcmp.writeToOutputFile("PASSED", pdbarr1[i], pdbarr2[i]); 528*cdf0e10cSrcweir status=0; 529*cdf0e10cSrcweir } else { 530*cdf0e10cSrcweir pdbcmp.writeToOutputFile("FAILED", pdbarr1[i], pdbarr2[i]); 531*cdf0e10cSrcweir status=-1; 532*cdf0e10cSrcweir } 533*cdf0e10cSrcweir } 534*cdf0e10cSrcweir 535*cdf0e10cSrcweir Date endTime = new Date(); 536*cdf0e10cSrcweir pdbcmp.writeToLog("PDB Comparison: end time " + endTime); 537*cdf0e10cSrcweir pdbcmp.writeToLog("************** End *****************n"); 538*cdf0e10cSrcweir pdbcmp.writeToLog("\n"); 539*cdf0e10cSrcweir 540*cdf0e10cSrcweir System.exit(status); 541*cdf0e10cSrcweir } 542*cdf0e10cSrcweir } 543