Example usage for java.io BufferedWriter flush

List of usage examples for java.io BufferedWriter flush

Introduction

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

Prototype

public void flush() throws IOException 

Source Link

Document

Flushes the stream.

Usage

From source file:com.xafero.vee.cmd.MainApp.java

private static void printVersion() throws IOException {
    StringWriter writer;//  ww  w. j ava2  s .  c o m
    BufferedWriter out = new BufferedWriter(writer = new StringWriter());
    out.write(APP_SHORT_NAME + " " + APP_VER + " built on JSR 223.");
    out.newLine();
    out.newLine();
    out.write("Copyright (C) 2015 xafero");
    out.newLine();
    out.write("License AGPLv3+: GNU AGPL version 3 or later");
    out.newLine();
    out.write("<https://gnu.org/licenses/agpl.html>.");
    out.newLine();
    out.write("This is free software: you are free to change and redistribute it.");
    out.newLine();
    out.write("There is NO WARRANTY, to the extent permitted by law.");
    out.newLine();
    out.newLine();
    out.write("Please send bug reports and questions to <" + APP_SRC_URL + ">.");
    out.newLine();
    out.flush();
    System.out.print(writer.toString());
}

From source file:LVCoref.MMAX2.java

public static void exportWords(Document d, String filename) {
    BufferedWriter writer = null;
    try {//www  .  j a v  a  2 s  .com
        writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename), "UTF-8"));
    } catch (java.io.IOException ex) {
        ex.printStackTrace();
    }
    Utils.toWriter(writer, "<?xml version=\"1.0\" encoding=\"" + "UTF-8" + "\"?>\n"
            + "<!DOCTYPE words SYSTEM \"words.dtd\">\n" + "<words>\n");

    for (Node n : d.tree) {
        Utils.toWriter(writer,
                "<word id=\"word_" + (n.id + 1) + "\">" + StringEscapeUtils.escapeXml(n.word) + "</word>\n");
    }
    Utils.toWriter(writer, "</words>");
    try {
        writer.flush();
        writer.close();
    } catch (IOException ex) {
        Logger.getLogger(Document.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:net.openchrom.xxd.processor.supplier.rscripting.ui.code.RServe.java

/**
 * Evaluates and prints an expression to the Plugin console executed in a job.
 * /*  www .  j a v a  2  s . co  m*/
 * @param expression
 *            a R expression as a string.
 */
public static void printJob(String expression) {// helper class to print

    if (RState.isBusy() == false) {
        RState.setBusy(true);
        REvaluateJob job = new REvaluateJob(expression);
        job.addJobChangeListener(new JobChangeAdapter() {

            public void done(IJobChangeEvent event) {

                if (event.getResult().isOK()) {
                    int countDev = getDisplayNumber();
                    RState.setBusy(false);
                    if (countDev > 0) {
                        RServe.closeAndDisplay();
                    }
                    System.out.flush();
                } else {
                    RState.setBusy(false);
                    System.out.flush();
                }
            }
        });
        // job.setSystem(true);
        job.schedule();
    } else {
        Process p;
        IPreferenceStore store = Activator.getDefault().getPreferenceStore();
        if (store.getBoolean("RSERVE_NATIVE_START")) {
            ConsolePageParticipant consol = ConsolePageParticipant.getConsolePageParticipantInstance();
            p = consol.getRProcess();
        } else {
            p = RConnectionJob.getProc();
        }
        // Write to the output!
        if (p != null) {
            final OutputStream os = p.getOutputStream();
            final OutputStreamWriter osw = new OutputStreamWriter(os);
            final BufferedWriter bw = new BufferedWriter(osw, 100);
            try {
                bw.write(expression);
                bw.newLine();
                os.flush();
                bw.flush();
                // bw.close();
                System.out.flush();
            } catch (IOException e) {
                System.err.println("");
            }
        }
        MsgDialog.message("Rserve is busy!");
    }
}

From source file:com.vmware.bdd.utils.CommonUtil.java

public static void writeFile(File file, String content, boolean append) {
    OutputStream out = null;/*from  www. j  a v  a2s .  c  o  m*/
    BufferedWriter bw = null;
    try {
        out = new FileOutputStream(file, append);
        bw = new BufferedWriter(new OutputStreamWriter(out, "UTF-8"));
        bw.write(content);
        bw.flush();
    } catch (IOException e) {
        logger.warn("Write file failed : " + e.getMessage());
    } finally {
        if (bw != null && out != null) {
            try {
                bw.close();
                out.close();
            } catch (IOException e) {
                logger.warn("Close file failed : " + e.getMessage());
            }
        }
    }
}

From source file:bridge.toolkit.commands.S1000DConverter.java

/**
 * Write the string in the file on disk/*from ww  w  .  j  av  a 2 s  .c  o  m*/
 * 
 * @param file
 * @param contenuto
 * @throws Exception
 */
public static void writeOnDisk(File file, String contenuto) throws Exception {
    try {
        BufferedWriter outWriter = null;

        outWriter = new BufferedWriter(new java.io.FileWriter(file));
        outWriter.write(contenuto);
        outWriter.flush();
        outWriter.close();
    } catch (Exception ex) {
        throw ex;
    }
}

From source file:com.oocl.euc.ita.core.utils.FileUtils.java

public static void writefile(String path, String content, boolean append) {
    BufferedWriter bw;
    File targetFile;/*ww  w .j  a  va 2  s . c  om*/
    try {
        targetFile = new File(path);
        if (targetFile.exists() == false) {
            targetFile.createNewFile();
        }
        FileWriter fw = new FileWriter(targetFile, append);
        bw = new BufferedWriter(fw);
        bw.write(content + "\n");
        bw.flush();
        bw.close();
    } catch (Exception d) {
        System.out.println(d.getMessage());
    }
}

From source file:com.trackplus.ddl.DataReader.java

private static void writeInfoToFile(Map<String, String> info, String fileName) throws DDLException {
    BufferedWriter writer = createBufferedWriter(fileName);
    Iterator<String> it = info.keySet().iterator();
    while (it.hasNext()) {
        String key = it.next();//from  www  .j ava2s.c om
        String value = info.get(key);
        try {
            writer.write(key);
            writer.write("=");
            writer.write(value);
            writer.newLine();
        } catch (IOException ex) {
            throw new DDLException(ex.getMessage(), ex);
        }
    }

    try {
        writer.flush();
        writer.close();
    } catch (IOException e) {
        LOGGER.error("Error on close stream file " + fileName + " :" + e.getMessage());
        throw new DDLException(e.getMessage(), e);
    }
}

From source file:de.tudarmstadt.ukp.dkpro.tc.mallet.util.MalletUtils.java

public static void writeFeatureValuesToFile(String featureValues[], String outcome, File outputFile)
        throws IOException {
    BufferedWriter bw = new BufferedWriter(
            new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(outputFile, true)), "UTF-8"));
    bw.write("\n");
    for (String featureValue : featureValues) {
        bw.write(featureValue + " ");
    }/*  ww w .  j  a  v  a2  s.co  m*/
    bw.write(outcome);
    bw.flush();
    bw.close();
}

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   www. j  av  a 2 s  .  c  o 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:ar.com.tadp.xml.rinzo.core.utils.FileUtils.java

