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:com.sciaps.utils.ImportExportSpectrumCSV.java

public void exportSpectrumFile(File saveFile, PiecewiseSpectrum spectrum) throws IOException {
    if (spectrum == null || saveFile == null) {
        logger_.warn("", "will not save spectrum csv file");
        return;/* ww  w . j  a v a  2s.  c o  m*/
    }

    final UnivariateFunction intensity = spectrum.getIntensityFunction();

    BufferedWriter bout = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(saveFile)));
    try {
        bout.append("wavelength, intensity");
        bout.newLine();
        final DoubleRange range = spectrum.getValidRange();

        for (double x = range.getMinimumDouble(); x <= range.getMaximumDouble(); x += 1.0
                / EXPORT_SAMPLE_RATE) {
            double y = intensity.value(x);
            if (Double.isNaN(y)) {
                y = 0;
            }
            bout.append(Double.toString(x));
            bout.append(", ");
            bout.append(Double.toString(y));
            bout.newLine();
        }
    } finally {
        bout.close();
    }

    logger_.info("saved spectrum csv file to " + saveFile.getAbsolutePath());
}

From source file:fr.calamus.common.tools.AbstractTxtFileAccess.java

/**
 * Saves data (obtained by getLines()) in the file.
 *///from  ww w. j  a v a  2  s . com
public void save() {
    try {
        BufferedWriter bw = prepareBufferedWriter();
        List<String> lines = getLines();
        for (int i = 0; i < lines.size(); i++) {
            bw.write(lines.get(i));
            bw.newLine();
        }
        bw.flush();
        bw.close();
    } catch (IOException ex) {
        //log.error("", ex);
        ex.printStackTrace();
    }
}

From source file:ffx.utilities.BlockAverager.java

/**
 * Uncorrelated process: x = 5 + 2 * rand(N,1) - 1 Correlated process: x(1)
 * = 0; x(t+1) = 0.95 * x(t) + 2 * rand(N,1) - 1; shift all up by 5
 *///ww w  .  j  a  va 2s. c  om
public static void generateTestData(String filename, int size) throws IOException {
    logger.info(format(" Generating test data set of size: %d.", size));
    File outFile = new File(filename);
    if (outFile.exists()) {
        logger.severe("Outfile already exists.");
    }
    Random rng = new Random();
    double[] uncor = new double[size];
    double[] corr = new double[size];
    corr[0] = 0.0;
    for (int i = 0; i < size; i++) {
        uncor[i] = 5 + (2 * rng.nextDouble() - 1);
        if (i > 0) {
            corr[i] = 0.95 * corr[i - 1] + (2 * rng.nextDouble() - 1);
        }
    }
    for (int i = 0; i < size; i++) {
        corr[i] += 5.0;
    }
    BufferedWriter bw = new BufferedWriter(new FileWriter(outFile));
    for (int i = 0; i < size; i++) {
        bw.write(format(" %4d  %6.4f  %6.4f", i, uncor[i], corr[i]));
        bw.newLine();
    }
    bw.close();
    logger.info(format("    Data saved to: %s", filename));
}

From source file:de.micromata.genome.util.runtime.config.LocalSettingsWriter.java

protected void storeLocalSettingsEntry(BufferedWriter writer, LocalSetingsEntry entry) throws IOException {
    if (StringUtils.isNotBlank(entry.comment) == true) {
        writer.newLine();
        PropertiesReadWriter.writeComments(writer, entry.comment);
    }/*from   w  w w . j a v a2s .c o  m*/
    writeEntryKeyValue(writer, entry.key, entry.value);
}

From source file:de.micromata.genome.util.runtime.config.LocalSettingsWriter.java

protected void storeSection(BufferedWriter writer, LocalSettingsSection section) throws IOException {
    if (StringUtils.isNotBlank(section.comment) == true) {
        writer.newLine();
        writer.newLine();/* ww w . java  2  s  .c om*/
        PropertiesReadWriter.writeComments(writer, section.comment);
    }
    for (LocalSetingsEntry entry : section.entries) {
        storeLocalSettingsEntry(writer, entry);
    }
}

From source file:TextFile.java

/**
 * Writes the specified list of lines to the file.
 * /*  w ww  .  ja  v  a 2s.  co  m*/
 * @param lines The lines to be written
 * @throws IOException if an I/O exception occurs
 */
public void writeLines(final List<String> lines) throws IOException {
    if (file == null) {
        throw new UnsupportedOperationException("Cannot write to TextFile " + "opened with an InputStream");
    }

    final BufferedWriter writer = new BufferedWriter(new FileWriter(file));

    for (String line : lines) {
        writer.write(line);
        writer.newLine();
    }

    writer.close();
}

