Example usage for java.io PrintWriter println

List of usage examples for java.io PrintWriter println

Introduction

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

Prototype

public void println(Object x) 

Source Link

Document

Prints an Object and then terminates the line.

Usage

From source file:net.sf.firemox.tools.Converter.java

/**
 * DCK format should be :// w w  w  .  j av  a 2s  . c o  m
 * <ul>
 * <li>;comment</li>
 * <li>...</li>
 * <li>...\t$number $card-name</li>
 * </ul>
 * 
 * @param directory
 *          the directory containing the files to translate.
 * @throws IOException
 *           If some other I/O error occurs
 */
public static void convertDCK(String directory) throws IOException {
    final File file = MToolKit.getFile(directory);
    if (!file.isDirectory()) {
        throw new RuntimeException("The given parameter should be a directory");
    }

    File[] list = file.listFiles((FileFilter) FileFilterUtils.suffixFileFilter("dck"));
    for (File fileI : list) {
        String fileName = FilenameUtils.removeExtension(fileI.getAbsolutePath()) + ".txt";
        FileOutputStream out = new FileOutputStream(fileName);
        InputStream in = new FileInputStream(fileI);
        BufferedReader bufIn = new BufferedReader(new InputStreamReader(in));
        PrintWriter bufOut = new PrintWriter(out);
        String line = null;
        while ((line = bufIn.readLine()) != null) {
            if (line.startsWith(";")) {
                // this is a comment
                bufOut.println("#" + line.substring(1));
            } else if (line.startsWith(".") && line.indexOf('\t') > 1) {
                // this is a line containing card definition
                line = line.substring(line.indexOf('\t') + 1).trim();
                int delim = line.indexOf('\t');
                String cardName = line.substring(delim + 1);
                cardName = cardName.replaceAll(" : ", "_").replaceAll(" :", "_").replaceAll(": ", "_")
                        .replaceAll(":", "_").replaceAll(" ", "_").replaceAll("'", "").replaceAll(",", "")
                        .replaceAll("-", "");
                bufOut.println(cardName + ";" + line.substring(0, delim));
            }
        }
        IOUtils.closeQuietly(bufOut);
        IOUtils.closeQuietly(bufIn);
    }
}

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

private static void writeRegistration(PrintWriter w) {
    w.print(HEADER);// w ww  .  j  a  v a2  s .c o  m

    w.println("package " + PACKAGE + ";");
    w.println("");
    w.println("import org.apache.beam.sdk.Pipeline;");
    w.println("import org.apache.beam.sdk.coders.CoderRegistry;");
    for (int i = FIRST; i < LAST; i++) {
        w.println("import org.apache.flink.api.java.tuple.Tuple" + i + ";");
    }
    w.println("");
    w.println("public class RegisterTupleCoders {");
    w.println("    public static void run(Pipeline p) {");
    w.println("        CoderRegistry cr = p.getCoderRegistry();");
    for (int i = FIRST; i < LAST; i++) {
        w.println("        cr.registerCoder(Tuple" + i + ".class, Tuple" + i + "Coder.class);");
    }
    w.println("    }");
    w.println("}");
    w.println("");
}

From source file:Main.java

/**
 * Print a DOM tree to an output stream or if there is an exception while doing so, print the
 * stack trace./*www.j a v  a  2  s .  co m*/
 *
 * @param dom
 * @param os
 */
public static void printDom(Node dom, OutputStream os) {
    Transformer trans;
    PrintWriter w = new PrintWriter(os);
    try {
        TransformerFactory fact = TransformerFactory.newInstance();
        trans = fact.newTransformer();
        trans.transform(new DOMSource(dom), new StreamResult(new OutputStreamWriter(os)));
    } catch (TransformerException e) {
        w.println("An error ocurred while transforming the given DOM:");
        e.printStackTrace(w);
    }
}

From source file:com.qwazr.utils.IOUtils.java

public static final void appendLines(File file, String... lines) throws IOException {
    FileWriter fw = null;/*  w  ww .j av  a 2s. c o  m*/
    PrintWriter pw = null;
    try {
        fw = new FileWriter(file, true);
        pw = new PrintWriter(fw);
        for (String line : lines)
            pw.println(line);
    } finally {
        close(fw, pw);
    }
}

From source file:io.uengine.util.StringUtils.java

/**
 * Properties? key value ? ./*from  w w  w . j av a 2 s  .com*/
 *
 * @param properties Properties
 * @return key value ?
 */
public static String propertiesToString(Properties properties) {
    StringWriter writer = new StringWriter();
    PrintWriter out = new PrintWriter(writer);
    Set<Object> keys = properties.keySet();
    for (Object key : keys) {
        out.println(key + "=" + properties.get(key));
    }
    return writer.getBuffer().toString();
}

From source file:ReflectionUtils.java

/**
 * Print all of the thread's information and stack traces.
 * //from   w w  w.j  a  v a2s  . co m
 * @param stream
 *          the stream to
 * @param title
 *          a string title for the stack trace
 */
