Example usage for java.io BufferedWriter BufferedWriter

List of usage examples for java.io BufferedWriter BufferedWriter

Introduction

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

Prototype

public BufferedWriter(Writer out) 

Source Link

Document

Creates a buffered character-output stream that uses a default-sized output buffer.

Usage

From source file:com.evidon.areweprivateyet.Crawler.java

private void recordLog(String name) throws IOException {
    BufferedWriter out = new BufferedWriter(new FileWriter(path + "crawl-" + name + ".log"));
    out.write(out.toString());//from   www .  j ava  2 s  . co  m
    out.close();
}

From source file:ir.pooyahfp.matrixcli.ProgramTest.java

@Test
public void testLoadCommandFile() throws Exception {
    String path = "test.txt";
    BufferedWriter writer = new BufferedWriter(new FileWriter(new File(path)));
    writer.write("matrix x 3 3");
    writer.newLine();//ww  w . ja  v  a  2 s .c  o m
    writer.write("show x");
    writer.flush();
    writer.close();

    program.loadCommandFile(path);
}

From source file:com.kappaware.logtrawler.output.flow.FileJsonOutputFlow.java

public FileJsonOutputFlow(String fileName, boolean outputArray) throws IOException {
    super(outputArray);
    out = new PrintWriter(new BufferedWriter(new FileWriter(fileName, true)));
    log.info(String.format("Json events will be stored in to '%s'", fileName));
}

From source file:matrix.CreateUserList.java

public void tweetsToUserList()
        throws FileNotFoundException, UnsupportedEncodingException, IOException, ParseException {

    File fout = new File(userListPathOutput);
    FileOutputStream fos = new FileOutputStream(fout);
    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));

    BufferedReader inputTW = new BufferedReader(
            new InputStreamReader(new FileInputStream(tweetsJsonInput), "ISO-8859-9"));
    ArrayList userList = new ArrayList();
    JSONParser jsonParser = new JSONParser();
    JSONArray jsonArray = (JSONArray) jsonParser.parse(inputTW);
    int sayac = 0;
    for (Object obj : jsonArray) {

        JSONObject tweet = (JSONObject) obj;
        JSONObject user = (JSONObject) tweet.get("user");
        //            String userID = user.get("id").toString();
        //            String userName = user.get("name").toString();
        String userID = user.get("id").toString();
        String userName = user.get("name").toString();

        if (userList.contains(userID) == false) {
            userList.add(userID);//from  w  w w.ja v a2  s. c  o m
            bw.write(userID + "," + userName);
            bw.newLine();
            sayac++;
        }

    }
    System.out.println(sayac);
}

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();/*from  w w w . j a v  a2 s  . c om*/
                writer.write("dprops1=" + String.valueOf(Long.MIN_VALUE));
                writer.newLine();
                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:com.alibaba.otter.shared.common.utils.cmd.StreamAppender.java

public StreamAppender(OutputStream output) {
    this.output = new PrintWriter(new BufferedWriter(new OutputStreamWriter(output)));
}

From source file:coolmap.application.io.internal.cmatrix.DefaultCMatrixExporter.java

