List of usage examples for java.io PrintStream print
public void print(Object obj)
From source file:org.apache.hadoop.hive.ql.exec.ExplainTask.java
@VisibleForTesting JSONObject outputDependencies(Task<?> task, PrintStream out, JSONObject parentJson, boolean jsonOutput, boolean taskType, int indent) throws Exception { boolean first = true; JSONObject json = jsonOutput ? new JSONObject(new LinkedHashMap<>()) : null; if (out != null) { out.print(indentString(indent)); out.print(task.getId());/*from w ww . j a v a 2 s . com*/ } if ((task.getParentTasks() == null || task.getParentTasks().isEmpty())) { if (task.isRootTask()) { if (out != null) { out.print(" is a root stage"); } if (jsonOutput) { json.put("ROOT STAGE", "TRUE"); } } } else { StringBuilder s = new StringBuilder(); first = true; for (Task<?> parent : task.getParentTasks()) { if (!first) { s.append(", "); } first = false; s.append(parent.getId()); } if (out != null) { out.print(" depends on stages: "); out.print(s.toString()); } if (jsonOutput) { json.put("DEPENDENT STAGES", s.toString()); } } Task<?> currBackupTask = task.getBackupTask(); if (currBackupTask != null) { if (out != null) { out.print(" has a backup stage: "); out.print(currBackupTask.getId()); } if (jsonOutput) { json.put("BACKUP STAGE", currBackupTask.getId()); } } if (task instanceof ConditionalTask && ((ConditionalTask) task).getListTasks() != null) { StringBuilder s = new StringBuilder(); first = true; for (Task<?> con : ((ConditionalTask) task).getListTasks()) { if (!first) { s.append(", "); } first = false; s.append(con.getId()); } if (out != null) { out.print(" , consists of "); out.print(s.toString()); } if (jsonOutput) { json.put("CONDITIONAL CHILD TASKS", s.toString()); } } if (taskType) { if (out != null) { out.print(" ["); out.print(task.getType()); out.print("]"); } if (jsonOutput) { json.put("TASK TYPE", task.getType().name()); } } if (out != null) { out.println(); } return jsonOutput ? json : null; }
From source file:org.broad.igv.tools.IgvTools.java
private void GFFToBed(String ifile, String ofile) throws FileNotFoundException { IGVBEDCodec outCodec = new IGVBEDCodec(); GFFParser parser = new GFFParser(); GFFCodec codec = null;/* w w w . j av a 2s.c o m*/ try { codec = (GFFCodec) CodecFactory.getCodec(ifile, null); } catch (Exception e) { throw new IllegalArgumentException("Input file is not recognized as a GFF"); } BufferedReader reader = null; PrintStream outStream = System.out; if (!ofile.equals(STDOUT_FILE_STR)) { outStream = new PrintStream(new FileOutputStream(ofile)); } try { reader = ParsingUtils.openBufferedReader(ifile); List<Feature> features = parser.loadFeatures(reader, null, codec); for (Feature feat : features) { String encoded = outCodec.encode(feat); outStream.print(encoded); outStream.print('\n'); } } catch (IOException e) { log.error(e.getMessage(), e); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { log.error(e.getMessage(), e); } } if (outStream != null) { outStream.flush(); outStream.close(); } } }
From source file:fr.in2p3.maven.plugin.DependencyXmlMojo.java
private void dump(DependencyNode current, PrintStream out) throws MojoExecutionException, MojoFailureException { String artifactId = current.getArtifact().getArtifactId(); boolean hasClassifier = (current.getArtifact().getClassifier() != null); if ((artifactId.startsWith("jsaga-") || artifactId.startsWith("saga-")) && !hasClassifier) { MavenProject module = this.getMavenProject(current.getArtifact()); if (module != null) { // Filter does NOT work // AndArtifactFilter scopeFilter = new AndArtifactFilter(); // scopeFilter.add(new ScopeArtifactFilter(Artifact.SCOPE_COMPILE)); // scopeFilter.add(new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME)); try { current = dependencyTreeBuilder.buildDependencyTree(module, localRepository, factory, artifactMetadataSource, null, collector); } catch (DependencyTreeBuilderException e) { throw new MojoExecutionException("Unable to build dependency tree", e); }//from w w w . j a va 2 s. c o m } } // dump (part 1) indent(current, out); out.print("<artifact"); Artifact artifact = current.getArtifact(); addAttribute(out, "id", artifact.getArtifactId()); addAttribute(out, "group", artifact.getGroupId()); // Get version from HashMap String v = includedArtifacts.get(artifact.getArtifactId()); if (v != null) { artifact.setVersion(v); } addAttribute(out, "version", artifact.getVersion()); addAttribute(out, "type", artifact.getType()); addAttribute(out, "scope", artifact.getScope()); addAttribute(out, "classifier", artifact.getClassifier()); try { addAttribute(out, "file", this.getJarFile(artifact).toString()); } catch (Exception e) { getLog().debug(artifact.getArtifactId() + "Could not find JAR"); } MavenProject proj = this.getMavenProject(artifact); if (proj != null) { if (!proj.getName().startsWith("Unnamed - ")) { addAttribute(out, "name", proj.getName()); } addAttribute(out, "description", proj.getDescription()); addAttribute(out, "url", proj.getUrl()); if (proj.getOrganization() != null) { addAttribute(out, "organization", proj.getOrganization().getName()); addAttribute(out, "organizationUrl", proj.getOrganization().getUrl()); } if (proj.getLicenses().size() > 0) { License license = (License) proj.getLicenses().get(0); addAttribute(out, "license", license.getName()); addAttribute(out, "licenseUrl", license.getUrl()); } } out.println(">"); // recurse for (Iterator it = current.getChildren().iterator(); it.hasNext();) { DependencyNode child = (DependencyNode) it.next(); // filter dependencies with scope "test", except those with classifier "tests" (i.e. adaptor integration tests) if ("test".equals(child.getArtifact().getScope()) && !"tests".equals(child.getArtifact().getClassifier())) { Artifact c = child.getArtifact(); getLog().debug(artifact.getArtifactId() + ": ignoring dependency " + c.getGroupId() + ":" + c.getArtifactId()); } else { this.dump(child, out); } } // dump (part 2) indent(current, out); out.println("</artifact>"); }
From source file:org.apache.jackrabbit.core.ItemManager.java
/** * {@inheritDoc}//w ww . ja v a 2s . com */ public synchronized void dump(PrintStream ps) { ps.println("ItemManager (" + this + ")"); ps.println(); ps.println("Items in cache:"); ps.println(); synchronized (itemCache) { Iterator iter = itemCache.keySet().iterator(); while (iter.hasNext()) { ItemId id = (ItemId) iter.next(); ItemImpl item = (ItemImpl) itemCache.get(id); if (item.isNode()) { ps.print("Node: "); } else { ps.print("Property: "); } if (item.isTransient()) { ps.print("transient "); } else { ps.print(" "); } ps.println(id + "\t" + item.safeGetJCRPath() + " (" + item + ")"); } } }
From source file:com.zimbra.cs.imap.ImapMessage.java
static void serializeStructure(PrintStream ps, MimeMessage root, boolean extensions) throws IOException, MessagingException { LinkedList<LinkedList<MPartInfo>> queue = new LinkedList<LinkedList<MPartInfo>>(); LinkedList<MPartInfo> level = new LinkedList<MPartInfo>(); level.add(Mime.getParts(root).get(0)); queue.add(level);/*w ww .j a v a 2 s . co m*/ boolean pop = false; while (!queue.isEmpty()) { level = queue.getLast(); if (level.isEmpty()) { queue.removeLast(); pop = true; continue; } MPartInfo mpi = level.getFirst(); MimePart mp = mpi.getMimePart(); boolean hasChildren = mpi.getChildren() != null && !mpi.getChildren().isEmpty(); // we used to force unset charsets on text/plain parts to US-ASCII, but that always seemed unwise... ContentType ctype = new ContentType(mp.getHeader("Content-Type", null)) .setContentType(mpi.getContentType()); String primary = nATOM(ctype.getPrimaryType()), subtype = nATOM(ctype.getSubType()); if (!pop) ps.write('('); if (primary.equals("\"MULTIPART\"")) { if (!pop) { // 7.4.2: "Multiple parts are indicated by parenthesis nesting. Instead of a body type // as the first element of the parenthesized list, there is a sequence of one // or more nested body structures. The second element of the parenthesized // list is the multipart subtype (mixed, digest, parallel, alternative, etc.)." if (!hasChildren) { ps.print("NIL"); } else { queue.addLast(new LinkedList<MPartInfo>(mpi.getChildren())); continue; } } ps.write(' '); ps.print(subtype); if (extensions) { // 7.4.2: "Extension data follows the multipart subtype. Extension data is never // returned with the BODY fetch, but can be returned with a BODYSTRUCTURE // fetch. Extension data, if present, MUST be in the defined order. The // extension data of a multipart body part are in the following order: // body parameter parenthesized list, body disposition, body language, // body location" ps.write(' '); nparams(ps, ctype); ps.write(' '); ndisposition(ps, mp.getHeader("Content-Disposition", null)); ps.write(' '); nlist(ps, mp.getContentLanguage()); ps.write(' '); nstring(ps, mp.getHeader("Content-Location", null)); } } else { if (!pop) { // 7.4.2: "The basic fields of a non-multipart body part are in the following order: // body type, body subtype, body parameter parenthesized list, body id, body // description, body encoding, body size." String cte = mp.getEncoding(); cte = (cte == null || cte.trim().equals("") ? "7bit" : cte); aSTRING(ps, ctype.getPrimaryType()); ps.write(' '); aSTRING(ps, ctype.getSubType()); ps.write(' '); nparams(ps, ctype); ps.write(' '); nstring(ps, mp.getContentID()); ps.write(' '); nstring2047(ps, mp.getDescription()); ps.write(' '); aSTRING(ps, cte); ps.write(' '); ps.print(Math.max(mp.getSize(), 0)); } boolean rfc822 = primary.equals("\"MESSAGE\"") && subtype.equals("\"RFC822\""); if (rfc822) { // 7.4.2: "A body type of type MESSAGE and subtype RFC822 contains, immediately // after the basic fields, the envelope structure, body structure, and // size in text lines of the encapsulated message." if (!pop) { if (!hasChildren) { ps.print(" NIL NIL"); } else { MimeMessage mm = (MimeMessage) mpi.getChildren().get(0).getMimePart(); ps.write(' '); serializeEnvelope(ps, mm); ps.write(' '); queue.addLast(new LinkedList<MPartInfo>(mpi.getChildren())); continue; } } ps.write(' '); ps.print(getLineCount(mp)); } else if (primary.equals("\"TEXT\"")) { // 7.4.2: "A body type of type TEXT contains, immediately after the basic fields, the // size of the body in text lines. Note that this size is the size in its // content transfer encoding and not the resulting size after any decoding." ps.write(' '); ps.print(getLineCount(mp)); } if (extensions) { // 7.4.2: "Extension data follows the basic fields and the type-specific fields // listed above. Extension data is never returned with the BODY fetch, // but can be returned with a BODYSTRUCTURE fetch. Extension data, if // present, MUST be in the defined order. The extension data of a // non-multipart body part are in the following order: body MD5, body // disposition, body language, body location" ps.write(' '); nstring(ps, mp.getContentMD5()); ps.write(' '); ndisposition(ps, mp.getHeader("Content-Disposition", null)); ps.write(' '); nlist(ps, mp.getContentLanguage()); ps.write(' '); nstring(ps, mp.getHeader("Content-Location", null)); } } ps.write(')'); level.removeFirst(); pop = false; } }
From source file:edu.msu.cme.rdp.seqmatch.cli.SeqmatchCheckRevSeq.java
/** * For each query, compares the S_ab scores of the original * sequence and the reversed but not complemented sequence. If the score differs above a threshold, the sequence is then * marked as bad seq. There are three output files: the seqmatch results of the good sequences, the seqmatch results of the bad sequences, * and a fasta file of the corrected sequence strings of the bad sequences. * @param inFileName/*from w w w. java 2 s . c o m*/ * @param traineeFile * @param outFileName * @param revOutFileName * @param correctedQueryOut * @param diffScoreCutoff * @param trainset_no * @throws IOException */ public void checkRevSeq(String inFileName, String traineeFile, String outFileName, PrintWriter revOutputWriter, PrintStream correctedQueryOut, float diffScoreCutoff, String format, String traineeDesc) throws IOException { CheckReverseSeq checker = new CheckReverseSeq(traineeFile, traineeDesc); BufferedWriter writer = new BufferedWriter(new FileWriter(outFileName)); Map<String, SeqMatchResultSet> resultMap = new HashMap(); Sequence seq; SequenceReader reader = new SequenceReader(new File(inFileName)); while ((seq = reader.readNextSequence()) != null) { ArrayList<SeqMatchResultSet> result = checker.check(seq); SeqMatchResultSet resultSet = result.get(0); float origScore = resultSet.iterator().next().getScore(); // check the reverse without complement SeqMatchResultSet revResultSet = result.get(1); float revScore = revResultSet.iterator().next().getScore(); if ((revScore - origScore) < diffScoreCutoff) { resultMap.put(seq.getSeqName(), resultSet); printResult(resultMap, format, writer, traineeDesc); } else { // this sequence is possibly a bad sequence resultMap.put(seq.getSeqName(), revResultSet); printResult(resultMap, format, revOutputWriter, traineeDesc); correctedQueryOut.print(">" + seq.getSeqName() + "\t" + seq.getDesc() + "\t" + revScore + "\t" + origScore + "\n" + IUBUtilities.reverse(seq.getSeqString()) + "\n"); } resultMap.clear(); } reader.close(); writer.close(); revOutputWriter.close(); }
From source file:org.apache.jackrabbit.core.ItemManager.java
/** * {@inheritDoc}/*from w w w.j a v a 2 s . c om*/ */ public synchronized void dump(PrintStream ps) { ps.println("ItemManager (" + this + ")"); ps.println(); ps.println("Items in cache:"); ps.println(); synchronized (itemCache) { Iterator iter = itemCache.keySet().iterator(); while (iter.hasNext()) { ItemId id = (ItemId) iter.next(); ItemData item = (ItemData) itemCache.get(id); if (item.isNode()) { ps.print("Node: "); } else { ps.print("Property: "); } if (item.getState().isTransient()) { ps.print("transient "); } else { ps.print(" "); } ps.println(id + "\t" + safeGetJCRPath(id) + " (" + item + ")"); } } }
From source file:hudson.tools.JDKInstaller.java
@SuppressWarnings("unchecked") // dom4j doesn't do generics, apparently... should probably switch to XOM private HttpURLConnection locateStage1(Platform platform, CPU cpu) throws IOException { URL url = new URL( "https://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/ViewProductDetail-Start?ProductRef=" + id);/*from ww w . jav a2 s .com*/ HttpURLConnection con = (HttpURLConnection) url.openConnection(); String cookie = con.getHeaderField("Set-Cookie"); LOGGER.fine("Cookie=" + cookie); Tidy tidy = new Tidy(); tidy.setErrout(new PrintWriter(new NullWriter())); DOMReader domReader = new DOMReader(); Document dom = domReader.read(tidy.parseDOM(con.getInputStream(), null)); Element form = null; for (Element e : (List<Element>) dom.selectNodes("//form")) { String action = e.attributeValue("action"); LOGGER.fine("Found form:" + action); if (action.contains("ViewFilteredProducts")) { form = e; break; } } con = (HttpURLConnection) new URL(form.attributeValue("action")).openConnection(); con.setRequestMethod("POST"); con.setDoOutput(true); con.setRequestProperty("Cookie", cookie); con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); PrintStream os = new PrintStream(con.getOutputStream()); // select platform String primary = null, secondary = null; Element p = (Element) form.selectSingleNode(".//select[@id='dnld_platform']"); for (Element opt : (List<Element>) p.elements("option")) { String value = opt.attributeValue("value"); String vcap = value.toUpperCase(Locale.ENGLISH); if (!platform.is(vcap)) continue; switch (cpu.accept(vcap)) { case PRIMARY: primary = value; break; case SECONDARY: secondary = value; break; case UNACCEPTABLE: break; } } if (primary == null) primary = secondary; if (primary == null) throw new AbortException( "Couldn't find the right download for " + platform + " and " + cpu + " combination"); os.print(p.attributeValue("name") + '=' + primary); LOGGER.fine("Platform choice:" + primary); // select language Element l = (Element) form.selectSingleNode(".//select[@id='dnld_language']"); if (l != null) { os.print("&" + l.attributeValue("name") + "=" + l.element("option").attributeValue("value")); } // the rest for (Element e : (List<Element>) form.selectNodes(".//input")) { os.print('&'); os.print(e.attributeValue("name")); os.print('='); String value = e.attributeValue("value"); if (value == null) os.print("on"); // assume this is a checkbox else os.print(URLEncoder.encode(value, "UTF-8")); } os.close(); return con; }
From source file:org.apache.hadoop.hive.ql.exec.ExplainTask.java
public JSONObject getJSONLogicalPlan(PrintStream out, ExplainWork work) throws Exception { isLogical = true;//from w w w . jav a 2 s .c o m JSONObject outJSONObject = new JSONObject(new LinkedHashMap<>()); boolean jsonOutput = work.isFormatted(); if (jsonOutput) { out = null; } if (work.getParseContext() != null) { if (out != null) { out.print("LOGICAL PLAN:"); } JSONObject jsonPlan = outputMap(work.getParseContext().getTopOps(), true, out, work.getExtended(), jsonOutput, 0); if (out != null) { out.println(); } if (jsonOutput) { outJSONObject.put("LOGICAL PLAN", jsonPlan); } } else { System.err.println("No parse context!"); } return outJSONObject; }
From source file:edu.cornell.med.icb.goby.modes.AbstractCommandLineMode.java
/** * Print the usage for a mode in the format appropriate for a table in HTML. * * @param jsap The parameters for the mode *///from www. j av a2 s .c om public void printUsageAsHtmlTable(final JSAP jsap) { final PrintStream writer = System.out; // Table definition/header writer.println("<table style=\"background: #efefef;\" border=\"1\" cellpadding=\"5\">"); writer.println("<tbody>"); writer.println("<tr style=\"background: #ffdead;\" align=\"left\" valign=\"bottom\">"); writer.println("<th style=\"width: 15%\">Flag</th>"); writer.println("<th style=\"width: 10%\">Arguments</th>"); writer.println("<th style=\"width: 5%\">Required</th>"); writer.println("<th>Description</th>"); writer.println("</tr>"); // iterate through help entries for the mode final IDMap idMap = jsap.getIDMap(); final Iterator iterator = idMap.idIterator(); while (iterator.hasNext()) { final String id = (String) iterator.next(); if (!"mode".equals(id) && !isJSAPHelpId(id)) { // skip the mode and help ids final Parameter parameter = jsap.getByID(id); writer.println("<tr align=\"left\" valign=\"top\">"); writer.print("<td><code>"); if (parameter instanceof Flagged) { final Flagged flagged = (Flagged) parameter; final Character characterFlag = flagged.getShortFlagCharacter(); final String longFlag = flagged.getLongFlag(); if (characterFlag != null && StringUtils.isNotBlank(longFlag)) { writer.print("(-" + characterFlag + "|--" + longFlag + ")"); } else if (characterFlag != null) { writer.print("-" + characterFlag); } else if (StringUtils.isNotBlank(longFlag)) { writer.print("--" + longFlag); } } else { writer.print("n/a"); } writer.println("</code></td>"); writer.print("<td>"); if (parameter instanceof Switch) { writer.print("n/a"); } else { writer.print(id); } writer.println("</td>"); final boolean required; if (parameter instanceof Option) { final Option option = (Option) parameter; required = option.required(); } else { required = !(parameter instanceof Switch); } writer.println("<td>" + BooleanUtils.toStringYesNo(required) + "</td>"); writer.print("<td>"); // convert any strange characters to html codes final String htmlHelpString = StringEscapeUtils.escapeHtml(parameter.getHelp()); // and also convert "-" to the hyphen character code writer.print(StringUtils.replace(htmlHelpString, "-", "-")); if (parameter.getDefault() != null) { writer.print(" Default value: "); for (final String defaultValue : parameter.getDefault()) { writer.print(" "); writer.print(StringUtils.replace(defaultValue, "-", "-")); } } writer.println("</td>"); writer.println("</tr>"); } } // table close writer.println("</tbody>"); writer.println("</table>"); }