Example usage for java.io Writer flush

List of usage examples for java.io Writer flush

Introduction

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

Prototype

public abstract void flush() throws IOException;

Source Link

Document

Flushes the stream.

Usage

From source file:Main.java

public static void writeStr(OutputStream out, String str, String charset) throws IOException {
    if (TextUtils.isEmpty(charset))
        charset = "UTF-8";

    Writer writer = new OutputStreamWriter(out, charset);
    writer.write(str);/*w w  w .j  a  v  a 2  s  . c o  m*/
    writer.flush();
}

From source file:Main.java

/**
 * flush Writer//from w ww  . ja va2  s  .  c om
 * 
 * @param br
 */
public static void flushWriter(Writer wr) {
    if (wr != null) {
        try {
            wr.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:Main.java

public static String sourceToString(Source source) throws IOException {

    try {// w  ww.j  av a2 s  . c  o m
        Transformer trans = transFactory.newTransformer();
        trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        trans.setOutputProperty(OutputKeys.INDENT, "yes");
        Writer writer = new StringWriter();
        trans.transform(source, new StreamResult(writer));
        writer.flush();
        return writer.toString();
    } catch (TransformerException ex) {
        throw new IOException(ex);
    }
}

From source file:Main.java

public static void createAccessLog(String accessLog, String fileName) {

    makeDirectory(getFilesDir());//ww w.  j a  v  a  2 s. c o m
    FileOutputStream fos = null;
    try {
        File newFile = new File(getFilesDir(), fileName);
        if (!newFile.exists()) {
            newFile.createNewFile();
        }

        fos = new FileOutputStream(newFile, false);
        Writer writer = new OutputStreamWriter(fos);
        writer.write(accessLog);
        writer.flush();
        fos.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:Main.java

public static void writeXml(String content, String path) {
    try {//from  w ww . j a  v a  2  s. c  om
        File file = new File(path);
        Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "utf-8"));
        out.write(content);
        out.flush();
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:Streams.java

public static void drain(Reader r, OutputStream os) throws IOException {
    Writer w = new OutputStreamWriter(os);
    drain(r, w);/*from ww w. j  a  v a 2 s . c o  m*/
    w.flush();
}

From source file:com.smash.revolance.ui.materials.TemplateHelper.java

public static String processTemplate(String templateName, Map<String, Object> variables)
        throws TemplateException, IOException {
    // load template
    Template template = null;//from w  w  w.jav  a2  s.c o m
    InputStreamReader stream = null;
    try {
        InputStream content = TemplateHelper.class.getClassLoader().getResourceAsStream(templateName);
        if (content == null) {
            System.err.println("Unable to find template: " + templateName);
            return "Unable to find template: " + templateName;
        } else {
            stream = new InputStreamReader(content);
            template = new Template("template", stream, null);
        }
    } catch (IOException e) {
        System.err.println("Unable to find template: " + templateName);
        return "Unable to find template: " + templateName;
    } finally {
        IOUtils.closeQuietly(stream);
    }
    // process template
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    if (template != null) {
        // Fill the template with parameter values
        Writer out = new OutputStreamWriter(baos);
        template.process(variables, out);
        out.flush();
    }
    return baos.toString();
}

From source file:Main.java

public static void writeToWriter(Iterator it, Writer out) throws IOException {
    while (it.hasNext()) {
        out.write(it.next().toString());
        out.write(newLine);/*from  w w w. j a v a 2s  .c om*/
    }
    out.flush();
}

From source file:Main.java

public static void writeToFile(String s, String filePath, boolean append) {
    File f = new File(filePath);
    Writer writer = null;
    try {// w w w  . j  av  a  2s.c om
        writer = new BufferedWriter(new FileWriter(f, append));
        writer.write(s);
        writer.flush();
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (writer != null) {
        try {
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:org.dkpro.lab.reporting.ChartUtil.java

/**
 * Exports a JFreeChart to a SVG file./*from w w w  .j a  v a  2 s .  c  om*/
 *
 * @param chart JFreeChart to export
 * @param aOS stream to write to.
 * @param aWidth width of the chart in pixels
 * @param aHeight height of the chart in pixels
 * @throws IOException if writing the svgFile fails.
 * @see <a href="http://dolf.trieschnigg.nl/jfreechart/">Saving JFreeChart as SVG vector images
 *      using Batik</a>
 */
public static void writeChartAsSVG(OutputStream aOS, JFreeChart chart, int aWidth, int aHeight)
        throws IOException {
    // Get a DOMImplementation and create an XML document
    DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
    Document document = domImpl.createDocument(null, "svg", null);

    // Create an instance of the SVG Generator
    SVGGraphics2D svgGenerator = new SVGGraphics2D(document);

    // draw the chart in the SVG generator
    chart.draw(svgGenerator, new Rectangle(aWidth, aHeight));

    // Write svg file
    Writer out = new OutputStreamWriter(aOS, "UTF-8");
    svgGenerator.stream(out, true /* use css */);
    out.flush();
    out.close();
}