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:fr.gouv.finances.dgfip.xemelios.utils.TextWriter.java

/**
 * write writes the node to the writer as text.
 *
 * @param writer The Writer to write to//from  w  w  w .ja  v a 2 s .com
 */
public void write(Writer writer) throws IOException {
    try {
        BufferedWriter buf = new BufferedWriter(writer, 4096);
        writeNode(buf, node);
        buf.flush();
    } catch (Exception e) {
        e.printStackTrace(System.err);
    }
}

From source file:com.github.braully.graph.BatchExecuteOperation.java

void processFileG6GZ(IGraphOperation operation, File file, String dirname, boolean contProcess)
        throws IOException {
    if (file != null) {
        String name = file.getName();
        long continueOffset = -1;
        if (contProcess) {
            continueOffset = getLastProcessCont(operation, dirname, name, file);
        }// w w  w .  j ava  2s  .c  om

        BufferedReader r = new BufferedReader(
                new InputStreamReader(new GZIPInputStream(new FileInputStream(file))));
        File resultFile = getResultFile(operation, file, dirname);
        BufferedWriter writer = new BufferedWriter(new FileWriter(resultFile, true));
        processStreamGraph(r, operation, dirname, file.getName(), writer, continueOffset);
        try {
            writer.flush();
            writer.close();
            r.close();
        } catch (Exception e) {
        }
    }
}

From source file:com.github.braully.graph.BatchExecuteOperation.java

void processFileG6(IGraphOperation operation, File file, String dirname, boolean contProcess)
        throws IOException {

    if (file != null) {
        if (verbose) {
            System.out.println("Processing file: " + file.getAbsolutePath());
        }/*from  www.j  a v a2  s  . c  o m*/
        String name = file.getName();
        long continueOffset = -1;
        if (contProcess) {
            continueOffset = getLastProcessCont(operation, dirname, name, file);
        }

        BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
        File resultFile = getResultFile(operation, file, dirname);
        BufferedWriter writer = new BufferedWriter(new FileWriter(resultFile, true));
        processStreamGraph(r, operation, dirname, file.getName(), writer, continueOffset);
        try {
            writer.flush();
            writer.close();
            r.close();
        } catch (Exception e) {

        }
    }
}

From source file:com.zimbra.qa.unittest.prov.ldap.TestProvIDN.java

private void printOutput(boolean verbose, String text) {
    if (!verbose)
        return;/*  www .ja  v a2  s  .co m*/

    PrintStream ps = System.out;
    try {
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(ps, "UTF-8"));
        writer.write(text + "\n");
        writer.flush();
    } catch (UnsupportedEncodingException e) {
        ps.println(text);
    } catch (IOException e) {
        ps.println(text);
    }
}

From source file:com.github.niltz.maven.plugins.mongodb.AbstractMongoDBMojo.java

/**
 * //  w w  w.  ja v  a 2 s .c o  m
 * @param outputFileWriter
 * @param scriptFile
 * @param scriptData
 * @throws IOException
 */
private void appendScriptToFileWriter(BufferedWriter outputFileWriter, File scriptFile, StringBuffer scriptData)
        throws IOException {
    outputFileWriter.append("//").append("\n");
    outputFileWriter.append("// -------------------- " + scriptFile.getName()).append("\n");
    outputFileWriter.append("//").append("\n");
    outputFileWriter.append(scriptData.toString());
    outputFileWriter.flush();
}

From source file:edu.tsinghua.lumaqq.ui.helper.ExportHelper.java

/**
 * /*from www.j  a va 2s. com*/
 * 
 * @param exporter
 *       
 * @param argument
 *       ?
 * @param filename
 *       ??
 */
private void exportToFile(IRecordExporter exporter, Object argument, String filename) {
    // filename?null
    if (filename != null) {
        BufferedWriter writer = null;
        try {
            // 
            File file = new File(filename);
            if (!file.exists())
                file.createNewFile();

            writer = new BufferedWriter(new FileWriter(file));
            writer.write(exporter.generate(argument));
            writer.flush();
        } catch (IOException ex) {
            log.error("?");
        } finally {
            try {
                if (writer != null)
                    writer.close();
            } catch (IOException e1) {
                log.error(e1.getMessage());
            }
        }
    }
}

From source file:musite.io.xml.ProteinResidueAnnotationWriter.java

