Example usage for java.io BufferedWriter newLine

List of usage examples for java.io BufferedWriter newLine

Introduction

In this page you can find the example usage for java.io BufferedWriter newLine.

Prototype

public void newLine() throws IOException 

Source Link

Document

Writes a line separator.

Usage

From source file:org.matsim.contrib.drt.analysis.DrtRequestAnalyzer.java

public void writeAndPlotWaitTimeEstimateComparison(String plotFileName, String textFileName) {
    BufferedWriter bw = IOUtils.getBufferedWriter(textFileName);

    XYSeries times = new XYSeries("waittimes", true, true);

    try {/*  www.j a v a2s  . c  o  m*/
        bw.append("RequestId;actualWaitTime;estimatedWaitTime;deviate");
        for (Entry<Id<Request>, Tuple<Double, Double>> e : this.waitTimeCompare.entrySet()) {
            bw.newLine();
            double first = e.getValue().getFirst();
            double second = e.getValue().getSecond();
            bw.append(e.getKey().toString() + ";" + first + ";" + second + ";" + (first - second));
            times.add(first, second);
        }
        bw.flush();
        bw.close();

        final JFreeChart chart2 = DensityScatterPlots.createPlot("Wait times", "Actual wait time [s]",
                "Initially planned wait time [s]", times, Pair.of(0., drtCfg.getMaxWaitTime()));
        //         xAxis.setLowerBound(0);
        //         yAxis.setLowerBound(0);
        ChartUtilities.writeChartAsPNG(new FileOutputStream(plotFileName), chart2, 1500, 1500);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:jade.core.messaging.FileMessageStorage.java

private void decrementCounter(File f) throws IOException {

    BufferedReader in = new BufferedReader(new FileReader(f));
    File tmp = File.createTempFile("JADE", ".tmp");
    String s = in.readLine();//from   www.  ja v a 2s. com
    try {
        long counter = Long.parseLong(s);
        counter--;
        if (counter == 0) {
            in.close();
            f.delete();
        } else {
            BufferedWriter out = new BufferedWriter(new FileWriter(tmp));
            try {
                s = Long.toString(counter);
                out.write(s, 0, s.length());
                out.newLine();

                s = in.readLine();
                while (s != null) {
                    out.write(s, 0, s.length());
                    out.newLine();
                    s = in.readLine();
                }
            } finally {
                in.close();
                out.close();
            }

            f.delete();
            tmp.renameTo(f);
        }
    } catch (NumberFormatException nfe) {
        in.close();
        nfe.printStackTrace();
    }

}

From source file:com.itemanalysis.psychometrics.irt.estimation.MMLEsimulation.java

private void processReplication(int rep) {
    String inputPath = "S:\\2014-3pl-simulation\\simdata\\c3";
    String outputPath = inputPath + "\\jmetrik-output";
    String dataFile = "";

    int nItems = 40;

    ItemResponseFileSummary fileSummary = new ItemResponseFileSummary();

    dataFile = "\\c3rep" + (rep + 1) + ".txt";
    ItemResponseVector[] responseData = fileSummary.getResponseVectors(inputPath + dataFile, false);

    //Create array of 2PL item response models
    ItemResponseModel[] irm = new ItemResponseModel[nItems];
    Irm3PL pl3 = null;//from   w  ww.  ja v  a 2s.  com
    for (int j = 0; j < nItems; j++) {
        pl3 = new Irm3PL(1.0, 0.0, 0.05, 1.0);
        pl3.setDiscriminationPrior(new ItemParamPriorLogNormal(0.13, 0.6));
        pl3.setDifficultyPrior(new ItemParamPriorNormal(0.0, 2.0));

        //            pl3.setDiscriminationPrior(new ItemParamPriorBeta4(1.75, 3.0, 0.0, 3.0));//ICL default
        //            pl3.setDifficultyPrior(new ItemParamPriorBeta4(1.01, 1.01, -6.0, 6.0));//default ICL prior
        pl3.setGuessingPrior(new ItemParamPriorBeta4(3.75, 4, 0.0, 0.5));//default ICL prior
        irm[j] = pl3;
    }

    //computation of quadrature points as done in the mirt R package
    double quadPoints = 41;
    double min = -.8 * Math.sqrt(quadPoints);
    double max = -1 * min;
    NormalDistributionApproximation latentDistribution = new NormalDistributionApproximation(min, max,
            (int) quadPoints);

    //        HermiteRuleFactory gaussHermite = new HermiteRuleFactory();
    //        Pair<double[], double[]> dist = gaussHermite.getRule(41);
    //        UserSuppliedDistributionApproximation latentDistribution = new UserSuppliedDistributionApproximation(dist.getKey(), dist.getValue());

    //compute start values
    StartingValues startValues = new StartingValues(responseData, irm);
    irm = startValues.computeStartingValues();

    //estimate parameters
    MarginalMaximumLikelihoodEstimation mmle = new MarginalMaximumLikelihoodEstimation(responseData, irm,
            latentDistribution);
    //        mmle.setVerbose(true);
    DefaultEMStatusListener emStatus = new DefaultEMStatusListener();
    mmle.addEMStatusListener(emStatus);
    mmle.estimateParameters(0.0001, 250);
    System.out.println("Replication " + (rep + 1) + " complete");

    //        System.out.println(mmle.printItemParameters());

    try {
        File f = new File(outputPath + dataFile);
        BufferedWriter writer = new BufferedWriter(new FileWriter(f));
        for (int j = 0; j < nItems; j++) {
            writer.write(Precision.round(irm[j].getDiscrimination(), 6) + ","
                    + Precision.round(irm[j].getDifficulty(), 6) + ","
                    + Precision.round(irm[j].getGuessing(), 6));
            writer.newLine();
        }
        writer.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    }

}

From source file:io.hops.transaction.context.TransactionsStats.java

private void dumpDetailed() throws IOException {
    if (detailedStats) {
        BufferedWriter writer = getStatsLogWriter();
        for (TransactionStat stat : transactionStats) {
            writer.write("Transaction: " + stat.name.toString());
            writer.newLine();
            dump(writer, stat);/*from www. j  a  v a 2s  . com*/
            writer.newLine();
            writer.newLine();
        }
    }
}

From source file:edu.illinois.cs.cogcomp.core.datastructures.Lexicon.java

/**
 * Saves the feature to id mapping. Note: This does not store the feature names.
 *///from   w w  w  .j  a  v a2  s  . c om
public void save(String file) throws IOException {
    BufferedOutputStream stream = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(file)));

    final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stream));

    writer.write(lexManagerVersion);
    writer.newLine();

    writeInt(writer, nextFeatureId);

    log.info("Lexicon contains {} features", feature2Id.size());

    writeInt(writer, feature2Id.size());

    feature2Id.forEachEntry(new TIntIntProcedure() {

        @Override
        public boolean execute(int a, int b) {
            try {
                writeInt(writer, a);
                writeInt(writer, b);

            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return true;
        }
    });

    if (featureNames != null) {
        writeInt(writer, featureNames.size());
        for (String s : featureNames) {
            writer.write(s);
            writer.newLine();
        }

    } else {
        writeInt(writer, 0);
    }

    writer.close();

    log.info("Verifying save...");
    new Lexicon(new FileInputStream(new File(file)), false);
    log.info("Done.");
}

