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:com.googlecode.logVisualizer.LogVisualizer.java

/**
 * Creates KoL data files if they do not already exist in the file system.
 *//* w  w  w  .  j  a va  2  s . c om*/
public static void writeDataFilesToFileSystem() {
    final List<File> kolDataFiles = Lists.newArrayList();
    kolDataFiles
            .add(new File(ROOT_DIRECTORY + File.separator + KOL_DATA_DIRECTORY + "bbcodeAugmentations.txt"));
    kolDataFiles.add(new File(ROOT_DIRECTORY + File.separator + KOL_DATA_DIRECTORY + "htmlAugmentations.txt"));
    kolDataFiles.add(new File(ROOT_DIRECTORY + File.separator + KOL_DATA_DIRECTORY + "textAugmentations.txt"));

    for (final File f : kolDataFiles)
        if (!f.exists()) {
            String tmpLine;
            final BufferedReader br = DataUtilities.getReader(KOL_DATA_DIRECTORY, f.getName());

            try {
                f.createNewFile();
                final PrintWriter fileWriter = new PrintWriter(f);

                while ((tmpLine = br.readLine()) != null)
                    fileWriter.println(tmpLine);

                fileWriter.close();
                br.close();
            } catch (final IOException e) {
                e.printStackTrace();
            }
        }
}

From source file:com.alvermont.terraj.fracplanet.io.ColourFile.java

/**
 * Write a list of colours to a file that can be read by the
 * <code>readFile</code> method of this class.
 *
 * @param colours The list of colours to be written
 * @param target The file object indicating where the data is to be written
 * @throws java.io.IOException If there is an error opening or writing to
 * the file etc.//from w  w  w .  ja v a  2  s  .  c  om
 */
public static void writeFile(List<FloatRGBA> colours, File target) throws IOException {
    final PrintWriter pw = new PrintWriter(new FileOutputStream(target));

    try {
        for (int c = 0; c < colours.size(); ++c) {
            final FloatRGBA col = colours.get(c);

            pw.println(col.getR() + "," + col.getG() + "," + col.getB());
        }
    } finally {
        pw.close();
    }
}

From source file:de.tudarmstadt.ukp.experiments.dip.wp1.documents.Step11GoldDataStatistics.java

public static void statistics3(File inputDir, File outputDir) throws IOException {
    PrintWriter pw = new PrintWriter(new FileWriter(new File(outputDir, "stats3.csv")));
    pw.println("qID\tagreementMean\tagreementStdDev\tqueryText");

    // iterate over query containers
    for (File f : FileUtils.listFiles(inputDir, new String[] { "xml" }, false)) {
        QueryResultContainer queryResultContainer = QueryResultContainer
                .fromXML(FileUtils.readFileToString(f, "utf-8"));

        DescriptiveStatistics statistics = new DescriptiveStatistics();

        for (QueryResultContainer.SingleRankedResult rankedResult : queryResultContainer.rankedResults) {
            Double observedAgreement = rankedResult.observedAgreement;

            if (observedAgreement != null) {
                statistics.addValue(observedAgreement);
            }//  ww w  .j  av a  2  s. c  om
        }

        pw.printf(Locale.ENGLISH, "%s\t%.3f\t%.3f\t%s%n", queryResultContainer.qID, statistics.getMean(),
                statistics.getStandardDeviation(), queryResultContainer.query);
    }

    pw.close();
}

From source file:eu.trentorise.opendata.josman.test.GitTest.java

private static File createFile(Repository repository, String filePath) {

    try {// w  ww . ja va2 s.c o  m
        // create the file

        File targetFile = new File(repository.getDirectory().getParent(), filePath);
        File parent = targetFile.getParentFile();
        if (!parent.exists() && !parent.mkdirs()) {
            throw new IllegalStateException("Couldn't create dir: " + parent);
        }

        targetFile.createNewFile();

        PrintWriter pw = new PrintWriter(targetFile);
        pw.println("hello");
        pw.close();

        // run the add-call
        new Git(repository).add().addFilepattern(filePath).call();

        return targetFile;

    } catch (Exception ex) {
        throw new RuntimeException("Error while creating file!", ex);
    }
}

From source file:info.hieule.framework.laravel.utils.LaravelSecurityString.java

public static void updateSecurityString(FileObject configFile) throws IOException {
    List<String> lines = configFile.asLines();
    String newKey = RandomStringUtils.randomAlphanumeric(32);
    OutputStream outputStream = configFile.getOutputStream();
    PrintWriter pw = new PrintWriter(new OutputStreamWriter(outputStream, "UTF-8"), true); // NOI18N
    try {//ww w. j a v  a  2 s . co  m
        for (String line : lines) {
            if (line.contains(_SECURITY_STRING_LINE)) {
                line = String.format(_SECURITY_STRING_FORMAT, newKey);
            }
            pw.println(line);
        }
    } finally {
        outputStream.close();
        pw.close();
    }
}

From source file:com.twosigma.beaker.core.Main.java

private static void writePID(BeakerConfig bkConfig) throws FileNotFoundException {

    String name = ManagementFactory.getRuntimeMXBean().getName();
    int at = name.indexOf("@");
    if (at > 0) {
        String pid = name.substring(0, at);
        String dir = bkConfig.getNginxServDirectory();
        PrintWriter out = new PrintWriter(dir + "/pid");
        out.println(pid);
        out.close();/*from w w w.  jav a2 s  .  co  m*/
    } else {
        logger.warn("warning, could not determine PID");
    }
}

