List of usage examples for java.io FileNotFoundException printStackTrace
public void printStackTrace()
From source file:ai.susi.mind.SusiMind.java
public static void main(String[] args) { try {/*from ww w . j a v a2 s . c o m*/ File init = new File(new File("conf"), "susi"); File watch = new File(new File("data"), "susi"); SusiMind mem = new SusiMind(init, watch, watch); JSONObject lesson = mem.readJsonLesson(new File("conf/susi/susi_cognition_000.json")); mem.learn(lesson); System.out.println(mem.react("I feel funny", "localhost", new SusiThought())); System.out.println(mem.react("Help me!", "localhost", new SusiThought())); } catch (FileNotFoundException e) { e.printStackTrace(); } }
From source file:com.minoritycode.Application.java
public static void main(String[] args) { System.out.println("Trello Backup Application"); File configFile = new File(workingDir + "\\config.properties"); InputStream input = null;//from w w w .java 2 s .co m try { input = new FileInputStream(configFile); config.load(input); input.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } // String workingDir = System.getProperty("user.dir"); manualOperation = Boolean.parseBoolean(config.getProperty("manualOperation")); logger.startErrorLogger(); setBackupDir(); try { report.put("backupDate", backupDate); } catch (JSONException e) { e.printStackTrace(); logger.logLine(e.getMessage()); } lock = new ReentrantLock(); lockErrorRep = new ReentrantLock(); lockErrorLog = new ReentrantLock(); Application.key = config.getProperty("trellokey"); Application.token = config.getProperty("trellotoken"); boolean useProxy = Boolean.parseBoolean(config.getProperty("useProxy")); boolean proxySet = true; if (useProxy) { proxySet = setProxy(); } // GUI swingContainerDemo = new GUI(); // swingContainerDemo.showJPanelDemo(); if (proxySet) { Credentials credentials = new Credentials(); if (Application.key.isEmpty()) { Application.key = credentials.getKey(); } else { Application.key = config.getProperty("trellokey"); } if (token.isEmpty()) { Application.token = credentials.getToken(); } else { Application.token = config.getProperty("trellotoken"); } BoardDownloader downloader = new BoardDownloader(); downloader.downloadMyBoard(url); boards = downloader.downloadOrgBoard(url); if (boards != null) { try { report.put("boardNum", boards.size()); } catch (JSONException e) { e.printStackTrace(); logger.logLine(e.getMessage()); } Integer numberOfThreads = Integer.parseInt(config.getProperty("numberOfThreads")); if (numberOfThreads == null) { logger.logLine("error number of threads not set in config file"); if (manualOperation) { String message = "How many threads do you want to use (10) is average"; numberOfThreads = Integer.parseInt(Credentials.getInput(message)); Credentials.saveProperty("numberOfThreads", numberOfThreads.toString()); } else { if (Boolean.parseBoolean(config.getProperty("useMailer"))) { Mailer mailer = new Mailer(); mailer.SendMail(); } System.exit(-1); } } ArrayList<Thread> threadList = new ArrayList<Thread>(); for (int i = 0; i < numberOfThreads; i++) { Thread thread = new Thread(new Application(), "BoardDownloadThread"); threadList.add(thread); thread.start(); } } else { //create empty report try { report.put("boardsNotDownloaded", "99999"); report.put("boardNum", 0); report.put("boardNumSuccessful", 0); } catch (JSONException e) { e.printStackTrace(); logger.logLine(e.getMessage()); } if (Boolean.parseBoolean(config.getProperty("useMailer"))) { Mailer mailer = new Mailer(); mailer.SendMail(); } logger.logger(report); } } else { //create empty report try { report.put("boardsNotDownloaded", "99999"); report.put("boardNum", 0); report.put("boardNumSuccessful", 0); } catch (JSONException e) { e.printStackTrace(); logger.logLine(e.getMessage()); } if (Boolean.parseBoolean(config.getProperty("useMailer"))) { Mailer mailer = new Mailer(); mailer.SendMail(); } } }
From source file:edu.ku.brc.specify.conversion.MSULichensFixer.java
public static void main(String[] args) { String path = "msulichens.html"; TableWriter writer;// ww w . j a v a 2s . com try { writer = new TableWriter(path, "MSU Lichens"); MSULichensFixer msuf = new MSULichensFixer("msu_lichens", "msu_lichens_6", writer); msuf.doConnect(); msuf.convertTaxonRecords(); msuf.shutdown(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } }
From source file:edu.upenn.cis.FastAlign.java
/** * Prints alignments for options specified by command line arguments. * @param argv parameters to be used by FastAlign. *///w w w. j av a 2 s.c o m public static void main(String[] argv) { FastAlign align = FastAlign.initCommandLine(argv); if (align == null) { System.err.println("Usage: java " + FastAlign.class.getCanonicalName() + " -i file.fr-en\n" + " Standard options ([USE] = strongly recommended):\n" + " -i: [REQ] Input parallel corpus\n" + " -v: [USE] Use Dirichlet prior on lexical translation distributions\n" + " -d: [USE] Favor alignment points close to the monotonic diagonoal\n" + " -o: [USE] Optimize how close to the diagonal alignment points should be\n" + " -r: Run alignment in reverse (condition on target and predict source)\n" + " -c: Output conditional probability table\n" + " -e: Start with existing conditional probability table\n" + " Advanced options:\n" + " -I: number of iterations in EM training (default = 5)\n" + " -p: p_null parameter (default = 0.08)\n" + " -N: No null word\n" + " -a: alpha parameter for optional Dirichlet prior (default = 0.01)\n" + " -T: starting lambda for diagonal distance parameter (default = 4)\n"); System.exit(1); } boolean use_null = !align.no_null_word; if (align.variational_bayes && align.alpha <= 0.0) { System.err.println("--alpha must be > 0\n"); System.exit(1); } double prob_align_not_null = 1.0 - align.prob_align_null; final int kNULL = align.d.Convert("<eps>"); TTable s2t = new TTable(); if (!align.existing_probability_filename.isEmpty()) { boolean success = s2t.ImportFromFile(align.existing_probability_filename, '\t', align.d); if (!success) { System.err.println("Can't read table " + align.existing_probability_filename); System.exit(1); } } Map<Pair, Integer> size_counts = new HashMap<Pair, Integer>(); double tot_len_ratio = 0; double mean_srclen_multiplier = 0; List<Double> probs = new ArrayList<Double>(); ; // E-M Iterations Loop TODO move this into a method? for (int iter = 0; iter < align.iterations || (iter == 0 && align.iterations == 0); ++iter) { final boolean final_iteration = (iter >= (align.iterations - 1)); System.err.println("ITERATION " + (iter + 1) + (final_iteration ? " (FINAL)" : "")); Scanner in = null; try { in = new Scanner(new File(align.input)); if (!in.hasNextLine()) { System.err.println("Can't read " + align.input); System.exit(1); } } catch (FileNotFoundException e) { e.printStackTrace(); System.err.println("Can't read " + align.input); System.exit(1); } double likelihood = 0; double denom = 0.0; int lc = 0; boolean flag = false; String line; // String ssrc, strg; ArrayList<Integer> src = new ArrayList<Integer>(); ArrayList<Integer> trg = new ArrayList<Integer>(); double c0 = 0; double emp_feat = 0; double toks = 0; // Iterate over each line of the input file while (in.hasNextLine()) { line = in.nextLine(); ++lc; if (lc % 1000 == 0) { System.err.print('.'); flag = true; } if (lc % 50000 == 0) { System.err.println(" [" + lc + "]\n"); System.err.flush(); flag = false; } src.clear(); trg.clear(); // TODO this is redundant; src and tgt cleared in ParseLine // Integerize and split source and target lines. align.ParseLine(line, src, trg); if (align.is_reverse) { ArrayList<Integer> tmp = src; src = trg; trg = tmp; } // TODO Empty lines break the parser. Should this be true? if (src.size() == 0 || trg.size() == 0) { System.err.println("Error in line " + lc + "\n" + line); System.exit(1); } if (iter == 0) { tot_len_ratio += ((double) trg.size()) / ((double) src.size()); } denom += trg.size(); probs.clear(); // Add to pair length counts only if first iteration. if (iter == 0) { Pair pair = new Pair(trg.size(), src.size()); Integer value = size_counts.get(pair); if (value == null) value = 0; size_counts.put(pair, value + 1); } boolean first_al = true; // used when printing alignments toks += trg.size(); // Iterate through the English tokens for (int j = 0; j < trg.size(); ++j) { final int f_j = trg.get(j); double sum = 0; double prob_a_i = 1.0 / (src.size() + (use_null ? 1 : 0)); // uniform (model 1) if (use_null) { if (align.favor_diagonal) { prob_a_i = align.prob_align_null; } probs.add(0, s2t.prob(kNULL, f_j) * prob_a_i); sum += probs.get(0); } double az = 0; if (align.favor_diagonal) az = DiagonalAlignment.computeZ(j + 1, trg.size(), src.size(), align.diagonal_tension) / prob_align_not_null; for (int i = 1; i <= src.size(); ++i) { if (align.favor_diagonal) prob_a_i = DiagonalAlignment.unnormalizedProb(j + 1, i, trg.size(), src.size(), align.diagonal_tension) / az; probs.add(i, s2t.prob(src.get(i - 1), f_j) * prob_a_i); sum += probs.get(i); } if (final_iteration) { double max_p = -1; int max_index = -1; if (use_null) { max_index = 0; max_p = probs.get(0); } for (int i = 1; i <= src.size(); ++i) { if (probs.get(i) > max_p) { max_index = i; max_p = probs.get(i); } } if (max_index > 0) { if (first_al) first_al = false; else System.out.print(' '); if (align.is_reverse) System.out.print("" + j + '-' + (max_index - 1)); else System.out.print("" + (max_index - 1) + '-' + j); } } else { if (use_null) { double count = probs.get(0) / sum; c0 += count; s2t.Increment(kNULL, f_j, count); } for (int i = 1; i <= src.size(); ++i) { final double p = probs.get(i) / sum; s2t.Increment(src.get(i - 1), f_j, p); emp_feat += DiagonalAlignment.feature(j, i, trg.size(), src.size()) * p; } } likelihood += Math.log(sum); } if (final_iteration) System.out.println(); } // log(e) = 1.0 double base2_likelihood = likelihood / Math.log(2); if (flag) { System.err.println(); } if (iter == 0) { mean_srclen_multiplier = tot_len_ratio / lc; System.err.println("expected target length = source length * " + mean_srclen_multiplier); } emp_feat /= toks; System.err.println(" log_e likelihood: " + likelihood); System.err.println(" log_2 likelihood: " + base2_likelihood); System.err.println(" cross entropy: " + (-base2_likelihood / denom)); System.err.println(" perplexity: " + Math.pow(2.0, -base2_likelihood / denom)); System.err.println(" posterior p0: " + c0 / toks); System.err.println(" posterior al-feat: " + emp_feat); //System.err.println(" model tension: " + mod_feat / toks ); System.err.println(" size counts: " + size_counts.size()); if (!final_iteration) { if (align.favor_diagonal && align.optimize_tension && iter > 0) { for (int ii = 0; ii < 8; ++ii) { double mod_feat = 0; Iterator<Map.Entry<Pair, Integer>> it = size_counts.entrySet().iterator(); for (; it.hasNext();) { Map.Entry<Pair, Integer> entry = it.next(); final Pair p = entry.getKey(); for (int j = 1; j <= p.first; ++j) mod_feat += entry.getValue() * DiagonalAlignment.computeDLogZ(j, p.first, p.second, align.diagonal_tension); } mod_feat /= toks; System.err.println(" " + ii + 1 + " model al-feat: " + mod_feat + " (tension=" + align.diagonal_tension + ")"); align.diagonal_tension += (emp_feat - mod_feat) * 20.0; if (align.diagonal_tension <= 0.1) align.diagonal_tension = 0.1; if (align.diagonal_tension > 14) align.diagonal_tension = 14; } System.err.println(" final tension: " + align.diagonal_tension); } if (align.variational_bayes) s2t.NormalizeVB(align.alpha); else s2t.Normalize(); //prob_align_null *= 0.8; // XXX //prob_align_null += (c0 / toks) * 0.2; prob_align_not_null = 1.0 - align.prob_align_null; } } if (!align.conditional_probability_filename.isEmpty()) { System.err.println("conditional probabilities: " + align.conditional_probability_filename); s2t.ExportToFile(align.conditional_probability_filename, align.d); } System.exit(0); }
From source file:displayStructureAsPDFTable.java
public static void main(String args[]) { draw2d mk = new draw2d(); String[] filesToDraw = mk.parseCommandLineOptions(args); displayStructure ds = null;//from w ww .j a v a2s.c o m IteratingMDLReader imdlr; if (tabular) oformat = "PDF"; if (verbose) System.out.println("Output format is " + oformat); if (tabular) { if (verbose) System.out.println("Making a tabular PDF with " + ncol + " columns"); ds = new displayStructureAsPDFTable(withH, width, height, scale, ncol, props, doColor, outputDirectory); } try { imdlr = new IteratingMDLReader(new BufferedReader(new FileReader(filesToDraw[0])), DefaultChemObjectBuilder.getInstance()); int cnt = 1; while (imdlr.hasNext()) { if (verbose) { System.out.println("Processing molecule " + cnt); } IMolecule m = (IMolecule) imdlr.next(); // do atom typing AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(m); if (!tabular) { ds = new displayStructure(withH, width, height, scale, doColor, oformat, outputDirectory); } assert ds != null; ds.drawStructure(m, cnt); cnt = cnt + 1; } if (ds != null) ds.close(); System.exit(0); } catch (FileNotFoundException fnf) { System.out.println(fnf.toString()); } catch (Exception fnf) { System.out.println(fnf.toString()); fnf.printStackTrace(); } }
From source file:com.diversityarrays.kdxplore.trials.TrialSelectionDialog.java
static public void main(String[] args) { Transformer<BackgroundRunner, TrialSearchOptionsPanel> factory = new Transformer<BackgroundRunner, TrialSearchOptionsPanel>() { @Override// ww w.j a v a 2 s . co m public TrialSearchOptionsPanel transform(BackgroundRunner backgroundRunner) { return TrialSelectionSearchOptionsPanel.create(backgroundRunner); } }; boolean test = false; if (test) { @SuppressWarnings("unchecked") TrialSelectionDialog tsd = new TrialSelectionDialog(null, "Test Tree", null, Collections.EMPTY_LIST, //$NON-NLS-1$ factory); // tsd.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); tsd.setVisible(true); } else { File propertiesFile = new File(System.getProperty("user.home"), //$NON-NLS-1$ "LoginDialog.properties"); //$NON-NLS-1$ //.getBundle("LoginDialog"); //, Locale.getDefault()); ResourceBundle bundle = null; if (propertiesFile.exists()) { try { bundle = new PropertyResourceBundle(new FileReader(propertiesFile)); } catch (FileNotFoundException e) { e.printStackTrace(); System.exit(1); } catch (IOException e) { e.printStackTrace(); System.exit(1); } } Preferences loginPreferences = KdxplorePreferences.getInstance().getPreferences(); // Preferences loginPreferences = Preferences.userNodeForPackage(KdxConstants.class); LoginDialog ld = new LoginDialog(null, "Login Please", loginPreferences, bundle); //$NON-NLS-1$ ld.setVisible(true); DALClient client = ld.getDALClient(); if (client != null) { @SuppressWarnings("unchecked") TrialSelectionDialog tsd = new TrialSelectionDialog(null, "Test Tree", client, //$NON-NLS-1$ Collections.EMPTY_LIST, factory); // tsd.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); tsd.setVisible(true); if (tsd.trialRecords == null) { System.out.println("Cancelled !"); //$NON-NLS-1$ } else { System.out.println(tsd.trialRecords.length + " chosen: "); //$NON-NLS-1$ for (TrialPlus tr : tsd.trialRecords) { System.out.println("\t" + tr.getTrialId() + ": " + tr.getTrialName()); //$NON-NLS-1$ //$NON-NLS-2$ } System.out.println("- - -"); //$NON-NLS-1$ } } } System.exit(0); }
From source file:com.cloud.utils.crypt.EncryptionSecretKeyChanger.java
public static void main(String[] args) { List<String> argsList = Arrays.asList(args); Iterator<String> iter = argsList.iterator(); String oldMSKey = null;//from w w w. j a va 2s. c om String oldDBKey = null; String newMSKey = null; String newDBKey = null; //Parse command-line args while (iter.hasNext()) { String arg = iter.next(); // Old MS Key if (arg.equals("-m")) { oldMSKey = iter.next(); } // Old DB Key if (arg.equals("-d")) { oldDBKey = iter.next(); } // New MS Key if (arg.equals("-n")) { newMSKey = iter.next(); } // New DB Key if (arg.equals("-e")) { newDBKey = iter.next(); } } if (oldMSKey == null || oldDBKey == null) { System.out.println("Existing MS secret key or DB secret key is not provided"); usage(); return; } if (newMSKey == null && newDBKey == null) { System.out.println("New MS secret key and DB secret are both not provided"); usage(); return; } final File dbPropsFile = PropertiesUtil.findConfigFile("db.properties"); final Properties dbProps; EncryptionSecretKeyChanger keyChanger = new EncryptionSecretKeyChanger(); StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor(); keyChanger.initEncryptor(encryptor, oldMSKey); dbProps = new EncryptableProperties(encryptor); PropertiesConfiguration backupDBProps = null; System.out.println("Parsing db.properties file"); try { dbProps.load(new FileInputStream(dbPropsFile)); backupDBProps = new PropertiesConfiguration(dbPropsFile); } catch (FileNotFoundException e) { System.out.println("db.properties file not found while reading DB secret key" + e.getMessage()); } catch (IOException e) { System.out.println("Error while reading DB secret key from db.properties" + e.getMessage()); } catch (ConfigurationException e) { e.printStackTrace(); } String dbSecretKey = null; try { dbSecretKey = dbProps.getProperty("db.cloud.encrypt.secret"); } catch (EncryptionOperationNotPossibleException e) { System.out.println("Failed to decrypt existing DB secret key from db.properties. " + e.getMessage()); return; } if (!oldDBKey.equals(dbSecretKey)) { System.out.println("Incorrect MS Secret Key or DB Secret Key"); return; } System.out.println("Secret key provided matched the key in db.properties"); final String encryptionType = dbProps.getProperty("db.cloud.encryption.type"); if (newMSKey == null) { System.out.println("No change in MS Key. Skipping migrating db.properties"); } else { if (!keyChanger.migrateProperties(dbPropsFile, dbProps, newMSKey, newDBKey)) { System.out.println("Failed to update db.properties"); return; } else { //db.properties updated successfully if (encryptionType.equals("file")) { //update key file with new MS key try { FileWriter fwriter = new FileWriter(keyFile); BufferedWriter bwriter = new BufferedWriter(fwriter); bwriter.write(newMSKey); bwriter.close(); } catch (IOException e) { System.out.println("Failed to write new secret to file. Please update the file manually"); } } } } boolean success = false; if (newDBKey == null || newDBKey.equals(oldDBKey)) { System.out.println("No change in DB Secret Key. Skipping Data Migration"); } else { EncryptionSecretKeyChecker.initEncryptorForMigration(oldMSKey); try { success = keyChanger.migrateData(oldDBKey, newDBKey); } catch (Exception e) { System.out.println("Error during data migration"); e.printStackTrace(); success = false; } } if (success) { System.out.println("Successfully updated secret key(s)"); } else { System.out.println("Data Migration failed. Reverting db.properties"); //revert db.properties try { backupDBProps.save(); } catch (ConfigurationException e) { e.printStackTrace(); } if (encryptionType.equals("file")) { //revert secret key in file try { FileWriter fwriter = new FileWriter(keyFile); BufferedWriter bwriter = new BufferedWriter(fwriter); bwriter.write(oldMSKey); bwriter.close(); } catch (IOException e) { System.out.println("Failed to revert to old secret to file. Please update the file manually"); } } } }
From source file:ca.uqac.info.trace.execution.BabelTrace.java
/** * Main program loop//w w w . jav a 2 s.c o m * @param args */ public static void main(String[] args) { String trace_type = "", tool_name = ""; String trace_in_filename = "", formula_in_filename = ""; String out_formula = "", out_trace = "", out_signature = "", output_dir = ""; File formula_in, trace_in; trace_in = null; Operator op = null; EventTrace trace = null; boolean run_tool = false, show_command = false; // Parse command line arguments Options options = setupOptions(); CommandLine c_line = setupCommandLine(args, options); assert c_line != null; if (c_line.hasOption("version")) { System.out.println("\nBabelTrace build " + BUILD_STRING); System.out.println("(C) 2012-2013 Sylvain Hall et al., Universit du Qubec Chicoutimi"); System.out.println("This program comes with ABSOLUTELY NO WARRANTY."); System.out.println("This is a free software, and you are welcome to redistribute it"); System.out.println("under certain conditions. See the file COPYING for details.\n"); System.exit(ERR_OK); } if (c_line.hasOption("h")) { showUsage(options); System.exit(ERR_OK); } if (c_line.hasOption("t")) trace_in_filename = c_line.getOptionValue("t"); else { showUsage(options); System.exit(ERR_ARGUMENTS); } if (c_line.hasOption("f")) formula_in_filename = c_line.getOptionValue("f"); else { showUsage(options); System.exit(ERR_ARGUMENTS); } if (c_line.hasOption("i")) trace_type = c_line.getOptionValue("i"); else { showUsage(options); System.exit(ERR_ARGUMENTS); } if (c_line.hasOption("c")) tool_name = c_line.getOptionValue("c"); else { showUsage(options); System.exit(ERR_ARGUMENTS); } if (c_line.hasOption("o")) output_dir = c_line.getOptionValue("o"); else { showUsage(options); System.exit(ERR_ARGUMENTS); } if (c_line.hasOption("b")) { run_tool = false; show_command = true; } if (c_line.hasOption("r")) { run_tool = true; show_command = false; } // Read input formula formula_in = new File(formula_in_filename); if (!formula_in.exists()) { System.err.println("Error reading " + formula_in_filename); System.exit(ERR_IO); } try { out_formula = ca.uqac.info.util.FileReadWrite.readFile(formula_in_filename); } catch (java.io.FileNotFoundException e) { System.err.println("File not found: " + formula_in_filename); System.exit(ERR_IO); } catch (java.io.IOException e) { System.err.println("IO Exception: " + formula_in_filename); e.printStackTrace(); System.exit(ERR_IO); } // Get trace file trace_in = new File(trace_in_filename); // Get execution Execution ex = getExecution(tool_name); // Get filenames for each part String base_filename = FileReadWrite.baseName(trace_in) + "." + FileReadWrite.baseName(formula_in); String trace_filename = output_dir + "/" + base_filename + "." + ex.getTraceExtension(); String formula_filename = output_dir + "/" + base_filename + "." + ex.getFormulaExtension(); String signature_filename = output_dir + "/" + base_filename + "." + ex.getSignatureExtension(); // Setup execution environment ex.setProperty(formula_filename); ex.setSignature(signature_filename); ex.setTrace(trace_filename); // Show command lines and leave if (show_command) { String[] cl = ex.getCommandLines(); for (String c : cl) { System.out.println(c); } System.exit(ERR_OK); } // Initialize the translator Translator tt = getTraceTranslator(tool_name); if (tt == null) { System.err.println("Error: unrecognized conversion format \"" + tool_name + "\""); System.exit(ERR_NO_SUCH_TOOL); } tt.setTrace(trace); // Parse the trace TraceReader t_read = getTraceReader(trace_type); try { trace = t_read.parseEventTrace(new FileInputStream(trace_in)); } catch (FileNotFoundException e) { e.printStackTrace(); System.exit(ERR_IO); } // Get the formula as an operator try { op = Operator.parseFromString(out_formula); } catch (ParseException e) { System.err.println("Error parsing the input formula"); System.exit(ERR_PARSE); } assert op != null; // Does the formula require flat messages and formulas? if (tt.requiresFlat()) { // Convert the first-order formula to a propositional one FlatTranslator pt = new FlatTranslator(); pt.setFormula(op); pt.setTrace(trace); // Flatten the trace String tr_trans = pt.translateTrace(); TraceReader xtr = new XmlTraceReader(); trace = xtr.parseEventTrace(new ByteArrayInputStream(tr_trans.getBytes())); // Flatten the formula String op_trans = pt.translateFormula(); try { op = Operator.parseFromString(op_trans); } catch (ParseException e) { System.err.println("Error parsing the formula once translated to propositional"); System.exit(ERR_PARSE); } } // Is the formula first-order while the tool requires propositional? if (tt.requiresPropositional() && FirstOrderDetector.isFirstOrder(op)) { // Convert the first-order formula to a propositional one PropositionalTranslator pt = new PropositionalTranslator(); pt.setFormula(op); pt.setTrace(trace); String op_trans = pt.translateFormula(); try { op = Operator.parseFromString(op_trans); } catch (ParseException e) { System.err.println("Error parsing the formula once translated to propositional"); System.exit(ERR_PARSE); } // We also convert equalities between constants produced by the translator // into Booleans ConstantConverter cc = new ConstantConverter(); op.accept(cc); op = cc.getFormula(); // And then propagate those constants UnitPropagator up = new UnitPropagator(); op.accept(up); op = up.getFormula(); } // Convert tt.setTrace(trace); tt.setFormula(op); tt.translateAll(); out_trace = tt.getTraceFile(); out_formula = tt.getFormulaFile(); out_signature = tt.getSignatureFile(); // Save conversions to files try { if (!out_trace.isEmpty()) { ca.uqac.info.util.FileReadWrite.writeToFile(trace_filename, out_trace); } if (!out_formula.isEmpty()) { ca.uqac.info.util.FileReadWrite.writeToFile(formula_filename, out_formula); } if (!out_signature.isEmpty()) { ca.uqac.info.util.FileReadWrite.writeToFile(signature_filename, out_signature); } } catch (java.io.IOException e) { System.err.println("Error writing to file"); System.err.println(e.getMessage()); System.exit(ERR_IO); } // Now that all conversions have been made, run the tool if (run_tool) { try { ex.run(); } catch (Execution.CommandLineException e) { System.err.println("Error running command"); System.exit(ERR_TOOL_EXECUTION); } // Print results ReturnVerdict ex_retval = ex.getReturnVerdict(); float ex_time = (float) ex.getTime() / (float) 1000000000; // We show seconds, not s float ex_memory = (float) ex.getMemory() / (float) 1024; // We show megabytes, not bytes System.out.printf("%s,%.2f,%.2f\n", ex_retval, ex_time, ex_memory); // If an error occurred, dump it if (ex_retval == ReturnVerdict.ERROR) { System.err.println("Error while executing " + tool_name); System.err.println("Command line(s):"); for (String cl : ex.getCommandLines()) { System.err.println(cl); } System.err.println("Below is the string returned by the tool\n"); System.err.println(ex.getErrorString()); System.exit(ERR_TOOL_EXECUTION); } } // Quit System.exit(ERR_OK); }
From source file:eu.planets_project.pp.plato.xml.ProjectImporter.java
/** * /*from w w w. j a va 2s . co m*/ * @param args * first entry is the filename of the xml-file to be imported * second entry is the name of the output-file */ public static void main(String[] args) { ProjectImporter projectImp = new ProjectImporter(); ProjectExporter exporter = new ProjectExporter(); try { for (Plan plan : projectImp.importProjects(args[0])) { System.out.println("Imported : " + plan.getPlanProperties().getName()); // export the imported project FileOutputStream out = new FileOutputStream(args[1]); XMLWriter writer = new XMLWriter(out, ProjectExporter.prettyFormat); writer.write(exporter.exportToXml(plan)); writer.close(); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } }
From source file:examples.nntp.post.java
public final static void main(String[] args) { String from, subject, newsgroup, filename, server, organization; String references;//from w ww . java2 s.c o m BufferedReader stdin; FileReader fileReader = null; SimpleNNTPHeader header; NNTPClient client; if (args.length < 1) { System.err.println("Usage: post newsserver"); System.exit(1); } server = args[0]; stdin = new BufferedReader(new InputStreamReader(System.in)); try { System.out.print("From: "); System.out.flush(); from = stdin.readLine(); System.out.print("Subject: "); System.out.flush(); subject = stdin.readLine(); header = new SimpleNNTPHeader(from, subject); System.out.print("Newsgroup: "); System.out.flush(); newsgroup = stdin.readLine(); header.addNewsgroup(newsgroup); while (true) { System.out.print("Additional Newsgroup <Hit enter to end>: "); System.out.flush(); // Of course you don't want to do this because readLine() may be null newsgroup = stdin.readLine().trim(); if (newsgroup.length() == 0) break; header.addNewsgroup(newsgroup); } System.out.print("Organization: "); System.out.flush(); organization = stdin.readLine(); System.out.print("References: "); System.out.flush(); references = stdin.readLine(); if (organization != null && organization.length() > 0) header.addHeaderField("Organization", organization); if (references != null && organization.length() > 0) header.addHeaderField("References", references); header.addHeaderField("X-Newsreader", "NetComponents"); System.out.print("Filename: "); System.out.flush(); filename = stdin.readLine(); try { fileReader = new FileReader(filename); } catch (FileNotFoundException e) { System.err.println("File not found. " + e.getMessage()); System.exit(1); } client = new NNTPClient(); client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out))); client.connect(server); if (!NNTPReply.isPositiveCompletion(client.getReplyCode())) { client.disconnect(); System.err.println("NNTP server refused connection."); System.exit(1); } if (client.isAllowedToPost()) { Writer writer = client.postArticle(); if (writer != null) { writer.write(header.toString()); Util.copyReader(fileReader, writer); writer.close(); client.completePendingCommand(); } } fileReader.close(); client.logout(); client.disconnect(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } }