Example usage for java.io PrintWriter print

List of usage examples for java.io PrintWriter print

Introduction

In this page you can find the example usage for java.io PrintWriter print.

Prototype

public void print(Object obj) 

Source Link

Document

Prints an object.

Usage

From source file:gov.nih.nci.caarray.application.translation.geosoft.GeoSoftFileWriterUtil.java

@SuppressWarnings("PMD.ExcessiveMethodLength")
private static void writeSampleSection(Hybridization h, PrintWriter out) {
    final Set<Source> sources = new TreeSet<Source>(ENTITY_COMPARATOR);
    final Set<Sample> samples = new TreeSet<Sample>(ENTITY_COMPARATOR);
    final Set<Extract> extracts = new TreeSet<Extract>(ENTITY_COMPARATOR);
    final Set<LabeledExtract> labeledExtracts = new TreeSet<LabeledExtract>(ENTITY_COMPARATOR);
    GeoSoftFileWriterUtil.collectBioMaterials(h, sources, samples, extracts, labeledExtracts);

    out.print("^SAMPLE=");
    out.println(h.getName());/* w  ww  . j a va 2s . com*/
    out.print("!Sample_title=");
    out.println(h.getName());
    writeDescription(out, h, samples);
    writeData(h, out);
    writeSources(out, sources);
    writeOrganism(sources, samples, h.getExperiment(), out);
    final Set<ProtocolApplication> pas = new TreeSet<ProtocolApplication>(ENTITY_COMPARATOR);
    pas.addAll(h.getProtocolApplications());
    collectAllProtocols(labeledExtracts, pas);
    collectAllProtocols(extracts, pas);
    collectAllProtocols(samples, pas);
    collectAllProtocols(sources, pas);

    writeProtocol(pas, "Sample_treatment_protocol", PREDICATE_TREATMENT, out);
    writeProtocol(pas, "Sample_growth_protocol", PREDICATE_GROWTH, out);
    writeProtocol(pas, "Sample_extract_protocol", PREDICATE_EXTRACT, out);
    writeProtocol(getAllProtocols(extracts), "Sample_label_protocol", PREDICATE_LABELING, out);
    writeProtocol(getAllProtocols(labeledExtracts), "Sample_hyb_protocol", PREDICATE_HYB, out);
    writeProtocol(h.getProtocolApplications(), "Sample_scan_protocol", PREDICATE_SCAN, out);
    writeProtocolsForData(h.getRawDataCollection(), "Sample_data_processing", out);

    for (final LabeledExtract labeledExtract : labeledExtracts) {
        out.print("!Sample_label=");
        out.println(labeledExtract.getLabel().getValue());
    }
    writeProviders(sources, out);

    out.print("!Sample_platform_id=");
    out.println(h.getArray().getDesign().getGeoAccession());

    final Set<String> uniqueEntries = new HashSet<String>();
    for (final AbstractFactorValue fv : h.getFactorValues()) {
        writeCharacteristics(fv.getFactor().getName(), fv.getDisplayValue(), out, uniqueEntries);
    }
    writeCharacteristics(labeledExtracts, out, uniqueEntries);
    writeCharacteristics(extracts, out, uniqueEntries);
    writeCharacteristics(samples, out, uniqueEntries);
    writeCharacteristics(sources, out, uniqueEntries);

    writeMaterialTypes(extracts, labeledExtracts, out);
}

From source file:it.greenvulcano.util.txt.TextUtils.java

/**
 * Writes a text String into a file/*w w  w. ja  v  a  2  s .c  o m*/
 * 
 * @param contentString
 *        The String to be written into the file
 * @param file
 *        The destination file
 * @param append
 *        If true the data are appended to existent file
 * @throws IOException
 */
public static void writeFile(String contentString, File file, boolean append) throws IOException {
    PrintWriter out = null;
    try {
        out = new PrintWriter(new FileWriter(file, append));
        out.print(contentString);
        out.flush();
    } finally {
        if (out != null) {
            out.close();
        }
    }
}

From source file:mx.unam.ecologia.gye.coalescence.app.CreateSampleConfiguration.java

protected static final void writeSampleConfig(List leaves, String fname) {
    try {//from www  . ja v a 2 s .  co m

        FileOutputStream fout = new FileOutputStream(fname);
        PrintWriter pw = new PrintWriter(fout);
        HaplotypeFreqSet len1 = new HaplotypeFreqSet(new CompoundSequenceLengthComparator());
        HaplotypeFreqSet len2 = new HaplotypeFreqSet(new CompoundSequenceLengthComparator());
        HaplotypeFreqSet ident = new HaplotypeFreqSet(new CompoundSequenceIdentityComparator());

        for (int i = 0; i < leaves.size(); i++) {
            UniParentalGene upgene = (UniParentalGene) leaves.get(i);
            CompoundSequence h = upgene.getCompoundSequence();
            len1.add(h);
            ident.add(h);
            CompoundSequence cs = h.getCopy();
            cs.setLocus(true);
            len2.add(cs);

            int numloc = h.getSequenceCount();
            for (int n = 0; n < numloc; n++) {
                Sequence s = h.get(n);
                pw.print(s.toFullString());
                pw.print(" ");
            }
            pw.println();
        }
        //print length as locus
        pw.println();
        pw.println("Haplotypes by Length (locus)");
        pw.println(len2.toString());
        pw.println("Haplotypes by Length (multilocus)");
        pw.println(len1.toString());
        pw.println("Haplotypes by Identity");
        pw.println(ident.toFullString());
        pw.println();

        //System.out.println("TEST");
        //ident.sort(new CSAncestryComparator());
        //System.out.println(ident.toFullString());
        //System.out.println(ident.findMostFrequent() + 1);

        pw.flush();
        pw.close();
        fout.close();
    } catch (IOException ex) {
        CreateSampleConfiguration.log.error("writeSampleConfig()", ex);
    }

}

From source file:com.adito.util.Utils.java

public static void printIndent(PrintWriter out, int indent) {
    out.print(indent(indent));
}

From source file:eu.pawelsz.apache.beam.coders.TupleCoderGenerator.java

private static void writeTupleCoderClass(PrintWriter w, int numFields) {
    final String tupleClass = "Tuple" + numFields;
    final String className = tupleClass + "Coder";

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < numFields; i++) {
        if (i > 0) {
            sb.append(", ");
        }//from ww w .  j av a 2 s.  co m
        sb.append(GEN_TYPE_PREFIX + i);
    }
    final String types = sb.toString();
    final int maxIdx = numFields - 1;

    // head
    w.print(HEADER);

    // package and imports
    w.println("package " + PACKAGE + ';');
    w.println();
    w.println("import com.fasterxml.jackson.annotation.JsonCreator;");
    w.println("import com.fasterxml.jackson.annotation.JsonProperty;");
    w.println("import com.google.common.base.Preconditions;");
    w.println("import org.apache.beam.sdk.coders.Coder;");
    w.println("import org.apache.beam.sdk.coders.CoderException;");
    w.println("import org.apache.beam.sdk.coders.StandardCoder;");
    w.println("import org.apache.beam.sdk.util.PropertyNames;");
    w.println("import org.apache.beam.sdk.util.common.ElementByteSizeObserver;");
    w.println("import org.apache.flink.api.java.tuple." + tupleClass + ";");
    w.println("");
    w.println("import java.io.IOException;");
    w.println("import java.io.InputStream;");
    w.println("import java.io.OutputStream;");
    w.println("import java.util.Arrays;");
    w.println("import java.util.List;");
    w.println("");
    w.println("public class " + className + "<" + types + "> extends StandardCoder<" + tupleClass + "<" + types
            + ">> {");
    w.println();
    w.println("");
    w.println("  public static <" + types + "> " + className + "<" + types + "> of(");
    for (int i = 0; i < numFields - 1; i++) {
        w.println("      Coder<" + GEN_TYPE_PREFIX + i + "> t" + i + ",");
    }
    w.println("      Coder<" + GEN_TYPE_PREFIX + maxIdx + "> t" + maxIdx + ") {");

    w.print("    return new " + className + "<>(");
    for (int i = 0; i < numFields; i++) {
        if (i > 0) {
            w.print(", ");
        }
        w.print("t" + i);
    }
    w.println(");");
    w.println("  }");
    w.println("");
    w.println("  @JsonCreator");
    w.print("  public static " + className + "<");
    for (int i = 0; i < numFields; i++) {
        if (i > 0) {
            w.print(", ");
        }
        w.print("?");
    }
    w.println("> of(");
    w.println("      @JsonProperty(PropertyNames.COMPONENT_ENCODINGS)");
    w.println("          List<Coder<?>> components) {");
    w.println("    Preconditions.checkArgument(components.size() == " + numFields + ",");
    w.println("        \"Expecting " + numFields + " components, got\" + components.size());");
    w.println("    return of(");
    for (int i = 0; i < numFields; i++) {
        if (i > 0) {
            w.println(",");
        }
        w.print("        components.get(" + i + ")");
    }
    w.println(");");
    w.println("  }");
    w.println("");
    w.println("  public static <" + types + "> List<Object> getInstanceComponents(");
    w.println("      " + tupleClass + "<" + types + "> exampleValue) {");
    w.println("    return Arrays.asList(");
    for (int i = 0; i < numFields; i++) {
        if (i > 0) {
            w.println(",");
        }
        w.print("        exampleValue.f" + i);
    }
    w.println(");");
    w.println("  }");
    for (int i = 0; i < numFields; i++) {
        w.println("");
        w.println("  public Coder<" + GEN_TYPE_PREFIX + i + "> getF" + i + "Coder() {");
        w.println("    return t" + i + "Coder;");
        w.println("  }");
    }
    w.println("");
    for (int i = 0; i < numFields; i++) {
        w.println("  private final Coder<" + GEN_TYPE_PREFIX + i + "> t" + i + "Coder;");
    }
    w.println("");

    w.println("  private " + className + "(");
    for (int i = 0; i < numFields; i++) {
        if (i > 0) {
            w.println(",");
        }
        w.print("      Coder<" + GEN_TYPE_PREFIX + i + "> t" + i + "Coder");
    }
    w.println(") {");
    for (int i = 0; i < numFields; i++) {
        w.println("    this.t" + i + "Coder = t" + i + "Coder;");
    }
    w.println("  }");
    w.println("");
    w.println("  @Override");
    w.println("  public void encode(" + tupleClass + "<" + types
            + "> tuple, OutputStream outputStream, Context context)");
    w.println("      throws CoderException, IOException {");
    w.println("    if (tuple == null) {");
    w.println("      throw new CoderException(\"cannot encode a null " + tupleClass + "\");");
    w.println("    }");
    w.println("    Context nestedContext = context.nested();");
    for (int i = 0; i < numFields; i++) {
        w.println("    t" + i + "Coder.encode(tuple.f" + i + ", outputStream, nestedContext);");
    }
    w.println("  }");
    w.println("");
    w.println("  @Override");
    w.println("  public " + tupleClass + "<" + types + "> decode(InputStream inputStream, Context context)");
    w.println("      throws CoderException, IOException {");
    w.println("    Context nestedContext = context.nested();");
    for (int i = 0; i < numFields; i++) {
        w.println("    " + GEN_TYPE_PREFIX + i + " f" + i + " = t" + i
                + "Coder.decode(inputStream, nestedContext);");
    }
    w.print("    return " + tupleClass + ".of(");
    for (int i = 0; i < numFields; i++) {
        if (i > 0) {
            w.print(", ");
        }
        w.print("f" + i);
    }
    w.println(");");
    w.println("  }");
    w.println("");
    w.println("  @Override");
    w.println("  public List<? extends Coder<?>> getCoderArguments() {");
    w.print("    return Arrays.asList(");
    for (int i = 0; i < numFields; i++) {
        if (i > 0) {
            w.print(", ");
        }
        w.print("t" + i + "Coder");
    }
    w.print(");");
    w.println("  }");
    w.println("");
    w.println("  @Override");
    w.println("  public void verifyDeterministic() throws NonDeterministicException {");
    for (int i = 0; i < numFields; i++) {
        w.println("    verifyDeterministic(\"Coder of T" + i + " must be deterministic\", t" + i + "Coder);");
    }
    w.println("  }");
    w.println("");
    w.println("  @Override");
    w.println("  public boolean consistentWithEquals() {");
    w.print("    return");
    for (int i = 0; i < numFields; i++) {
        if (i > 0) {
            w.print("\n        &&");
        }
        w.print(" t" + i + "Coder.consistentWithEquals()");
    }
    w.println(";");
    w.println("  }");
    w.println("");
    w.println("  @Override");
    w.println("  public Object structuralValue(" + tupleClass + "<" + types + "> tuple) throws Exception {");
    w.println("    if (consistentWithEquals()) {");
    w.println("      return tuple;");
    w.println("    } else {");
    w.println("      return " + tupleClass + ".of(");
    for (int i = 0; i < numFields; i++) {
        if (i > 0) {
            w.println(",");
        }
        w.print("        t" + i + "Coder.structuralValue(tuple.f" + i + ")");
    }
    w.println(");");
    w.println("    }");
    w.println("  }");
    w.println("");
    w.println("  @Override");
    w.println("  public boolean isRegisterByteSizeObserverCheap(" + tupleClass + "<" + types
            + "> tuple, Context context) {");
    w.print("    return");
    for (int i = 0; i < numFields; i++) {
        if (i > 0) {
            w.print("\n        &&");
        }
        w.print(" t" + i + "Coder.isRegisterByteSizeObserverCheap(tuple.f" + i + ", context.nested())");
    }
    w.println(";");
    w.println("  }");
    w.println("");
    w.println("  @Override");
    w.println("  public void registerByteSizeObserver(" + tupleClass + "<" + types + "> tuple,");
    w.println("                                       ElementByteSizeObserver observer,");
    w.println("                                       Context context) throws Exception {");
    w.println("    if (tuple == null) {");
    w.println("      throw new CoderException(\"cannot encode a null " + tupleClass + " \");");
    w.println("    }");
    w.println("    Context nestedContext = context.nested();");
    for (int i = 0; i < numFields; i++) {
        w.println("    t" + i + "Coder.registerByteSizeObserver(tuple.f" + i + ", observer, nestedContext);");
    }
    w.println("  }");
    w.println("}");
}

