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:networkanalyzer.DynamicPing.java

public static void pingData(int ping) throws IOException {

    DynamicPing.series.addOrUpdate(new Second(), ping);

    if (NetworkAnalyzer.saveCheck.isSelected() && !NetworkAnalyzer.saveLoc.getText().isEmpty()) {
        long timeNowMsec = System.currentTimeMillis();
        Date timeNow = new Date(timeNowMsec);
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
        String time = sdf.format(timeNow);
        try (PrintWriter out = new PrintWriter(
                new BufferedWriter(new FileWriter(NetworkAnalyzer.saveLoc.getText() + ".txt", true)))) {
            out.println(time + " " + ping);
        }/*  w w w  . j  ava2s .c  o  m*/
    }

}

From source file:juicebox.tools.utils.juicer.apa.APAUtils.java

public static void saveListText(String filename, List<Double> array) {
    Writer writer = null;// www  .  ja  va2  s  . c  om
    try {
        writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename), "utf-8"));
        for (double val : array) {
            writer.write(val + " ");
        }
        writer.write("\n");
    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {
        try {
            if (writer != null)
                writer.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

From source file:bftsmart.tom.util.RSAKeyPairGenerator.java

private void saveToFile(int id, PublicKey puk, PrivateKey prk) throws Exception {
    String path = "config" + System.getProperty("file.separator") + "keys"
            + System.getProperty("file.separator");

    BufferedWriter w = new BufferedWriter(new FileWriter(path + "publickey" + id, false));
    w.write(getKeyAsString(puk));//from  www . j  a  v a  2  s  .  c o m
    w.flush();
    w.close();

    w = new BufferedWriter(new FileWriter(path + "privatekey" + id, false));
    w.write(getKeyAsString(prk));
    w.flush();
    w.close();
}

From source file:edu.harvard.med.screensaver.ui.arch.searchresults.CsvDataExporter.java

@Override
public InputStream export(Iterator<T> iter) throws IOException {
    assert _columns != null : "must call setTableColumns() first";
    CSVPrintWriter csvWriter = null;// www. java  2  s  .c  om
    try {
        File file = File.createTempFile("screensaver", "csv");
        Writer writer = new BufferedWriter(new FileWriter(file));
        csvWriter = new CSVPrintWriter(writer, "\n");
        writeFile(csvWriter, iter);
        csvWriter.close();
        return new BufferedInputStream(new FileInputStream(file));
    } catch (Exception e) {
        if (e instanceof IOException) {
            throw (IOException) e;
        }
        throw new DevelopmentException(e.getMessage());
    } finally {
        if (csvWriter != null) {
            IOUtils.closeQuietly(csvWriter);
        }
    }
}

From source file:com.yahoo.ycsb.db.RedisClient.java

public static String compressWithLog(String st) {
    // System.out.println("compress");
    // System.out.println(st.substring(0, 20));
    long start_time = System.nanoTime();
    String ret = compress(st);/* w ww  .j  a v  a2  s.c om*/
    try {
        long end_time = System.nanoTime();
        long time = end_time - start_time;
        BufferedWriter bw = new BufferedWriter(new FileWriter("compress_time.txt", true));
        bw.write("" + time);
        bw.newLine();
        bw.flush();
        BufferedWriter bw2 = new BufferedWriter(new FileWriter("compress_rate.txt", true));
        double r1 = ret.length();
        double r2 = st.length();
        double r = r1 / r2;
        bw2.write("" + r);
        bw2.newLine();
        bw2.flush();
    } catch (Exception e) {
    }
    // System.out.println("compressed");
    // System.out.println(ret.substring(0, 20));
    return ret;
}

From source file:fr.sanofi.fcl4transmart.controllers.listeners.clinicalData.SelectOtherIdentifiersListener.java

@Override
public void handleEvent(Event event) {
    //write in a new file
    File file = new File(this.dataType.getPath().toString() + File.separator
            + this.dataType.getStudy().toString() + ".columns.tmp");
    try {/*  w  w  w .j ava  2  s .  c  o  m*/
        FileWriter fw = new FileWriter(file);
        BufferedWriter out = new BufferedWriter(fw);
        out.write(
                "Filename\tCategory Code\tColumn Number\tData Label\tData Label Source\tControlled Vocab Code\n");

        //subject identifier
        Vector<File> rawFiles = ((ClinicalData) this.dataType).getRawFiles();
        Vector<String> siteIds = this.setOtherIdsUI.getSiteIds();
        Vector<String> visitNames = this.setOtherIdsUI.getVisitNames();
        for (int i = 0; i < rawFiles.size(); i++) {

            //site identifier
            if (siteIds.elementAt(i).compareTo("") != 0) {
                int columnNumber = FileHandler.getHeaderNumber(rawFiles.elementAt(i), siteIds.elementAt(i));
                if (columnNumber != -1) {
                    out.write(rawFiles.elementAt(i).getName() + "\t\t" + columnNumber + "\tSITE_ID\t\t\n");
                }
            }

            //visit name
            if (visitNames.elementAt(i).compareTo("") != 0) {
                int columnNumber = FileHandler.getHeaderNumber(rawFiles.elementAt(i), visitNames.elementAt(i));
                if (columnNumber != -1) {
                    out.write(rawFiles.elementAt(i).getName() + "\t\t" + columnNumber + "\tVISIT_NAME\t\t\n");
                }
            }
        }
        try {
            BufferedReader br = new BufferedReader(new FileReader(((ClinicalData) this.dataType).getCMF()));
            String line = br.readLine();
            while ((line = br.readLine()) != null) {
                String[] s = line.split("\t", -1);
                if (s[3].compareTo("SITE_ID") != 0 && s[3].compareTo("VISIT_NAME") != 0) {
                    out.write(line + "\n");
                }
            }
            br.close();
        } catch (Exception e) {
            this.setOtherIdsUI.displayMessage("Error: " + e.getLocalizedMessage());
            e.printStackTrace();
            out.close();
        }
        out.close();
        try {
            String fileName = ((ClinicalData) this.dataType).getCMF().getName();
            ((ClinicalData) this.dataType).getCMF().delete();
            File fileDest = new File(this.dataType.getPath() + File.separator + fileName);
            FileUtils.moveFile(file, fileDest);
            ((ClinicalData) this.dataType).setCMF(fileDest);
        } catch (IOException ioe) {
            this.setOtherIdsUI.displayMessage("File error: " + ioe.getLocalizedMessage());
            return;
        }

    } catch (Exception e) {
        this.setOtherIdsUI.displayMessage("Error: " + e.getLocalizedMessage());
        e.printStackTrace();
    }
    this.setOtherIdsUI.displayMessage("Column mapping file updated");
    WorkPart.updateSteps();
    WorkPart.updateFiles();
    UsedFilesPart.sendFilesChanged(dataType);
}

From source file:de.thischwa.pmcms.view.renderer.ExportRenderThread.java

@Override
public void run() {
    if (controller.isCanceled()) {
        this.interrupt();
        return;//w  w w . j  ava 2  s  .  c  om
    }

    File outputFile = PathTool.getExportFile(renderable, poExtension);
    Writer fileWriter = null;
    try {
        fileWriter = new BufferedWriter(new FileWriter(outputFile));
        velocityRenderer.render(fileWriter, renderable, ViewMode.EXPORT);
        fileWriter.flush();
    } catch (Exception e) {
        controller.interrupt(this, e);
    } finally {
        IOUtils.closeQuietly(fileWriter);
    }
    logger.debug("Rendered: ".concat(renderable.toString()));
}

From source file:org.lieuofs.extraction.commune.ExtractionGeTax.java

public void extraire() throws IOException {
    CommuneCritere critere = new CommuneCritere();
    Calendar cal = Calendar.getInstance();
    cal.set(2012, Calendar.JANUARY, 1);
    critere.setDateValiditeApres(cal.getTime());
    cal.set(2012, Calendar.DECEMBER, 31);
    critere.setDateValiditeAvant(cal.getTime());
    List<ICommuneSuisse> communes = gestionnaire.rechercher(critere);
    Collections.sort(communes, new Comparator<ICommuneSuisse>() {
        @Override/* w ww  .  ja v a2  s .  c om*/
        public int compare(ICommuneSuisse o1, ICommuneSuisse o2) {
            return o1.getNumeroOFS() - o2.getNumeroOFS();
        }
    });
    // Attention, le fichier est une iste historise des communes.
    // Une commune peut donc figurer 2 fois dans le fichier
    Set<Integer> numOFS = new HashSet<Integer>(3000);
    int nbreCommune = 0;
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
            new FileOutputStream(new File("ExtractionCommuneGETaX2012.csv")), Charset.forName("ISO8859-1")));

    for (ICommuneSuisse commune : communes) {
        if (!numOFS.contains(commune.getNumeroOFS())) {
            nbreCommune++;
            numOFS.add(commune.getNumeroOFS());
            writer.write(String.valueOf(commune.getNumeroOFS()));
            writer.write(";");
            writer.write(commune.getNomCourt());
            writer.write(";");
            writer.write(commune.getCanton().getCodeIso2());
            writer.newLine();
            System.out.println(commune.getNumeroOFS() + " " + commune.getNomCourt());
        }
    }
    writer.close();
    System.out.println("Nbre commune : " + nbreCommune);
}

