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:mase.MaseEvolve.java

public static File writeConfig(String[] args, Map<String, String> params, File outDir,
        boolean replaceDirWildcard) throws IOException {
    File configFile = File.createTempFile("maseconfig", ".params");

    // Write the parameter map into a new file
    BufferedWriter bw = new BufferedWriter(new FileWriter(configFile));

    // Write the command line arguments in a comment
    bw.write("#");
    for (String arg : args) {
        bw.write(" " + arg);
    }//from   w  ww . j a va  2s.c o m
    bw.newLine();

    // Write the parameters correctly padded
    int maxLen = -1;
    for (String str : params.keySet()) {
        maxLen = Math.max(maxLen, str.length());
    }

    for (Entry<String, String> e : params.entrySet()) {
        String value = e.getValue();
        if (value.contains("$") && replaceDirWildcard) {
            File f = new File(outDir, value.replace("$", ""));
            value = f.getAbsolutePath().replace("\\", "/");
        }
        bw.write(StringUtils.rightPad(e.getKey(), maxLen) + " = " + value);
        bw.newLine();
    }
    bw.close();

    return configFile;
}

From source file:ch.ethz.matsim.ivt_baseline.counts.StreetCountsLinkIdentification.java

private static void writeStreetCounts(String pathToCountsOutput, Map<CountInput, Id<Link>> identifiedLinks) {
    BufferedWriter writer = IOUtils.getBufferedWriter(pathToCountsOutput, Charset.forName("UTF-8"));
    try {/*from   w w  w  .  j ava 2 s  . c  o m*/
        String header = "countStationId" + COUNTS_DELIMITER + "direction" + COUNTS_DELIMITER + "linkId";
        writer.write(header);
        writer.newLine();
        //for (Id<Link> linkId : identifiedLinks.keySet()) {
        for (CountInput countInput : identifiedLinks.keySet()) {
            writer.write(countInput.id + COUNTS_DELIMITER);
            writer.write(countInput.directionDescr + COUNTS_DELIMITER);
            writer.write(identifiedLinks.get(countInput).toString());
            writer.newLine();
        }
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:edgeserver.Publicador.java

private static void armazenaFila(ArrayList filaPublicacoes) throws IOException {
    new PrintWriter("fila.txt").close();
    filaPublicacoes.stream().forEach((publicacao) -> {
        BufferedWriter bw = null;
        try {/*from   w w w  .  ja v  a 2  s . com*/
            // APPEND MODE SET HERE
            bw = new BufferedWriter(new FileWriter("fila.txt", true));
            bw.write(publicacao.toString());
            bw.newLine();
            bw.flush();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        } finally { // always close the file
            if (bw != null)
                try {
                    bw.close();
                } catch (IOException ioe2) {
                    // just ignore it
                }
        }
    });

}

From source file:com.packtpub.mahout.cookbook.chapter01.App.java

private static void CreateCsvRatingsFile() throws FileNotFoundException, IOException {

    BufferedReader br = new BufferedReader(new FileReader(inputFile));
    BufferedWriter bw = new BufferedWriter(new FileWriter(outputFile));

    String line = null;/*  w  w w . j  a  v a2s  .c o  m*/
    String line2write = null;
    String[] temp;

    int i = 0;
    while ((line = br.readLine()) != null && i < 1000) {
        i++;
        temp = line.split("::");
        line2write = temp[0] + "," + temp[1];
        bw.write(line2write);
        bw.newLine();
        bw.flush();

    }
    br.close();
    bw.close();
}

From source file:ProxyAuthTest.java

private static void generateData() throws Exception {
    String fileData[] = { "1|aaa", "2|bbb", "3|ccc", "4|ddd", "5|eee", };

    File tmpFile = File.createTempFile(tabName, ".data");
    tmpFile.deleteOnExit();//from w w w .  ja  v a 2 s  . co m
    tabDataFileName = tmpFile.getPath();
    FileWriter fstream = new FileWriter(tabDataFileName);
    BufferedWriter out = new BufferedWriter(fstream);
    for (String line : fileData) {
        out.write(line);
        out.newLine();
    }
    out.close();
    tmpFile.setWritable(true, true);
}

From source file:com.netflix.config.DynamicFileConfigurationTest.java

static void modifyConfigFile() {
    new Thread() {
        public void run() {
            try {
                BufferedWriter writer = new BufferedWriter(
                        new OutputStreamWriter(new FileOutputStream(configFile), "UTF-8"));
                writer.write("abc=-2"); // this property should fail validation but should not affect update of other properties
                writer.newLine();
                writer.write("dprops1=" + String.valueOf(Long.MIN_VALUE));
                writer.newLine();/*from  w  ww . j  av a  2  s.c  om*/
                writer.write("dprops2=" + String.valueOf(Double.MAX_VALUE));
                writer.newLine();
                writer.close();
                System.err.println(configFile.getPath() + " modified");
            } catch (Exception e) {
                e.printStackTrace();
                fail("Unexpected exception");
            }
        }
    }.start();
}

From source file:edu.iu.kmeans.regroupallgather.KMUtil.java

/**
 * Generate centroids and upload to the cDir
 * /*from   w  w  w. j  a  v a2 s  .  c o m*/
 * @param numCentroids
 * @param vectorSize
 * @param configuration
 * @param random
 * @param cenDir
 * @param fs
 * @throws IOException
 */
static void generateCentroids(int numCentroids, int vectorSize, Configuration configuration, Path cenDir,
        FileSystem fs) throws IOException {
    Random random = new Random();
    double[] data = null;
    if (fs.exists(cenDir))
        fs.delete(cenDir, true);
    if (!fs.mkdirs(cenDir)) {
        throw new IOException("Mkdirs failed to create " + cenDir.toString());
    }
    data = new double[numCentroids * vectorSize];
    for (int i = 0; i < data.length; i++) {
        // data[i] = 1000;
        data[i] = random.nextDouble() * 1000;
    }
    Path initClustersFile = new Path(cenDir, Constants.CENTROID_FILE_NAME);
    System.out.println("Generate centroid data." + initClustersFile.toString());
    FSDataOutputStream out = fs.create(initClustersFile, true);
    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out));
    for (int i = 0; i < data.length; i++) {
        if ((i % vectorSize) == (vectorSize - 1)) {
            bw.write(data[i] + "");
            bw.newLine();
        } else {
            bw.write(data[i] + " ");
        }
    }
    bw.flush();
    bw.close();
    System.out.println("Wrote centroids data to file");
}