From source file:de.tudarmstadt.ukp.experiments.dip.wp1.documents.Step11GoldDataStatistics.java

/**
 * (2) which documents were eventually judged as relevant ones.
 * So basically a plain text file with 3 columns:
 * query_id, document_id, binary_relevance
 * This will allow us to judge the document lists and give some performance, at least of
 * document level. This will allow us to identify "hard" and "easy" queries and having an agreement
 * rate per query we can see whether the two correlate. Then we potentially can "blame" the harder
 * queries for low agreement.//  w w  w . j a v  a 2 s . c o  m
 */
public static void statistics2(File inputDir, File outputDir) throws IOException {
    PrintWriter pw = new PrintWriter(new FileWriter(new File(outputDir, "stats2.csv")));
    pw.println("qID\tclueWebID\tpartiallyRelevant\tfullyRelevant\trankedResult.rank\trankedResult.score");

    // iterate over query containers
    for (File f : FileUtils.listFiles(inputDir, new String[] { "xml" }, false)) {
        QueryResultContainer queryResultContainer = QueryResultContainer
                .fromXML(FileUtils.readFileToString(f, "utf-8"));

        for (QueryResultContainer.SingleRankedResult rankedResult : queryResultContainer.rankedResults) {
            List<QueryResultContainer.SingleSentenceRelevanceVote> goldEstimatedLabels = rankedResult.goldEstimatedLabels;
            if (goldEstimatedLabels != null && !goldEstimatedLabels.isEmpty()) {
                boolean fullyRelevant = true;
                boolean partiallyRelevant = false;

                // all must be relevant
                for (QueryResultContainer.SingleSentenceRelevanceVote s : goldEstimatedLabels) {
                    fullyRelevant &= Boolean.valueOf(s.relevant);
                    partiallyRelevant |= Boolean.valueOf(s.relevant);
                }

                pw.printf(Locale.ENGLISH, "%s\t%s\t%s\t%s\t%d\t%.8f%n", queryResultContainer.qID,
                        rankedResult.clueWebID, partiallyRelevant, fullyRelevant, rankedResult.rank,
                        rankedResult.score);
            }
        }
    }
    pw.close();
}

From source file:edu.msu.cme.rdp.readseq.utils.SequenceTrimmer.java

public static void writeStatsHeader(PrintWriter out) {
    out.println(
            "#seq name\tfirst model pos\tlast model pos\tfilled ratio\ttrim seq start coord\ttrim seq end coord\tNs\tNs in trimmed seq\ttrimmed seq length\tseq length\tpassed trimming");
}

From source file:fr.inria.maestro.lga.graph.model.impl.nodenamer.NodeNamerImpl.java

/**
 * writes the file from a given List/*w w  w  .  j a  v  a2 s .c o m*/
 *
 * @param file
 * @param lines
 * @throws IOException
 */
public static void save(final File file, final List<String> lines) throws IOException {
    final PrintWriter os = new PrintWriter(file, Encoding.DEFAULT_CHARSET_NAME); //default charset is utf-8
    try {
        for (final String line : lines) {
            os.println(line);
        }
    } finally {
        os.close();
    }
}

From source file:de.tudarmstadt.ukp.experiments.dip.wp1.documents.Step11GoldDataStatistics.java

/**
 * The following (full) data://from w  w w  .  java2 s  . c o  m
 * query docID rank agreement score relevance length
 * (7 columns)
 * The above detailed data about all annotated documents will allow me to
 * calculate different aggregations, such as average agreement at top 20
 * documents and etc...
 * By "relevance" is meant partial relevance.
 */
public static void statistics4(File inputDir, File outputDir) throws IOException {
    PrintWriter pw = new PrintWriter(new FileWriter(new File(outputDir, "stats4.csv")));
    pw.println("query\tdocID\trank\tagreement\tscore\trelevance\tlength");

    // iterate over query containers
    for (File f : FileUtils.listFiles(inputDir, new String[] { "xml" }, false)) {
        QueryResultContainer queryResultContainer = QueryResultContainer
                .fromXML(FileUtils.readFileToString(f, "utf-8"));
        System.out.println("Processing " + f);

        for (QueryResultContainer.SingleRankedResult rankedResult : queryResultContainer.rankedResults) {
            double agreement = rankedResult.observedAgreement != null ? rankedResult.observedAgreement : 0;

            boolean isRelevant = false;

            List<QueryResultContainer.SingleSentenceRelevanceVote> goldEstimatedLabels = rankedResult.goldEstimatedLabels;
            // all must be relevant
            if (goldEstimatedLabels != null) {
                for (QueryResultContainer.SingleSentenceRelevanceVote s : goldEstimatedLabels) {
                    isRelevant |= Boolean.valueOf(s.relevant);
                }
            }

            pw.printf(Locale.ENGLISH, "%s\t%s\t%d\t%.3f\t%.8f\t%b\t%d%n", queryResultContainer.qID,
                    rankedResult.clueWebID, rankedResult.rank, agreement, rankedResult.score, isRelevant,
                    rankedResult.plainText != null ? rankedResult.plainText.length() : 0);
        }
    }

    pw.close();

}