List of usage examples for java.io PrintStream PrintStream
public PrintStream(OutputStream out, boolean autoFlush, Charset charset)
From source file:ca.nines.ise.cmd.Annotations.java
/** * {@inheritDoc}/*from w ww . j a v a 2 s. c om*/ */ @ErrorCode(code = { "dom.errors" }) @Override public void execute(CommandLine cmd) throws Exception { Log log = Log.getInstance(); Locale.setDefault(Locale.ENGLISH); PrintStream logOut = new PrintStream(System.out, true, "UTF-8"); if (cmd.hasOption("l")) { logOut = new PrintStream(new FileOutputStream(cmd.getOptionValue("l")), true, "UTF-8"); } String args[] = getArgList(cmd); File docFile = new File(args[0]); if (!docFile.exists()) { System.err.println("Cannot read document " + docFile.getCanonicalPath()); System.exit(1); } File annFile = new File(args[1]); if (!annFile.exists()) { System.err.println("Cannot read annotations " + annFile.getCanonicalPath()); System.exit(1); } DOM dom = new DOMBuilder(docFile).build(); if (dom.getStatus() != DOM.DOMStatus.ERROR) { Annotation annotation = Annotation.builder().from(annFile).build(); AnnotationValidator av = new AnnotationValidator(); av.validate(dom, annotation); } else { Message m = Message.builder("dom.errors").setSource(dom.getSource()).build(); log.add(m); } if (log.count() > 0) { logOut.print(log); } }
From source file:ca.nines.ise.cmd.Validate.java
/** * {@inheritDoc}// w ww. j a v a 2 s . c om */ @ErrorCode(code = { "dom.errors" }) @Override public void execute(CommandLine cmd) throws Exception { File[] files; Log log = Log.getInstance(); Locale.setDefault(Locale.ENGLISH); Schema schema = Schema.defaultSchema(); DOMValidator dv = new DOMValidator(); NestingValidator nv = new NestingValidator(schema); PrintStream out = new PrintStream(System.out, true, "UTF-8"); if (cmd.hasOption("l")) { out = new PrintStream(new FileOutputStream(cmd.getOptionValue("l")), true, "UTF-8"); } files = getFilePaths(cmd); if (files != null) { out.println("Found " + files.length + " files to check."); for (File in : files) { DOM dom = new DOMBuilder(in).build(); if (dom.getStatus() != DOM.DOMStatus.ERROR) { dv.validate(dom, schema); nv.validate(dom); } else { Message m = Message.builder("dom.errors").setSource(dom.getSource()).build(); log.add(m); } if (log.count() > 0) { out.println(log); } log.clear(); } } }
From source file:com.sap.prd.mobile.ios.mios.CodeSignManager.java
private static ExecResult exec(String[] cmd) throws IOException { String cmdStr = StringUtils.join(cmd, " "); System.out.println("Invoking " + cmdStr); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos, true, "UTF-8"); try {/* w w w . j ava 2s .co m*/ int exitValue = Forker.forkProcess(ps, null, "bash", "-c", cmdStr); return new ExecResult(cmdStr, baos.toString("UTF-8"), exitValue); } finally { ps.close(); } }
From source file:ca.nines.ise.cmd.Modernize.java
/** * {@inheritDoc}/* w w w . ja va2 s .com*/ */ @Override public void execute(CommandLine cmd) throws Exception { PrintStream out; Writer renderer; Log log = Log.getInstance(); Locale.setDefault(Locale.ENGLISH); out = new PrintStream(System.out, true, "UTF-8"); if (cmd.hasOption("o")) { out = new PrintStream(new FileOutputStream(cmd.getOptionValue("o")), true, "UTF-8"); } renderer = new SGMLWriter(out); String[] files = getArgList(cmd); DOM dom = new DOMBuilder(new File(files[0])).build(); if (dom.getStatus() == DOMStatus.ERROR) { System.err.println("Document contains errors. Cannot continue."); if (log.count() > 0) { out.println(log); log.clear(); } System.exit(-1); } Schema schema = Schema.defaultSchema(); DOMValidator dv = new DOMValidator(); NestingValidator nv = new NestingValidator(schema); Modernizer m = new Modernizer(); Normalizer n = new Normalizer(); Formatter f = new Formatter(); dv.validate(dom, schema); nv.validate(dom); dom = m.transform(dom); dom = n.transform(dom); dom = f.transform(dom); renderer.render(dom); }
From source file:ca.nines.ise.cmd.Transform.java
/** * {@inheritDoc}// w ww .j a va 2 s .c o m */ @Override public void execute(CommandLine cmd) throws Exception { PrintStream out; Locale.setDefault(Locale.ENGLISH); out = new PrintStream(System.out, true, "UTF-8"); if (cmd.hasOption("o")) { out = new PrintStream(new FileOutputStream(cmd.getOptionValue("o")), true, "UTF-8"); } Log log = Log.getInstance(); Writer renderer = null; if (cmd.hasOption("text")) { renderer = new TextWriter(out); } if (cmd.hasOption("xml")) { renderer = new XMLWriter(out); } if (cmd.hasOption("rtf")) { renderer = new RTFWriter(out); } if (cmd.hasOption("sgml")) { renderer = new SGMLWriter(out); } if (cmd.hasOption("ximl")) { renderer = new ExpandedSGMLWriter(out); } if (renderer == null) { System.err.println("You must specify a transformation"); System.exit(1); return; } String[] files = getArgList(cmd); DOM dom = new DOMBuilder(new File(files[0])).build(); Schema schema = Schema.defaultSchema(); DOMValidator dv = new DOMValidator(); NestingValidator nv = new NestingValidator(schema); dv.validate(dom, schema); nv.validate(dom); if (dom.getStatus() != DOMStatus.ERROR) { if (files.length == 2) { Annotation ann = Annotation.builder().from(new File(files[1])).build(); renderer.render(dom, ann); } else { renderer.render(dom); } } else { Message m = Message.builder("dom.errors").setSource(dom.getSource()).build(); log.add(m); } if (log.count() > 0) { System.err.println(log.count() + " errors or warnings."); System.err.println(log); } log.clear(); }
From source file:com.leavesfly.lia.advsearching.SortingExample.java
public void displayResults(Query query, Sort sort) // #1 throws IOException { IndexSearcher searcher = new IndexSearcher(directory); searcher.setDefaultFieldSortScoring(true, false); // #2 TopDocs results = searcher.search(query, null, // #3 20, sort); // #3 System.out.println("\nResults for: " + // #4 query.toString() + " sorted by " + sort); System.out.println(StringUtils.rightPad("Title", 30) + StringUtils.rightPad("pubmonth", 10) + StringUtils.center("id", 4) + StringUtils.center("score", 15)); PrintStream out = new PrintStream(System.out, true, "UTF-8"); // #5 DecimalFormat scoreFormatter = new DecimalFormat("0.######"); for (ScoreDoc sd : results.scoreDocs) { int docID = sd.doc; float score = sd.score; Document doc = searcher.doc(docID); out.println(StringUtils.rightPad( // #6 StringUtils.abbreviate(doc.get("title"), 29), 30) + // #6 StringUtils.rightPad(doc.get("pubmonth"), 10) + // #6 StringUtils.center("" + docID, 4) + // #6 StringUtils.leftPad( // #6 scoreFormatter.format(score), 12)); // #6 out.println(" " + doc.get("category")); // out.println(searcher.explain(query, docID)); // #7 }/*from w w w . j a v a 2 s . c o m*/ searcher.close(); }
From source file:de.fau.cs.osr.hddiff.utils.Report.java
public void writeCsv(File outFile, Locale locale, String encoding) throws IOException { try (OutputStream os = new FileOutputStream(outFile)) { try (PrintStream ps = new PrintStream(os, true, encoding)) { ArrayList<String> headers = new ArrayList<String>(this.headers); Collections.sort(headers); int cols = headers.size(); int i = 0; for (String header : headers) { ps.print(StringEscapeUtils.escapeCsv(header)); if (++i < cols) ps.print(','); }/*w w w . j a v a2 s . c o m*/ ps.println(); i = 0; for (String header : headers) { String unit = units.get(header); if (unit != null) ps.print(StringEscapeUtils.escapeCsv(unit)); if (++i < cols) ps.print(','); } ps.println(); for (ReportItem item : items) { Map<String, Indicator> values = item.getIndicators(); i = 0; for (String header : headers) { Indicator ind = values.get(header); if (ind != null) ps.print(StringEscapeUtils.escapeCsv(ind.formatValue(locale))); if (++i < cols) ps.print(','); } ps.println(); } } } }
From source file:com.zimbra.cs.mailbox.util.MetadataDump.java
public static void main(String[] args) { try {/*from w w w.j av a 2s . c o m*/ CliUtil.toolSetup("WARN"); int mboxId = 0; int itemId = 0; PrintStream out = new PrintStream(System.out, true, "utf-8"); CommandLine cl = parseArgs(args); if (cl.hasOption(OPT_HELP)) { usage(null); System.exit(0); } // Get data from file. String infileName = cl.getOptionValue(OPT_FILE); if (infileName != null) { File file = new File(infileName); if (file.exists()) { String encoded = loadFromFile(file); Metadata md = new Metadata(encoded); String pretty = md.prettyPrint(); out.println(pretty); return; } else { System.err.println("File " + infileName + " does not exist"); System.exit(1); } } // Get data from input String. String encoded = cl.getOptionValue(OPT_STR); if (!StringUtil.isNullOrEmpty(encoded)) { Metadata md = new Metadata(encoded); String pretty = md.prettyPrint(); out.println(pretty); return; } // Get data from db. DbPool.startup(); DbConnection conn = null; try { boolean fromDumpster = cl.hasOption(OPT_DUMPSTER); String mboxIdStr = cl.getOptionValue(OPT_MAILBOX_ID); String itemIdStr = cl.getOptionValue(OPT_ITEM_ID); if (mboxIdStr == null || itemIdStr == null) { usage(null); System.exit(1); return; } if (mboxIdStr.matches("\\d+")) { try { mboxId = Integer.parseInt(mboxIdStr); } catch (NumberFormatException e) { System.err.println("Invalid mailbox id " + mboxIdStr); System.exit(1); } } else { conn = DbPool.getConnection(); mboxId = lookupMailboxIdFromEmail(conn, mboxIdStr); } try { itemId = Integer.parseInt(itemIdStr); } catch (NumberFormatException e) { usage(null); System.exit(1); } if (conn == null) conn = DbPool.getConnection(); doDump(conn, mboxId, itemId, fromDumpster, out); } finally { DbPool.quietClose(conn); } } catch (Exception e) { System.err.println(e.getMessage()); System.err.println(); System.err.println(); e.printStackTrace(); System.exit(1); } }
From source file:ca.nines.ise.cmd.Wikify.java
/** * {@inheritDoc}/*w w w . ja v a2 s. co m*/ */ @Override public void execute(CommandLine cmd) throws Exception { Locale.setDefault(Locale.ENGLISH); PrintStream out = new PrintStream(System.out, true, "UTF-8"); if (cmd.hasOption("o")) { out = new PrintStream(new FileOutputStream(cmd.getOptionValue("l")), true, "UTF-8"); } if (cmd.hasOption("chars")) { wikifyCharacters(out); } if (cmd.hasOption("schema")) { wikifySchema(out); } if (cmd.hasOption("codepoints")) { wikifyCodepoints(out); } }
From source file:cc.wikitools.lucene.hadoop.FindWikipediaArticleIdHdfs.java
@SuppressWarnings("static-access") @Override//from w w w.j a v a 2 s.c o m public int run(String[] args) throws Exception { Options options = new Options(); options.addOption( OptionBuilder.withArgName("path").hasArg().withDescription("index location").create(INDEX_OPTION)); options.addOption( OptionBuilder.withArgName("string").hasArg().withDescription("article title").create(TITLE_OPTION)); CommandLine cmdline = null; CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (!cmdline.hasOption(TITLE_OPTION) || !cmdline.hasOption(INDEX_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(FindWikipediaArticleIdHdfs.class.getName(), options); System.exit(-1); } String indexLocation = cmdline.getOptionValue(INDEX_OPTION); String title = cmdline.getOptionValue(TITLE_OPTION); PrintStream out = new PrintStream(System.out, true, "UTF-8"); HdfsWikipediaSearcher searcher = new HdfsWikipediaSearcher(new Path(indexLocation), getConf()); int id = searcher.getArticleId(title); out.println(title + ": id = " + id); searcher.close(); out.close(); return 0; }