List of usage examples for java.io PrintStream print
public void print(Object obj)
From source file:org.cruxframework.crux.tools.schema.DefaultSchemaGenerator.java
/** * //ww w . jav a 2 s .c o m * @param out * @param attributes * @param children */ private void generateSequenceChild(PrintStream out, TagConstraints attributes, TagChildren children, String library) { try { out.print("<xs:sequence "); if (attributes != null) { out.print("minOccurs=\"" + attributes.minOccurs() + "\" "); out.print("maxOccurs=\"" + attributes.maxOccurs() + "\" "); } out.println(">"); for (TagChild child : children.value()) { generateChild(out, child, true, library); } out.println("</xs:sequence>"); } catch (Exception e) { throw new SchemaGeneratorException(e.getMessage(), e); } }
From source file:org.cruxframework.crux.tools.schema.DefaultSchemaGenerator.java
/** * /*from w w w. j a v a2s. c o m*/ * @param out * @param attributes * @param children * @throws NoSuchMethodException */ private void generateAllChild(PrintStream out, TagConstraints attributes, TagChildren children, String library) throws NoSuchMethodException { out.print("<xs:all "); if (attributes != null) { out.print("minOccurs=\"" + attributes.minOccurs() + "\" "); out.print("maxOccurs=\"" + attributes.maxOccurs() + "\" "); } out.println(">"); for (TagChild child : children.value()) { generateChild(out, child, true, library); } out.println("</xs:all>"); }
From source file:org.cruxframework.crux.tools.schema.DefaultSchemaGenerator.java
/** * //w w w. j a v a 2s .co m * @param out * @param attributes * @param children * @throws NoSuchMethodException */ private void generateChoiceChild(PrintStream out, TagConstraints attributes, TagChildren children, String library) throws NoSuchMethodException { out.print("<xs:choice "); if (attributes != null) { out.print("minOccurs=\"" + attributes.minOccurs() + "\" "); out.print("maxOccurs=\"" + attributes.maxOccurs() + "\" "); } out.println(">"); for (TagChild child : children.value()) { generateChild(out, child, true, library); } out.println("</xs:choice>"); }
From source file:org.apache.hadoop.hive.ql.exec.ExplainTask.java
@VisibleForTesting JSONObject outputMap(Map<?, ?> mp, boolean hasHeader, PrintStream out, boolean extended, boolean jsonOutput, int indent) throws Exception { TreeMap<Object, Object> tree = getBasictypeKeyedMap(mp); JSONObject json = jsonOutput ? new JSONObject(new LinkedHashMap<>()) : null; if (out != null && hasHeader && !mp.isEmpty()) { out.println();/*from ww w.ja v a 2 s . co m*/ } for (Entry<?, ?> ent : tree.entrySet()) { // Print the key if (out != null) { out.print(indentString(indent)); out.print(ent.getKey()); out.print(" "); } // Print the value if (isPrintable(ent.getValue())) { if (out != null) { out.print(ent.getValue()); out.println(); } if (jsonOutput) { json.put(ent.getKey().toString(), ent.getValue().toString()); } } else if (ent.getValue() instanceof List) { if (ent.getValue() != null && !((List<?>) ent.getValue()).isEmpty() && ((List<?>) ent.getValue()).get(0) != null && ((List<?>) ent.getValue()).get(0) instanceof TezWork.Dependency) { if (out != null) { boolean isFirst = true; for (TezWork.Dependency dep : (List<TezWork.Dependency>) ent.getValue()) { if (!isFirst) { out.print(", "); } else { out.print("<- "); isFirst = false; } out.print(dep.getName()); out.print(" ("); out.print(dep.getType()); out.print(")"); } out.println(); } if (jsonOutput) { for (TezWork.Dependency dep : (List<TezWork.Dependency>) ent.getValue()) { JSONObject jsonDep = new JSONObject(new LinkedHashMap<>()); jsonDep.put("parent", dep.getName()); jsonDep.put("type", dep.getType()); json.accumulate(ent.getKey().toString(), jsonDep); } } } else if (ent.getValue() != null && !((List<?>) ent.getValue()).isEmpty() && ((List<?>) ent.getValue()).get(0) != null && ((List<?>) ent.getValue()).get(0) instanceof SparkWork.Dependency) { if (out != null) { boolean isFirst = true; for (SparkWork.Dependency dep : (List<SparkWork.Dependency>) ent.getValue()) { if (!isFirst) { out.print(", "); } else { out.print("<- "); isFirst = false; } out.print(dep.getName()); out.print(" ("); out.print(dep.getShuffleType()); out.print(", "); out.print(dep.getNumPartitions()); out.print(")"); } out.println(); } if (jsonOutput) { for (SparkWork.Dependency dep : (List<SparkWork.Dependency>) ent.getValue()) { JSONObject jsonDep = new JSONObject(new LinkedHashMap<>()); jsonDep.put("parent", dep.getName()); jsonDep.put("type", dep.getShuffleType()); jsonDep.put("partitions", dep.getNumPartitions()); json.accumulate(ent.getKey().toString(), jsonDep); } } } else { if (out != null) { out.print(ent.getValue().toString()); out.println(); } if (jsonOutput) { json.put(ent.getKey().toString(), ent.getValue().toString()); } } } else if (ent.getValue() instanceof Map) { String stringValue = getBasictypeKeyedMap((Map) ent.getValue()).toString(); if (out != null) { out.print(stringValue); out.println(); } if (jsonOutput) { json.put(ent.getKey().toString(), stringValue); } } else if (ent.getValue() != null) { if (out != null) { out.println(); } JSONObject jsonOut = outputPlan(ent.getValue(), out, extended, jsonOutput, jsonOutput ? 0 : indent + 2); if (jsonOutput) { json.put(ent.getKey().toString(), jsonOut); } } else { if (out != null) { out.println(); } } } return jsonOutput ? json : null; }
From source file:examples.ClassPropertyUsageAnalyzer.java
/** * Prints the URL of a thumbnail for the given item document to the output, * or a default image if no image is given for the item. * * @param out/*from w ww . ja v a2 s. com*/ * the output to write to * @param itemDocument * the document that may provide the image information */ private void printImage(PrintStream out, ItemDocument itemDocument) { String imageFile = null; if (itemDocument != null) { for (StatementGroup sg : itemDocument.getStatementGroups()) { boolean isImage = "P18".equals(sg.getProperty().getId()); if (!isImage) { continue; } for (Statement s : sg.getStatements()) { if (s.getClaim().getMainSnak() instanceof ValueSnak) { Value value = ((ValueSnak) s.getClaim().getMainSnak()).getValue(); if (value instanceof StringValue) { imageFile = ((StringValue) value).getString(); break; } } } if (imageFile != null) { break; } } } if (imageFile == null) { out.print(",\"http://commons.wikimedia.org/w/thumb.php?f=MA_Route_blank.svg&w=50\""); } else { try { String imageFileEncoded; imageFileEncoded = URLEncoder.encode(imageFile.replace(" ", "_"), "utf-8"); // Keep special title symbols unescaped: imageFileEncoded = imageFileEncoded.replace("%3A", ":").replace("%2F", "/"); out.print("," + csvStringEscape("http://commons.wikimedia.org/w/thumb.php?f=" + imageFileEncoded) + "&w=50"); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Your JRE does not support UTF-8 encoding. Srsly?!", e); } } }
From source file:com.github.lindenb.jvarkit.tools.misc.AlleleFrequencyCalculator.java
@Override protected Collection<Throwable> call(String inputName) throws Exception { PrintStream out = null; VcfIterator in = null;/* w w w. j a v a2s . c o m*/ try { final List<String> args = this.getInputFiles(); if (inputName == null) { LOG.info("reading stdin"); in = new VcfIteratorImpl(stdin()); } else { LOG.info("reading " + args.get(0)); in = VCFUtils.createVcfIterator(inputName); } out = openFileOrStdoutAsPrintStream(); out.println("CHR\tPOS\tID\tREF\tALT\tTOTAL_CNT\tALT_CNT\tFRQ"); while (in.hasNext() && !out.checkError()) { VariantContext ctx = in.next(); Allele ref = ctx.getReference(); if (ref == null) continue; if (ctx.getNSamples() == 0 || ctx.getAlternateAlleles().isEmpty()) continue; Allele alt = ctx.getAltAlleleWithHighestAlleleCount(); if (alt == null) continue; GenotypesContext genotypes = ctx.getGenotypes(); if (genotypes == null) continue; int total_ctn = 0; int alt_ctn = 0; for (int i = 0; i < genotypes.size(); ++i) { Genotype g = genotypes.get(i); for (Allele allele : g.getAlleles()) { if (allele.equals(ref)) { total_ctn++; } else if (allele.equals(alt)) { total_ctn++; alt_ctn++; } } } out.print(ctx.getContig()); out.print("\t"); out.print(ctx.getStart()); out.print("\t"); out.print(ctx.hasID() ? ctx.getID() : "."); out.print("\t"); out.print(ref.getBaseString()); out.print("\t"); out.print(alt.getBaseString()); out.print("\t"); out.print(total_ctn); out.print("\t"); out.print(alt_ctn); out.print("\t"); out.print(alt_ctn / (float) total_ctn); out.println(); } out.flush(); return RETURN_OK; } catch (Exception err) { return wrapException(err); } finally { CloserUtil.close(out); CloserUtil.close(in); } }
From source file:org.apache.bookkeeper.common.conf.ConfigDef.java
private void writeConfigKey(PrintStream stream, ConfigKey key) { // "# <description>" // "#"/*from ww w . j a va 2 s.c o m*/ if (StringUtils.isNotBlank(key.description())) { writeSentence(stream, COMMENT_PREFIX, key.description()); stream.println("#"); } // "# <documentation>" // "#" if (StringUtils.isNotBlank(key.documentation())) { writeSentence(stream, COMMENT_PREFIX, key.documentation()); stream.println("#"); } // "# type: <type>, required" writeSentence(stream, COMMENT_PREFIX, "TYPE: " + key.type() + ", " + (key.required() ? "required" : "optional")); if (null != key.validator() && StringUtils.isNotBlank(key.validator().documentation())) { writeSentence(stream, COMMENT_PREFIX, "@constraints : " + key.validator().documentation()); } if (!key.optionValues().isEmpty()) { writeSentence(stream, COMMENT_PREFIX, "@options :"); key.optionValues().forEach(value -> { writeSentence(stream, COMMENT_PREFIX, " " + value); }); } // "#" // "# @Since" if (StringUtils.isNotBlank(key.since())) { stream.println("#"); writeSentence(stream, COMMENT_PREFIX, "@since " + key.since() + ""); } // "#" // "# @Deprecated" if (key.deprecated()) { stream.println("#"); writeSentence(stream, COMMENT_PREFIX, getDeprecationDescription(key)); } // <key>=<defaultValue> stream.print(key.name()); stream.print("="); if (null != key.defaultValue()) { stream.print(key.defaultValue()); } stream.println(); }
From source file:com.act.lcms.MS2Simple.java
private void plot(List<Pair<MS2Collected, Integer>> ms2Spectra, Double mz, List<Double> ms2SearchMZs, String outPrefix, String fmt) throws IOException { String outPDF = outPrefix + "." + fmt; String outDATA = outPrefix + ".data"; // Write data output to outfile PrintStream out = new PrintStream(new FileOutputStream(outDATA)); List<String> plotID = new ArrayList<>(ms2Spectra.size()); for (Pair<MS2Collected, Integer> pair : ms2Spectra) { MS2Collected yzSlice = pair.getLeft(); String caption;/*from www. j a v a 2s. co m*/ if (ms2SearchMZs != null && ms2SearchMZs.size() > 0) { caption = String.format("target: %.4f, time: %.4f, volts: %.4f, %d / %d matches", yzSlice.triggerMass, yzSlice.triggerTime, yzSlice.voltage, pair.getRight() == null ? 0 : pair.getRight(), ms2SearchMZs.size()); } else { caption = String.format("target: %.4f, time: %.4f, volts: %.4f", yzSlice.triggerMass, yzSlice.triggerTime, yzSlice.voltage); } plotID.add(caption); // Compute the total intensity on the fly so we can plot on a percentage scale. double maxIntensity = 0.0; for (YZ yz : yzSlice.ms2) { if (yz.intensity > maxIntensity) { maxIntensity = yz.intensity; } } // print out the spectra to outDATA for (YZ yz : yzSlice.ms2) { out.format("%.4f\t%.4f\n", yz.mz, 100.0 * yz.intensity / maxIntensity); out.flush(); } // delimit this dataset from the rest out.print("\n\n"); } // close the .data out.close(); // render outDATA to outPDF using gnuplot // 105.0 here means 105% for the y-range of a [0%:100%] plot. We want to leave some buffer space at // at the top, and hence we go a little outside of the 100% max range. /* We intend to plot the fragmentation pattern, and so do not expect to see fragments that are bigger than the * original selected molecule. We truncate the x-range to the specified m/z but since that will make values close * to the max hard to see we add a buffer and truncate the plot in the x-range to m/z + 50.0. */ new Gnuplotter().plot2DImpulsesWithLabels(outDATA, outPDF, plotID.toArray(new String[plotID.size()]), mz + 50.0, "mz", 105.0, "intensity (%)", fmt); }
From source file:org.apache.hadoop.hive.ql.exec.ExplainTask.java
@VisibleForTesting ImmutablePair<Boolean, JSONObject> outputPlanVectorization(PrintStream out, boolean jsonOutput) throws Exception { if (out != null) { out.println("PLAN VECTORIZATION:"); }/*from w w w . j av a 2s . c o m*/ JSONObject json = jsonOutput ? new JSONObject(new LinkedHashMap<>()) : null; HiveConf hiveConf = queryState.getConf(); boolean isVectorizationEnabled = HiveConf.getBoolVar(hiveConf, HiveConf.ConfVars.HIVE_VECTORIZATION_ENABLED); String isVectorizationEnabledCondName = (isVectorizationEnabled ? trueCondNameVectorizationEnabled : falseCondNameVectorizationEnabled); List<String> isVectorizationEnabledCondList = Arrays.asList(isVectorizationEnabledCondName); if (out != null) { out.print(indentString(2)); out.print("enabled: "); out.println(isVectorizationEnabled); out.print(indentString(2)); if (!isVectorizationEnabled) { out.print("enabledConditionsNotMet: "); } else { out.print("enabledConditionsMet: "); } out.println(isVectorizationEnabledCondList); } if (jsonOutput) { json.put("enabled", isVectorizationEnabled); JSONArray jsonArray = new JSONArray(Arrays.asList(isVectorizationEnabledCondName)); if (!isVectorizationEnabled) { json.put("enabledConditionsNotMet", jsonArray); } else { json.put("enabledConditionsMet", jsonArray); } } return new ImmutablePair<Boolean, JSONObject>(isVectorizationEnabled, jsonOutput ? json : null); }
From source file:com.buildml.main.CliUtils.java
/** * A helper method, called exclusively by printActionSet(). This method calls itself recursively * as it traverses the ActionSet's tree structure. * /*from w ww .ja v a 2s . co m*/ * @param outStream The PrintStream on which to display the output. * @param buildStore The database containing file, action and package information. * @param actionId The ID of the action we're currently displaying (at this level of recursion). * @param resultActionSet The full set of actions to be displayed (the result of some previous query). * @param filterActionSet The set of actions to actually be displayed (for post-filtering the query results). * @param outputFormat The way in which the actions should be formatted. * @param showPkgs Set to true if we should display package names. * @param indentLevel The number of spaces to indent this action by (at this recursion level). */ private static void printActionSetHelper(PrintStream outStream, IBuildStore buildStore, int actionId, ActionSet resultActionSet, ActionSet filterActionSet, DisplayWidth outputFormat, boolean showPkgs, int indentLevel) { IActionMgr actionMgr = buildStore.getActionMgr(); IFileMgr fileMgr = buildStore.getFileMgr(); IPackageMgr pkgMgr = buildStore.getPackageMgr(); IPackageMemberMgr pkgMemberMgr = buildStore.getPackageMemberMgr(); /* * Display the current action, at the appropriate indentation level. The format is: * * - Action 1 (/home/psmith/t/cvs-1.11.23) * if test ! -f config.h; then rm -f stamp-h1; emake stamp-h1; else :; * * -- Action 2 (/home/psmith/t/cvs-1.11.23) * failcom='exit 1'; for f in x $MAKEFLAGS; do case $f in *=* | --[!k]*);; \ * * Where Action 1 is the parent of Action 2. */ /* is this action in the ActionSet to be printed? If not, terminate recursion */ if (!(((resultActionSet == null) || (resultActionSet.isMember(actionId))) && ((filterActionSet == null) || (filterActionSet.isMember(actionId))))) { return; } /* * Fetch the action's command string (if there is one). It can either be * in short format (on a single line), or a full string (possibly multiple lines) */ String command = (String) actionMgr.getSlotValue(actionId, IActionMgr.COMMAND_SLOT_ID); if (command == null) { command = "<unknown command>"; } else if (outputFormat == DisplayWidth.ONE_LINE) { command = ShellCommandUtils.getCommandSummary(command, getColumnWidth() - indentLevel - 3); } /* fetch the name of the directory the action was executed in */ int actionDirId = (Integer) actionMgr.getSlotValue(actionId, IActionMgr.DIRECTORY_SLOT_ID); String actionDirName = fileMgr.getPathName(actionDirId); /* display the correct number of "-" characters */ for (int i = 0; i != indentLevel; i++) { outStream.append('-'); } outStream.print(" Action " + actionId + " (" + actionDirName); /* if requested, display the action's package name */ if (showPkgs) { PackageDesc pkg = pkgMemberMgr.getPackageOfMember(IPackageMemberMgr.TYPE_ACTION, actionId); if (pkg == null) { outStream.print(" - Invalid action"); } else { String pkgName = pkgMgr.getName(pkg.pkgId); if (pkgName == null) { outStream.print(" - Invalid package"); } else { outStream.print(" - " + pkgName); } } } outStream.println(")"); /* display the action's command string. Each line must be indented appropriately */ if (outputFormat != DisplayWidth.NOT_WRAPPED) { PrintUtils.indentAndWrap(outStream, command, indentLevel + 3, getColumnWidth()); outStream.println(); } else { outStream.println(command); } /* recursively call ourselves to display each of our children */ Integer children[] = actionMgr.getChildren(actionId); for (int i = 0; i < children.length; i++) { printActionSetHelper(outStream, buildStore, children[i], resultActionSet, filterActionSet, outputFormat, showPkgs, indentLevel + 1); } }