public static void printThreadInfo(PrintWriter stream, String title) {
    final int STACK_DEPTH = 20;
    boolean contention = threadBean.isThreadContentionMonitoringEnabled();
    long[] threadIds = threadBean.getAllThreadIds();
    stream.println("Process Thread Dump: " + title);
    stream.println(threadIds.length + " active threads");
    for (long tid : threadIds) {
        ThreadInfo info = threadBean.getThreadInfo(tid, STACK_DEPTH);
        if (info == null) {
            stream.println("  Inactive");
            continue;
        }
        stream.println("Thread " + getTaskName(info.getThreadId(), info.getThreadName()) + ":");
        Thread.State state = info.getThreadState();
        stream.println("  State: " + state);
        stream.println("  Blocked count: " + info.getBlockedCount());
        stream.println("  Waited count: " + info.getWaitedCount());
        if (contention) {
            stream.println("  Blocked time: " + info.getBlockedTime());
            stream.println("  Waited time: " + info.getWaitedTime());
        }
        if (state == Thread.State.WAITING) {
            stream.println("  Waiting on " + info.getLockName());
        } else if (state == Thread.State.BLOCKED) {
            stream.println("  Blocked on " + info.getLockName());
            stream.println("  Blocked by " + getTaskName(info.getLockOwnerId(), info.getLockOwnerName()));
        }
        stream.println("  Stack:");
        for (StackTraceElement frame : info.getStackTrace()) {
            stream.println("    " + frame.toString());
        }
    }
    stream.flush();
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.sampling.Step4MTurkOutputCollector.java

/**
 * Creates .success files for updating HITs in order to require more assignments.
 *
 * @param assignmentsPerHits actual assignments per HIT
 * @param hitTypeID          type//from  w  ww  .jav a  2s .  c o  m
 * @param resultFile         source MTurk file
 * @throws IOException IO exception
 */

static void prepareUpdateHITsFiles(Map<String, Integer> assignmentsPerHits, String hitTypeID, File resultFile)
        throws IOException {
    TreeSet<Integer> assignmentNumbers = new TreeSet<>(assignmentsPerHits.values());

    System.out.println(assignmentsPerHits);

    // how many is required to be fully annotated
    final int fullyAnnotated = 5;

    assignmentNumbers.remove(fullyAnnotated);

    for (Integer i : assignmentNumbers) {
        // output file
        int annotationsRequired = fullyAnnotated - i;
        File file = new File(resultFile + "_requires_extra_assignments_" + annotationsRequired + ".success");
        PrintWriter pw = new PrintWriter(file, "utf-8");
        pw.println("hitid\thittypeid");

        for (Map.Entry<String, Integer> entry : assignmentsPerHits.entrySet()) {
            if (i.equals(entry.getValue())) {
                pw.println(entry.getKey() + "\t" + hitTypeID);
            }
        }

        pw.close();

        System.out.println(
                "Extra annotations required (" + annotationsRequired + "), saved to " + file.getAbsolutePath());
    }
}

From source file:de.alpharogroup.exception.ExceptionExtensions.java

/**
 * Gets the stack trace elements from the given Throwable and returns a {@link String} object
 * from it.//  w  ww.j  av a  2  s.  co  m
 *
 * @param throwable
 *            the throwable
 * @return the stack trace elements
 */
public static String getStackTraceElements(Throwable throwable) {
    StringWriter sw = null;
    PrintWriter pw = null;
    String stacktrace = "throwable is null...";
    if (throwable != null) {
        try {
            sw = new StringWriter();
            pw = new PrintWriter(sw);
            pw.println(throwable.getClass().toString());
            while (throwable != null) {
                pw.println(throwable);
                final StackTraceElement[] stackTraceElements = throwable.getStackTrace();
                for (final StackTraceElement stackTraceElement : stackTraceElements) {
                    pw.println("\tat " + stackTraceElement);
                }

                throwable = throwable.getCause();
                if (throwable != null) {
                    pw.println("Caused by:\r\n");
                }
            }
            stacktrace = sw.toString();
        } finally {
            StreamExtensions.closeWriter(sw);
            StreamExtensions.closeWriter(pw);
        }
    }

    return stacktrace;
}

From source file:com.espertech.esper.view.ViewSupport.java

/**
 * Convenience method for logging the parameters passed to the update method. Only logs if debug is enabled.
 * @param prefix is a prefix text to output for each line
 * @param newData is the new data in an update call
 * @param oldData is the old data in an update call
 *///w  ww .ja  v  a2  s  .co m
public static void dumpUpdateParams(String prefix, Object[] newData, Object[] oldData) {
    if (!log.isDebugEnabled()) {
        return;
    }

    StringWriter buffer = new StringWriter();
    PrintWriter writer = new PrintWriter(buffer);
    if (newData == null) {
        writer.println(prefix + " newData=null ");
    } else {
        writer.println(prefix + " newData.size=" + newData.length + "...");
        printObjectArray(prefix, writer, newData);
    }

    if (oldData == null) {
        writer.println(prefix + " oldData=null ");
    } else {
        writer.println(prefix + " oldData.size=" + oldData.length + "...");
        printObjectArray(prefix, writer, oldData);
    }
}

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

static void printMetricsSummary(PrintWriter out, String title, ClassMetrics metrics,
        ConsoleReporterConfig cfg) {// w  ww.  j ava 2s  . c om
    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());
    }
}