From source file:jade.core.messaging.FileMessageStorage.java

private void incrementCounter(File f) throws IOException {
    BufferedReader in = new BufferedReader(new FileReader(f));
    File tmp = File.createTempFile("JADE", ".tmp");
    String s = in.readLine();//from w ww  .  j av a  2s . c o m
    try {
        long counter = Long.parseLong(s);
        BufferedWriter out = new BufferedWriter(new FileWriter(tmp));
        try {
            counter++;
            s = Long.toString(counter);
            out.write(s, 0, s.length());
            out.newLine();

            s = in.readLine();
            while (s != null) {
                out.write(s, 0, s.length());
                out.newLine();
                s = in.readLine();
            }
        } finally {
            out.close();
        }
    } catch (NumberFormatException nfe) {
        nfe.printStackTrace();
    } finally {
        in.close();
    }

    f.delete();
    tmp.renameTo(f);

}

From source file:BwaSingleAlignment.java

/**
 * Code to run in each one of the mappers. This is, the alignment with the corresponding entry data
 * The entry data has to be written into the local filesystem
 *///from w  ww .ja v a 2 s .c o m
@Override
public Iterator<String> call(Integer arg0, Iterator<String> arg1) throws Exception {

    LOG.info("JMAbuin:: Tmp dir: " + this.tmpDir);
    String fastqFileName1 = this.tmpDir + this.appId + "-RDD" + arg0 + "_1";

    LOG.info("JMAbuin:: Writing file: " + fastqFileName1);

    File FastqFile1 = new File(fastqFileName1);
    FileOutputStream fos1;
    BufferedWriter bw1;

    ArrayList<String> returnedValues = new ArrayList<String>();

    try {
        fos1 = new FileOutputStream(FastqFile1);
        bw1 = new BufferedWriter(new OutputStreamWriter(fos1));

        String newFastqRead;

        while (arg1.hasNext()) {
            newFastqRead = arg1.next();

            bw1.write(newFastqRead.toString());
            bw1.newLine();
        }

        bw1.close();

        //We do not need the input data anymore, as it is written in a local file
        arg1 = null;

        returnedValues = this.runAlignmentProcess(arg0, fastqFileName1, null);
        // Delete the temporary file, as is have now been copied to the
        // output directory
        FastqFile1.delete();

    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        LOG.error(e.toString());
    }

    return returnedValues.iterator();
}