@Override
public void dumpData(CMatrix matrix, TFile zipFolder) throws Exception {
    TFile outputFile = new TFile(zipFolder.getAbsolutePath() + File.separator + IOTerm.FILE_DATA);
    TFile propertyFile = new TFile(zipFolder.getAbsolutePath() + File.separator + IOTerm.FILE_PROPERTY);

    BufferedWriter propertyWriter = new BufferedWriter(
            new OutputStreamWriter(new TFileOutputStream(propertyFile)));

    JSONObject cmatrixPropertyEntry = new JSONObject();
    cmatrixPropertyEntry.put(IOTerm.ATTR_ID, matrix.getID());
    cmatrixPropertyEntry.put(IOTerm.ATTR_NAME, matrix.getName());
    cmatrixPropertyEntry.put(IOTerm.ATTR_CMATRIX_NUMROW, matrix.getNumRows());
    cmatrixPropertyEntry.put(IOTerm.ATTR_CMATRIX_NUMCOLUMN, matrix.getNumColumns());
    cmatrixPropertyEntry.put(IOTerm.ATTR_CLASS, matrix.getClass().getName());
    cmatrixPropertyEntry.put(IOTerm.ATTR_CMATRIX_MEMBERCLASS, matrix.getMemberClass().getName());

    //        System.out.println(cmatrixPropertyEntry);

    propertyWriter.write(cmatrixPropertyEntry.toString());

    propertyWriter.flush();//  w  ww .java2s  .  co m
    propertyWriter.close();

    BufferedWriter dataWriter = new BufferedWriter(new OutputStreamWriter(new TFileOutputStream(outputFile)));

    //        dataWriter.write("This is where cmatrix will be dumped");
    //        part of the following code can be extracted for other use
    //        dataWriter properties
    dataWriter.write("Row/Column");
    for (int i = 0; i < matrix.getNumColumns(); i++) {
        dataWriter.write("\t");
        String colLabelString = matrix.getColLabel(i);
        if (colLabelString == null)
            colLabelString = "";
        dataWriter.write(colLabelString);
    }
    dataWriter.write("\n");

    for (int i = 0; i < matrix.getNumRows(); i++) {

        String rowLabelString = matrix.getRowLabel(i);
        if (rowLabelString == null)
            rowLabelString = "";
        dataWriter.write(rowLabelString);

        for (int j = 0; j < matrix.getNumColumns(); j++) {
            dataWriter.write("\t");
            Object value = matrix.getValue(i, j);

            if (value != null) {
                dataWriter.write(value.toString());
            }
        }
        dataWriter.write("\n");

    }

    dataWriter.flush();
    dataWriter.close();

    //        System.out.println("Dumping successful");
}

From source file:mrdshinse.md2html.util.FileUtil.java

/**
 * Create file by String./* w w  w. ja v a 2s  .  c o  m*/
 *
 * @param file File class for output file.
 * @param str file content
 * @return Processed file
 */
public static File create(File file, String str) {

    try (PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file)))) {
        pw.print(str);
    } catch (IOException ex) {
        LOG.error(ex);
        return file;
    }
    return file;
}

From source file:eu.planets_project.tb.utils.ExperimentUtils.java

/**
 * //  w w w .  java 2s .co  m
 * @param os
 * @param expId
 * @throws IOException 
 */
public static void outputResults(OutputStream os, String expId, DATA_FORMAT format) throws IOException {
    log.info("Writing out experiment " + expId + " as " + format);

    Writer out = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
    CSVWriter writer = new CSVWriter(out);

    long id = Long.parseLong(expId);

    ExperimentPersistencyRemote edao = ExperimentPersistencyImpl.getInstance();
    Experiment exp = edao.findExperiment(id);

    // The string array 
    String sa[] = new String[8];
    sa[0] = "Name";
    sa[1] = "Run #";
    sa[2] = "Date";
    sa[3] = "Digital Object #";
    sa[4] = "Digital Object Source";
    sa[5] = "Stage";
    sa[6] = "Property Identifier";
    sa[7] = "Property Value";
    // write the headers out:
    writer.writeNext(sa);

    // Loop through:
    int bi = 1;
    for (BatchExecutionRecordImpl batch : exp.getExperimentExecutable().getBatchExecutionRecords()) {
        // log.info("Found batch... "+batch);
        int doi = 1;
        for (ExecutionRecordImpl exr : batch.getRuns()) {
            // log.info("Found Record... "+exr+" stages: "+exr.getStages());
            if (exr != null && exr.getStages() != null) {
                for (ExecutionStageRecordImpl exsr : exr.getStages()) {
                    // log.info("Found Stage... "+exsr);
                    for (MeasurementImpl m : exsr.getMeasurements()) {
                        // log.info("Looking at result for property "+m.getIdentifier());
                        sa[0] = exp.getExperimentSetup().getBasicProperties().getExperimentName();
                        sa[1] = "" + bi;
                        sa[2] = batch.getStartDate().getTime().toString();
                        sa[3] = "" + doi;
                        sa[4] = exr.getDigitalObjectSource();
                        sa[5] = exsr.getStage();
                        sa[6] = m.getIdentifier();
                        sa[7] = m.getValue();
                        // Write out CSV:
                        writer.writeNext(sa);
                    }
                }
            }
            // Increment, for the next DO.
            doi++;
            out.flush();
        }
        // Increment to the next batch:
        bi++;
    }

}

From source file:com.kappaware.logtrawler.output.flow.FileDataOutputFlow.java

public FileDataOutputFlow(String fileName) throws IOException {
    out = new PrintWriter(new BufferedWriter(new FileWriter(fileName, true)));
    log.info(String.format("Data events will be stored in to '%s'", fileName));
}