From source file:css.variable.converter.CSSVariableConverter.java

/**
 * Go through existing CSS Files and replace variable access with variable
 * values//from  w  w  w. j av a 2 s . c om
 *
 * @param rootCSSVars All css variables you want to convert from name to value
 */
private static void editForRelease(ArrayList<CSSVar> rootCSSVars) {
    for (File cssFile : theCSSList) {

        ArrayList<CSSVar> localCSSVars = getCSSVars(cssFile, ":local");
        for (CSSVar cssVar : rootCSSVars) {
            if (!localCSSVars.contains(cssVar)) {
                localCSSVars.add((CSSVar) (cssVar.clone()));
            }
        }

        // This will store info the new text for the file we will write below
        ArrayList<String> filesNewInfo = new ArrayList<String>();
        try {

            Scanner fileReader = new Scanner(cssFile);
            while (fileReader.hasNextLine()) {

                String currentLine = fileReader.nextLine();

                // If we find variables, replace them, with their value
                if (currentLine.contains("var(")) {
                    for (CSSVar var : localCSSVars) {
                        while (currentLine.contains(var.getName())) {
                            currentLine = currentLine.replace("var(" + var.getName() + ")", var.getValue());
                        }
                    }
                }
                // Add new currentLine to be written
                filesNewInfo.add(currentLine);
            }
            fileReader.close();
        } catch (FileNotFoundException ex) {
            Logger.getLogger(CSSVariableConverter.class.getName()).log(Level.SEVERE, null, ex);
        }

        // Write the new files below
        try {
            BufferedWriter writer = new BufferedWriter(new FileWriter(cssFile.getPath()));

            while (!filesNewInfo.isEmpty()) {
                writer.write(filesNewInfo.get(0));
                writer.newLine();
                filesNewInfo.remove(0);
            }
            writer.close();
        } catch (IOException ex) {
            Logger.getLogger(CSSVariableConverter.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:com.vmware.identity.interop.PlatformUtils.java

private static boolean renameFileOnWindows(File oldFile, File newFile) {
    String sCurrentLine = "";

    try {//  ww  w . j  a  v a  2 s  .c o  m
        BufferedReader bufReader = new BufferedReader(new FileReader(oldFile.getAbsoluteFile()));
        BufferedWriter bufWriter = new BufferedWriter(new FileWriter(newFile.getAbsoluteFile()));

        while ((sCurrentLine = bufReader.readLine()) != null) {
            bufWriter.write(sCurrentLine);
            bufWriter.newLine();
        }
        bufReader.close();
        bufWriter.close();
        oldFile.delete();

        return true;
    } catch (Exception e) {
        return false;
    }
}

From source file:jeplus.INSELWinTools.java

/**
 * Call INSEL executable file to run the simulation
 * @param config INSEL Configuration/* w w w  .  j  av  a2 s .  com*/
 * @param WorkDir The working directory where the input files are stored and the output files to be generated
 * @param useReadVars Whether or not to use readvars after simulation
 * @return the result code represents the state of execution steps. >=0 means successful
 */
public static int runINSEL(INSELConfig config, String WorkDir, String modelfile) {

    int ExitValue = -99;

    try {
        // Trace simulation time
        Date start = new Date();

        // Run EnergyPlus executable
        String CmdLine = config.getResolvedInselEXEC() + " " + modelfile;
        Process EPProc = Runtime.getRuntime().exec(CmdLine, null, new File(WorkDir));

        BufferedReader ins = new BufferedReader(new InputStreamReader(EPProc.getInputStream()));
        // Use console output as the report file
        BufferedWriter outs = new BufferedWriter(new FileWriter(WorkDir + config.ScreenFile, false));
        outs.newLine();
        outs.write("Calling insel.exe - " + (new SimpleDateFormat()).format(start));
        outs.newLine();
        outs.write("Command line: " + WorkDir + ">" + CmdLine);
        outs.newLine();

        int res = ins.read();
        while (res != -1) {
            outs.write(res);
            res = ins.read();
        }
        ins.close();
        outs.newLine();
        outs.write("Simulation time: " + Long.toString((new Date().getTime() - start.getTime()) / 1000)
                + " seconds");
        outs.flush();
        outs.close();

        EPProc.waitFor();
        ExitValue = EPProc.exitValue();
    } catch (IOException | InterruptedException e) {
        logger.error("Exception during INSEL execution.", e);
    }

    // Return Radiance exit value
    return ExitValue;
}