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:edu.iu.daal_naive.NaiveUtil.java

static void generateTestPoints(int numOfDataPoints, int vectorSize, int nClasses, String localInputDir,
        FileSystem fs, Path dataDir) throws IOException, InterruptedException, ExecutionException {

    // Check data directory
    if (fs.exists(dataDir)) {
        fs.delete(dataDir, true);/*www .j a  va 2s.  c  o m*/
    }
    // Check local directory
    File localDir = new File(localInputDir);
    // If existed, regenerate data
    if (localDir.exists() && localDir.isDirectory()) {
        for (File file : localDir.listFiles()) {
            file.delete();
        }
        localDir.delete();

    }
    boolean success = localDir.mkdir();
    if (success) {
        System.out.println("Directory: " + localInputDir + " created");
    }

    // generate test points
    BufferedWriter writer = new BufferedWriter(new FileWriter(localInputDir + File.separator + "testdata"));
    Random random = new Random();

    double point = 0;
    int label = 0;
    for (int i = 0; i < numOfDataPoints; i++) {
        for (int j = 0; j < vectorSize; j++) {
            point = random.nextDouble() * 2 - 1;
            writer.write(String.valueOf(point));
            writer.write(",");
        }

        label = random.nextInt(nClasses);
        writer.write(String.valueOf(label));
        writer.newLine();
    }

    writer.close();
    System.out.println("Write test data file");

    // Wrap to path object
    Path localInput = new Path(localInputDir);
    fs.copyFromLocalFile(localInput, dataDir);

}

From source file:edu.iu.daal_naive.NaiveUtil.java

static void generateGroundTruth(int numOfDataPoints, int nClasses, String localInputDir, FileSystem fs,
        Path dataDir) throws IOException, InterruptedException, ExecutionException {

    // Check data directory
    if (fs.exists(dataDir)) {
        fs.delete(dataDir, true);//from w  w w . j a  va2s .  co  m
    }
    // Check local directory
    File localDir = new File(localInputDir);
    // If existed, regenerate data
    if (localDir.exists() && localDir.isDirectory()) {
        for (File file : localDir.listFiles()) {
            file.delete();
        }
        localDir.delete();

    }
    boolean success = localDir.mkdir();
    if (success) {
        System.out.println("Directory: " + localInputDir + " created");
    }

    // generate test points
    BufferedWriter writer = new BufferedWriter(new FileWriter(localInputDir + File.separator + "groundtruth"));
    Random random = new Random();

    // double point = 0;
    int label = 0;
    for (int i = 0; i < numOfDataPoints; i++) {
        // for (int j = 0; j < vectorSize; j++) {
        //    point = random.nextDouble()*2 -1;
        //    writer.write(String.valueOf(point));
        //    writer.write(",");
        // }
        label = random.nextInt(nClasses);
        writer.write(String.valueOf(label));
        writer.newLine();
    }

    writer.close();
    System.out.println("Write groundtruth data file");

    // Wrap to path object
    Path localInput = new Path(localInputDir);
    fs.copyFromLocalFile(localInput, dataDir);

}

From source file:gamlss.utilities.MatrixFunctions.java

/**
 * Write matrix values to CSV file.//from www . j  ava  2 s  .c o  m
 * @param cmd - path to the file
 * @param m - matrix to write
 */
public static void matrixWriteCSV(final String cmd, final BlockRealMatrix m) {
    try {
        // Create file 
        FileWriter fstream = new FileWriter(cmd, false);
        BufferedWriter out = new BufferedWriter(fstream);

        for (int i = 0; i < m.getRowDimension(); i++) {
            for (int j = 0; j < m.getColumnDimension(); j++) {
                out.write(Double.toString(m.getEntry(i, j)));
                if (j < m.getColumnDimension() - 1) {
                    out.append(',');
                }
            }
            out.newLine();
        }
        out.close();
    } catch (Exception e) { //Catch exception if any
        System.err.println("Error: " + e.getMessage());
    }
}

From source file:com.ing.connector.util.WStringUtil.java