/**
 * Guarda un documento localmente en la cache
 */// w w w .  ja  v a  2s  .co  m
public static void saveFile(String inputFileName, File outputFile) {
    InputStream openStream = null;
    BufferedReader reader = null;
    BufferedWriter writer = null;
    try {
        File inputFile = new File(inputFileName);
        if (!inputFile.exists()) {
            openStream = new URL(inputFileName).openStream();
            InputStreamReader is = new InputStreamReader(openStream);
            String encoding = is.getEncoding();
            reader = new BufferedReader(is);
            writer = new BufferedWriter(
                    new OutputStreamWriter(new FileOutputStream(outputFile, false), encoding));

            String line = reader.readLine();
            while (line != null) {
                writer.write(line);
                writer.newLine();
                writer.flush();
                line = reader.readLine();
            }
        }
    } catch (Exception exception) {
        throw new RuntimeException("Error trying to save \'" + inputFileName + "\' in the cache.", exception);
    } finally {
        try {
            if (writer != null) {
                writer.flush();
                writer.close();
            }
            if (reader != null) {
                reader.close();
            }
            if (openStream != null) {
                openStream.close();
            }
        } catch (IOException e) {
            throw new RuntimeException(
                    "Error trying to close files while saving \'" + inputFileName + "\' in the cache.", e);
        }
    }
}