From source file:de.hska.ld.core.config.LDLoggerConfig.java

@Autowired
private void init() throws IOException {
    File f = File.createTempFile("tinylog_conf", ".txt");
    FileOutputStream fos = new FileOutputStream(f);
    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));
    try {/*from   ww w  .  ja  va2  s  .c  o m*/
        String writer = env.getProperty("tinylog.writer");
        bw.write("tinylog.writer = " + writer);
        bw.newLine();
        /*String fileName = env.getProperty("tinylog.writer.filename");
        bw.write("tinylog.writer.filename = " + fileName);
        bw.newLine();
        String buffered = env.getProperty("tinylog.writer.buffered");
        bw.write("tinylog.writer.buffered = " + buffered);
        bw.newLine();
        String append = env.getProperty("tinylog.writer.append");
        bw.write("tinylog.writer.append = " + append);
        bw.newLine();*/
        String level = env.getProperty("tinylog.level");
        bw.write("tinylog.level = " + level);
        bw.newLine();
        String writerUrl = env.getProperty("tinylog.writer.url");
        bw.write("tinylog.writer.url = " + writerUrl);
        bw.newLine();
        String writerTable = env.getProperty("tinylog.writer.table");
        bw.write("tinylog.writer.table = " + writerTable);
        bw.newLine();
        String writerColumns = env.getProperty("tinylog.writer.columns");
        bw.write("tinylog.writer.columns = " + writerColumns);
        bw.newLine();
        String writerValues = env.getProperty("tinylog.writer.values");
        bw.write("tinylog.writer.values = " + writerValues);
        bw.newLine();
        String writerBatch = env.getProperty("tinylog.writer.batch");
        bw.write("tinylog.writer.batch = " + writerBatch);
        bw.newLine();
        String writerUsername = env.getProperty("tinylog.writer.username");
        bw.write("tinylog.writer.username = " + writerUsername);
        bw.newLine();
        String writerPassword = env.getProperty("tinylog.writer.password");
        bw.write("tinylog.writer.password = " + writerPassword);
        bw.newLine();
        String writingThread = env.getProperty("tinylog.writingthread");
        bw.write("tinylog.writingthread = " + writingThread);
        bw.newLine();
        String wTObserve = env.getProperty("tinylog.writingthread.observe");
        bw.write("tinylog.writingthread.observe = " + wTObserve);
        bw.newLine();
        String wTPriority = env.getProperty("tinylog.writingthread.priority");
        bw.write("writingthread.priority = " + wTPriority);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        bw.close();
    }
    Configurator.fromFile(f).activate();
}

From source file:at.orz.arangodb.http.JsonSequenceEntity.java

public void writeTo(OutputStream outstream) throws IOException {

    if (outstream == null) {
        throw new IllegalArgumentException("Output stream may not be null");
    }//from   ww w . j  a v a  2s. c  o m

    BufferedWriter writer = null;
    try {
        writer = new BufferedWriter(new OutputStreamWriter(outstream, "UTF-8"));
        while (it.hasNext()) {
            Object value = it.next();
            gson.toJson(value, writer);
            writer.newLine();
        }
        writer.flush();
    } finally {
    }

}

From source file:fr.itinerennes.bundler.tasks.framework.AbstractCountedCsvTask.java

@PostExec
public void prependLineCount() throws IOException {

    LOGGER.debug("Inserting line count at file head: {}", lineCount);

    final File output = getOutputFile();
    final File source = File.createTempFile("itr-", output.getName(), output.getParentFile());
    source.delete();//from  w  w  w. j  ava 2  s.  c  o m
    FileUtils.moveFile(output, source);

    InputStream from = null;
    BufferedWriter to = null;
    try {
        from = new FileInputStream(source);
        to = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(output), CHARSET));
        to.write(String.valueOf(lineCount));
        to.newLine();
        final LineIterator i = IOUtils.lineIterator(from, CHARSET.name());
        while (i.hasNext()) {
            to.write(i.next());
            to.newLine();
        }
    } finally {
        IOUtils.closeQuietly(from);
        IOUtils.closeQuietly(to);
        FileUtils.deleteQuietly(source);
    }
}

From source file:org.apache.falcon.rerun.queue.InMemoryQueue.java

private void beforeRetry(T event) {
    File retryFile = getRetryFile(serializeFilePath, event);
    BufferedWriter out = null;
    try {/*from  w  w w  . ja v  a2s  .c  om*/
        out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(retryFile, true)));
        out.write(event.toString());
        out.newLine();
        out.close();
    } catch (IOException e) {
        LOG.warn("Unable to write entry for process-instance: {}:{}", event.getEntityName(),
                event.getInstance(), e);
    } finally {
        IOUtils.closeQuietly(out);
    }
}