private void writeMap(OutputStream os, BufferedWriter bufWriter, Map<String, Object> m, String prefix)
        throws IOException {
    if (m == null)
        return;/*from  w  ww .ja va2s. c  o  m*/

    for (Map.Entry<String, Object> entry : m.entrySet()) {
        String k = entry.getKey();
        if (fieldFilter != null && fieldFilter.contains(k) != fieldInclude)
            continue;

        Object v = entry.getValue();

        bufWriter.write(prefix + "<" + k + ">");

        Writer fieldWriter = annotationFieldWriters.get(k);
        if (fieldWriter == null) {
            fieldWriter = XMLUtil.createDefaultWriter(v);
            bufWriter.flush();
            fieldWriter.write(os, v);
        } else {
            bufWriter.write("\n");
            bufWriter.flush();
            if (fieldWriter instanceof AbstractXMLWriter)
                ((AbstractXMLWriter) fieldWriter).setIndent(getIndent() + 3);
            fieldWriter.write(os, v);
            bufWriter.write(prefix);
        }

        bufWriter.write("</" + k + ">\n");
    }

}

From source file:com.microsoft.alm.plugin.external.ToolRunner.java

public Process sendArgsViaStandardInput(final ArgumentBuilder argumentBuilder) {
    ArgumentHelper.checkNotNull(toolProcess, "toolProcess");
    ArgumentHelper.checkNotNull(argumentBuilder, "argumentBuilder");
    logger.info("sendArgsViaStandardInput: proceedWithArgs: " + argumentBuilder.toString());
    final OutputStream stdin = toolProcess.getOutputStream();
    final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stdin));
    try {/*  w  w  w.  j  ava2  s  .co  m*/
        for (final String arg : argumentBuilder.build()) {
            final String escapedArg = escapeArgument(arg);
            writer.write(escapedArg);
            writer.write(" ");
        }
        writer.write("\n");
        writer.flush();
    } catch (final Throwable throwable) {
        logger.warn("Error sending args.", throwable);
        listenerProxy.processException(throwable);
    } finally {
        try {
            writer.close();
        } catch (final IOException e) {
            logger.warn("Unable to close the writer.", e);
        }
    }
    return toolProcess;
}

From source file:io.github.jeddict.jcode.parser.ejs.EJSUtil.java

public static void insertNeedle(FileObject root, String source, String needlePointer, String needleContent,
        ProgressHandler handler) {//  w w  w  .ja  v a2 s. c om
    if (StringUtils.isEmpty(needleContent)) {
        return;
    }
    Charset charset = Charset.forName("UTF-8");
    BufferedReader reader;
    BufferedWriter writer;
    if (source.endsWith("json")) {
        needlePointer = "\"" + needlePointer + "\"";
    } else {
        needlePointer = " " + needlePointer + " ";
    }
    try {
        // temp file
        File outFile = File.createTempFile("needle", "tmp");
        // input
        FileObject sourceFileObject = root.getFileObject(source);
        if (sourceFileObject == null) {
            handler.error("Needle file", String.format("needle file '%s' not found ", source));
            return;
        }
        File sourceFile = FileUtil.toFile(sourceFileObject);
        reader = new BufferedReader(new InputStreamReader(new FileInputStream(sourceFile), charset));
        writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), charset));
        StringBuilder content = new StringBuilder();
        boolean contentUpdated = false;
        String thisLine;
        while ((thisLine = reader.readLine()) != null) {
            if (thisLine.contains(needlePointer)) {
                content.append(needleContent);
                contentUpdated = true;
            }
            content.append(thisLine).append("\n");
        }

        IOUtils.write(content.toString(), writer);

        try {
            reader.close();
        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        }
        try {
            writer.flush();
            writer.close();
        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        }
        if (contentUpdated) {
            sourceFile.delete();
            outFile.renameTo(sourceFile);
        } else {
            outFile.delete();
        }
    } catch (FileNotFoundException ex) {
        Exceptions.printStackTrace(ex);
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
}

From source file:com.ivanbratoev.festpal.datamodel.db.external.ExternalDatabaseHandler.java

private HttpURLConnection setupConnection(URL url, Map<String, String> parameters) throws IOException {
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setReadTimeout(10_000);//from   w w w.j av  a2  s.c  o  m
    connection.setConnectTimeout(15_000);
    connection.setRequestMethod("POST");
    connection.setDoInput(true);
    connection.setDoOutput(true);
    OutputStream os = connection.getOutputStream();
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
    writer.write(buildParametersList(parameters));
    writer.flush();
    writer.close();
    os.close();
    return connection;
}