From source file:FstDotWriter.java

public FstDotWriter(SymMap sm, File f, String sig, String encoding) {
    symmap = sm;//from w  ww .j  av a 2 s  . co m
    sigma = sig;
    this.encoding = encoding;

    // the File should be a full path to a file, constructed
    // appropriately on the calling side; the XML file is written there.

    try {
        out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f), encoding));
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.lieuofs.extraction.etatpays.ExtractionGeTaX.java

public void extraire() throws IOException {
    EtatCritere critere = new EtatCritere();
    Calendar cal = Calendar.getInstance();
    cal.set(2012, Calendar.DECEMBER, 31);
    critere.setReconnuSuisseALaDate(cal.getTime());
    Set<IEtat> etats = gestionnaire.rechercher(critere);
    List<IEtat> listeEtat = new ArrayList<IEtat>(etats);
    Collections.sort(listeEtat, new Comparator<IEtat>() {
        @Override//from  ww  w  . ja va 2 s .c om
        public int compare(IEtat o1, IEtat o2) {
            return o1.getNumeroOFS() - o2.getNumeroOFS();
        }
    });
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
            new FileOutputStream(new File("ExtractionEtatGETaX2012.csv")), Charset.forName("ISO8859-1")));

    for (IEtat etat : listeEtat) {
        writer.write(String.valueOf(etat.getNumeroOFS()));
        writer.write(";");
        writer.write(etat.getFormeCourte("fr"));
        writer.newLine();
    }
    writer.close();
}