From source file:org.ivan.service.ExcelExporter.java

public File createExcelExport(List<Person> objects, List<String> headers, String fileName) throws IOException {

    File xlsFile = new File(fileName);
    FileWriter writer = new FileWriter(xlsFile);

    BufferedWriter bufferedWriter = new BufferedWriter(writer);
    for (int i = 0; i < headers.size(); i++) {
        String cup = headers.get(i);

        if (i < headers.size() - 1) {
            cup += "\t";
        }/*w  w  w .  j  a  v  a  2s .c  o m*/
        bufferedWriter.write(cup);
    }
    bufferedWriter.newLine();
    for (Person obj : objects) {
        bufferedWriter.write(obj.getPersonId() + "\t");
        bufferedWriter.write(obj.getPersonName() + "\t");
        bufferedWriter.write(obj.getGender() + "\t");
        bufferedWriter.write(obj.getAddress().getAddressId() + "\t");
        bufferedWriter.write(obj.getAddress().getStreet() + "\t");
        bufferedWriter.write(obj.getAddress().getCity() + "\t");
        bufferedWriter.write(obj.getAddress().getCountry() + "\n");
    }

    bufferedWriter.close();

    return xlsFile;
}

From source file:jatoo.exec.InputStreamExhausterWithDumpStream.java

public final void exhaust() {

    BufferedReader processInputStreamReader = null;
    BufferedWriter dumpOutputStreamWriter = null;

    try {//from w  w w  .  ja va2  s  .  c om

        processInputStreamReader = new BufferedReader(new InputStreamReader(processInputStream));
        dumpOutputStreamWriter = new BufferedWriter(new OutputStreamWriter(dumpOutputStream));

        String line = null;
        while ((line = processInputStreamReader.readLine()) != null) {

            dumpOutputStreamWriter.write(line);
            dumpOutputStreamWriter.newLine();

            dumpOutputStreamWriter.flush();
        }
    }

    catch (IOException e) {
        LOGGER.error("error exhausting the stream", e);
    }

    finally {
        if (closeDumpOutputStream && dumpOutputStreamWriter != null) {
            try {
                dumpOutputStreamWriter.close();
            } catch (IOException e) {
                LOGGER.error("error closing the dump stream", e);
            }
        }
    }
}

From source file:com.ephesoft.dcma.util.FileUtils.java

/**
 * API to write a list of Strings to a property file.
 * /*from  w  ww . ja v  a 2s  .  c  o  m*/
 * @param propertyFile {@link File}
 * @param propertiesToWrite {@link List}
 * @throws IOException
 */
private static void writeToPropertyFile(final File propertyFile, final List<String> propertiesToWrite)
        throws IOException {

    FileWriter fileWriter = null;
    BufferedWriter bufferedWriter = null;
    try {
        fileWriter = new FileWriter(propertyFile, false);
        bufferedWriter = new BufferedWriter(fileWriter);
        for (String lineToWrite : propertiesToWrite) {
            bufferedWriter.write(lineToWrite);
            bufferedWriter.newLine();
        }
    } finally {
        if (bufferedWriter != null) {
            try {
                bufferedWriter.close();
            } catch (IOException exception) {
                LOGGER.error("Exception occured while closing bufferedWriter : " + exception);
            }
        }
        if (fileWriter != null) {
            try {
                fileWriter.close();
            } catch (IOException exception) {
                LOGGER.error("Exception occured while closing fileWriter : " + exception);
            }
        }

    }

}