public static void appendFile(String source, String filetoappend) {

    try {//  w w w  .ja  v  a  2s . c  o  m
        boolean append = true;
        File filesrc = new File(source);
        BufferedWriter output = new BufferedWriter(new FileWriter(filesrc, append));

        File ftoappend = new File(filetoappend);
        BufferedReader br = new BufferedReader(new FileReader(ftoappend));
        String line = br.readLine();

        while (line != null) {
            output.write(line);
            output.newLine();
            line = br.readLine();
        }
        output.close();
        br.close();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:funcoes.funcoes.java

public static void geraLog(String nome, String log) {

    int dia, mes, ano;
    String data_log;/* ww w.  java2  s. c o m*/
    Calendar data;
    data = Calendar.getInstance();
    dia = data.get(Calendar.DAY_OF_MONTH);
    mes = data.get(Calendar.MONTH);
    ano = data.get(Calendar.YEAR);
    data_log = +dia + "_" + (mes + 1) + "_" + ano;
    if (dia < 10 && mes < 10) {
        data_log = "0" + dia + "_0" + (mes + 1) + "_" + ano;
    } else if (dia < 10 && mes >= 10) {
        data_log = "0" + dia + "_" + (mes + 1) + "_" + ano;
    } else if (dia >= 10 && mes < 10) {
        data_log = dia + "_0" + (mes + 1) + "_" + ano;
    } else {
        data_log = dia + "_" + (mes + 1) + "_" + ano;
    }

    File arquivo = new File("C:/SOVIONG/log/log_" + data_log + ".txt");

    try {
        if (!arquivo.exists()) {
            //cria um arquivo (vazio)
            arquivo.createNewFile();
        }

        //caso seja um diretrio,  possvel listar seus arquivos e diretrios
        //File[] arquivos = arquivo.listFiles();
        //escreve no arquivo
        FileWriter fw = new FileWriter(arquivo, true);
        BufferedWriter bw = new BufferedWriter(fw);
        bw.write(log + " "
                + data.getTime().toLocaleString().substring(10, data.getTime().toLocaleString().length())
                + " do dia: " + data.getTime().toLocaleString().substring(0, 10));
        bw.newLine();
        bw.close();
        fw.close();

    } catch (IOException ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage());
    }

}

From source file:org.silverpeas.dbbuilder.DBBuilder.java

private static DBXmlDocument loadMasterContribution(File dirXml) throws IOException, AppBuilderException {
    DBXmlDocument destXml = new DBXmlDocument(dirXml, MASTER_DBCONTRIBUTION_FILE);
    destXml.setOutputEncoding(CharEncoding.UTF_8);
    if (!destXml.getPath().exists()) {
        destXml.getPath().createNewFile();
        BufferedWriter destXmlOut = new BufferedWriter(
                new OutputStreamWriter(new FileOutputStream(destXml.getPath(), false), Charsets.UTF_8));
        try {// ww w .ja va 2  s  .  co  m
            destXmlOut.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
            destXmlOut.newLine();
            destXmlOut.write("<allcontributions>");
            destXmlOut.newLine();
            destXmlOut.write("</allcontributions>");
            destXmlOut.newLine();
            destXmlOut.flush();
        } finally {
            IOUtils.closeQuietly(destXmlOut);
        }
    }
    destXml.load();
    return destXml;
}

From source file:com.github.seqware.queryengine.system.exporters.JSONDumper.java

/**
 * <p>dumpVCFFromFeatureSetID.</p>
 *
 * @param fSet a {@link com.github.seqware.queryengine.model.FeatureSet} object.
 * @param file a {@link java.lang.String} object.
 *///from  w  ww. j ava 2  s  .co m
public static void dumpVCFFromFeatureSetID(FeatureSet fSet, String file) {
    BufferedWriter outputStream = null;

    try {
        if (file != null) {
            outputStream = new BufferedWriter(new FileWriter(file));
        } else {
            outputStream = new BufferedWriter(new OutputStreamWriter(System.out));
        }
    } catch (IOException e) {
        Logger.getLogger(JSONDumper.class.getName()).fatal("Exception thrown starting export to file:", e);
        System.exit(-1);
    }

    // fall-through if plugin-fails
    try {
        for (Feature feature : fSet) {
            StringBuilder buffer = new StringBuilder();
            boolean caught = outputFeatureInVCF(buffer, feature, fSet);
            outputStream.append(buffer);
            outputStream.newLine();
        }
        outputStream.flush();
    } catch (IOException e) {
        Logger.getLogger(JSONDumper.class.getName()).fatal("Exception thrown exporting to file:", e);
        System.exit(-1);
    } finally {
        IOUtils.closeQuietly(outputStream);
    }
}

From source file:com.tencent.wetest.common.util.ReportUtil.java

@SuppressLint("SimpleDateFormat")
public static synchronized String saveReport() {

    try {//  w w w.j  a  v a2 s.  c  om

        path = WTApplication.getContext().getFilesDir().getPath();
        String versionName = ((WTApplication) WTApplication.getContext()).getApkinfo().getVersionName();

        packageName = ((WTApplication) WTApplication.getContext()).getApkinfo().getPackagename();
        appName = ((WTApplication) WTApplication.getContext()).getApkinfo().getAppname();
        ;
        datasource = ((WTApplication) WTApplication.getContext()).getReport();

        if (datasource != null)
            datas = datasource.getDatalist();

        size = datas.size();

        Date now = new Date();

        long timeStart = -1;
        long timeEnd = -1;
        boolean hasBaseTime = false;

        if (datasource.getBaseTime() == -1) {

            hasBaseTime = false;

            timeEnd = (new Date()).getTime();

            if (timeEnd == -1) {

                timeEnd = now.getTime();

                timeStart = (timeEnd - (SystemClock.uptimeMillis() - datasource.getBaseColock()))
                        + (datasource.getTimeStart() - datasource.getBaseColock());

            } else {

                timeStart = (timeEnd - (SystemClock.uptimeMillis() - datasource.getBaseColock()))
                        + (datasource.getTimeStart() - datasource.getBaseColock());

                ((WTApplication) WTApplication.getContext()).getReport().setBaseTime(timeEnd);
                ((WTApplication) WTApplication.getContext()).getReport()
                        .setBaseColock(SystemClock.uptimeMillis());

            }

        } else {

            hasBaseTime = true;

            timeStart = datasource.getBaseTime() + datasource.getTimeStart() - datasource.getBaseColock();

            timeEnd = datasource.getBaseTime() + SystemClock.uptimeMillis() - datasource.getBaseColock();

        }

        File f;
        File indexfile = new File(path + "/wtIndex");

        if (((WTApplication) WTApplication.getContext()).getCurrTestFile() == null) {

            name = "wt" + now.getTime();

            String fileDir = Environment.getExternalStorageDirectory().getAbsolutePath() + "/wetest";
            ToolUtil.createDir(fileDir);

            f = new File(fileDir + "/" + name);
            ((WTApplication) WTApplication.getContext()).setCurrTestFile(f);

        } else {
            f = ((WTApplication) WTApplication.getContext()).getCurrTestFile();
            name = f.getName();

        }

        DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        String isRoot = ((WTApplication) WTApplication.getContext()).isRoot() ? "1" : "0";

        String content_index = name + "/" + formatter.format(timeEnd) + "/" + appName.replaceFirst("\\s+", "")
                + "/" + packageName + "/" + (timeEnd - timeStart) / 1000 + "/" + timeStart + "/" + timeEnd + "/"
                + versionName + "/" + isRoot + "/" + "";

        ((WTApplication) WTApplication.getContext()).getTestReports().add(name);

        if (!f.exists()) {
            f.createNewFile();
        }

        if (!indexfile.exists())
            indexfile.createNewFile();

        JsonResult json_res = readFileReport(f);

        JSONObject cpu = new JSONObject();

        JSONObject natived = new JSONObject();
        JSONObject dalvik = new JSONObject();
        JSONObject total = new JSONObject();

        JSONObject networkIn = new JSONObject();
        JSONObject networkOut = new JSONObject();

        JSONObject fps = new JSONObject();

        JSONObject time = new JSONObject();

        JSONObject tag = new JSONObject();

        JSONObject temperature = new JSONObject();

        JSONObject current = new JSONObject();

        for (ReportData data : datas) {

            if (!hasBaseTime) {

                long gap = data.getTime() - datasource.getTimeStart();

                long offset = gap > 0 ? gap : 0;

                json_res.getContent_f_time().put((timeStart + offset) / 1000);

                //Logger.debug("dataTime is " + formatter.format(timeStart + offset));

            } else {

                json_res.getContent_f_time().put((data.getTime()) / 1000);

                //Logger.debug("dataTime is " + formatter.format(data.getTime()));

            }

            json_res.getContent_f_cpu().put(data.getCpu());

            json_res.getContent_f_native().put(data.getpNative());
            json_res.getContent_f_dalvik().put(data.getpDalvik());
            json_res.getContent_f_total().put(data.getpTotal());

            json_res.getContent_f_networkIn().put(data.getpNetworUsagekIn());
            json_res.getContent_f_networkOut().put(data.getpNetworUsagekOut());
            json_res.getContent_f_Fps().put(data.getFps());

            json_res.getContent_f_Tag().put(data.getTag());

            json_res.getContent_f_temperature().put(data.getpTemperature());

            json_res.getContent_f_current().put(data.getpCurrent());

        }

        cpu.put("cpu", json_res.getContent_f_cpu());

        natived.put("native", json_res.getContent_f_native());
        dalvik.put("dalvik", json_res.getContent_f_dalvik());
        total.put("total", json_res.getContent_f_total());

        networkIn.put("networkIn", json_res.getContent_f_networkIn());
        networkOut.put("networkOut", json_res.getContent_f_networkOut());
        time.put("time", json_res.getContent_f_time());

        fps.put("fps", json_res.getContent_f_Fps());
        tag.put("tag", json_res.getContent_f_Tag());

        temperature.put("temperature", json_res.getContent_f_temperature());
        current.put("current", json_res.getContent_f_current());

        BufferedWriter writer = new BufferedWriter(new FileWriter(f, false));

        writer.append(cpu.toString());
        writer.newLine();

        writer.append(natived.toString());
        writer.newLine();

        writer.append(dalvik.toString());
        writer.newLine();

        writer.append(total.toString());
        writer.newLine();

        writer.append(networkIn.toString());
        writer.newLine();

        writer.append(networkOut.toString());
        writer.newLine();

        writer.append(time.toString());
        writer.newLine();

        writer.append(fps.toString());
        writer.newLine();

        writer.append(tag.toString());

        writer.flush();
        writer.close();

        updateRecord(indexfile, name, content_index);

    } catch (Exception e) {
        Logger.error("report save exception :" + e.toString());
        e.printStackTrace();
    }

    return name;

}

From source file:de.uni_luebeck.inb.knowarc.usecases.invocation.local.LocalUseCaseInvocation.java

public static void persist(File directory) {
    File invocationsFile = new File(directory, LOCAL_INVOCATION_FILE);
    BufferedWriter writer = null;
    try {/*from   w ww.ja  va2s.c o  m*/
        writer = new BufferedWriter(new FileWriter(invocationsFile));
        for (String runId : runIdToTempDir.keySet()) {
            for (String tempDir : runIdToTempDir.get(runId)) {
                writer.write(runId);
                writer.write(" ");
                writer.write(tempDir);
                writer.newLine();
            }
        }
    } catch (IOException e) {
        logger.error(e);
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (IOException e) {
                logger.error(e);
            }
        }
    }
}

From source file:emperior.Main.java

public static void addLineToLogFile(String input) {
    if (!adminmode) {
        FileWriter fstream;/*from ww w  .j a va  2 s.c  o  m*/
        try {
            fstream = new FileWriter(logFile, true);
            BufferedWriter out = new BufferedWriter(fstream);
            out.write(getCurrentTime() + " {" + applicant + " | " + group + "}" + "<"
                    + Main.tasktypes.get(Main.activeType) + "_" + Main.tasks.get(Main.activeTask) + "> "
                    + input);
            out.newLine();
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}