From source file:it.greenvulcano.util.txt.TextUtils.java

/**
 * Writes a text String into a file//from  ww  w.j av  a2  s .  co m
 * 
 * @param contentString
 *        The String to be written into the file
 * @param filename
 *        The name of the file
 * @param append
 *        If true the data are appended to existent file
 * @throws IOException
 */
public static void writeFile(String contentString, String filename, boolean append) throws IOException {
    PrintWriter out = null;
    try {
        filename = adjustPath(filename);
        out = new PrintWriter(new FileWriter(filename, append));
        out.print(contentString);
        out.flush();
    } finally {
        if (out != null) {
            out.close();
        }
    }
}

From source file:Executable.LinkImputeR.java

private static void writeSumHeader(PrintWriter sum, boolean partial) {
    sum.print("Name\tSamples\tPositions\tAccuracy\tCorrelation\tFilters\tAdditional");
    if (partial) {
        sum.print("\tPartials (Accuracy)\tPartials (Correlation)");
    }//from w w w.  j ava  2s.c  om
    sum.println();
}

From source file:contract_net.main.java

public static void writeToTxt(List<AuctionResult> auctionResults, DispatchAgent da) {
    PrintWriter writer = null;
    try {// w w  w .  j a v a 2s .  c  om
        // generate a unique name for each experiment
        String logFileName = new SimpleDateFormat("yyyyMMddHHmmss'.txt'").format(new Date());
        String logNumberFileName = da + "_" + logFileName;
        writer = new PrintWriter(new BufferedWriter(new FileWriter(logNumberFileName)));
        for (AuctionResult auctionResult : auctionResults) {
            // auction result data are tab delimited, so we can read them as columns
            writer.print(da.toString());
            writer.print("\t");
            writer.print(auctionResult.hashCode());
            writer.print("\t");
            writer.print(auctionResult.getAuction());
            writer.print("\t");
            writer.print(auctionResult.getWinner());
            writer.print("\t");
            writer.print(auctionResult.getBestProposal());
            writer.print("\t");
            writer.print(auctionResult.getBestProposal().getTimeCostProposal());
            writer.print("\t");
            writer.print(auctionResult.getBestProposal()
                    .getDistanceCostProposal(auctionResult.getBestProposal().getTimeCostProposal()));
            writer.print("\t");
            writer.print(auctionResult.getAuctionDuration());
            writer.print("\t");
            writer.print(auctionResult.getRealTimeTruckToPickup());
            writer.print("\t");
            writer.print(auctionResult.getRealTimePickupToDelivery());
            writer.print("\t");
            writer.print(auctionResult.getRealTimeTruckToPickupToDelivery());
            writer.print("\t");
            writer.print(auctionResult.getPickupTardiness(auctionResult.getBestProposal(),
                    auctionResult.getRealTimeTruckToPickup()));
            writer.print("\t");
            writer.print(auctionResult.getDeliveryTardiness(auctionResult.getBestProposal(),
                    auctionResult.getRealTimePickupToDelivery()));
            writer.print("\t");
            writer.print(auctionResult.getPickupDeliveryTardiness(auctionResult.getBestProposal(),
                    auctionResult.getRealTimeTruckToPickupToDelivery()));
            writer.print("\t");
            writer.print(auctionResult.getRealTimeCFPDelivery());
            writer.print("\t");
            //TODO maybe leave away this one
            writer.print(auctionResult.getRejectedProposals());
            // new line for new auction
            writer.println();
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (writer != null) {
            writer.close();
        }
    }
}

From source file:edu.ucsd.ccdb.cil.xml2json.XML2JsonUtil.java

public void outputStringToFile(File f, String json) throws Exception {
    FileOutputStream fout = new FileOutputStream(f);
    PrintWriter pw = new PrintWriter(fout);
    pw.print(json);
    pw.close();//from  w  w  w .j  a va2s.  co m
}

From source file:com.atlassian.clover.reporters.console.ConsoleReporter.java

static void printMetricsSummary(PrintWriter out, String title, ClassMetrics metrics,
        ConsoleReporterConfig cfg) {/* w ww . ja va 2 s  . com*/
    out.println(title);
    out.println("Coverage:-");

    final String methodSummary = infoSummaryString(metrics.getNumCoveredMethods(), metrics.getNumMethods(),
            metrics.getPcCoveredMethods());
    final String stmtSummary = infoSummaryString(metrics.getNumCoveredStatements(), metrics.getNumStatements(),
            metrics.getPcCoveredStatements());
    final String branchSummary = infoSummaryString(metrics.getNumCoveredBranches(), metrics.getNumBranches(),
            metrics.getPcCoveredBranches());
    final String totalSummary = Color.make(Formatting.getPercentStr(metrics.getPcCoveredElements())).b()
            .toString();

    out.print("      Methods: " + methodSummary);
    printPcBar(out, methodSummary, metrics.getPcCoveredMethods());
    out.print("   Statements: " + stmtSummary);
    printPcBar(out, stmtSummary, metrics.getPcCoveredStatements());
    out.print("     Branches: " + branchSummary);
    printPcBar(out, branchSummary, metrics.getPcCoveredBranches());
    out.print("        Total: " + totalSummary);
    printPcBar(out, totalSummary, metrics.getPcCoveredElements());

    out.println("Complexity:-");
    out.println("   Avg Method: " + Formatting.format3d(metrics.getAvgMethodComplexity()));
    out.println("      Density: " + Formatting.format3d(metrics.getComplexityDensity()));
    out.println("        Total: " + metrics.getComplexity());

    if ((cfg != null) && (cfg.isShowUnitTests())) {
        out.println("Tests:-");
        out.println("    Available: " + metrics.getNumTests());
        out.println("     Executed: " + metrics.getNumTestsRun());
        out.println("       Passed: " + metrics.getNumTestPasses());
        out.println("       Failed: " + metrics.getNumTestFailures());
        out.println("       Errors: " + metrics.getNumTestErrors());
    }
}