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:com.whatsthatlight.teamcity.hipchat.test.HipChatConfigurationControllerTest.java

private static String renderTemplate(Template template) throws TemplateException, IOException {
    HashMap<String, Object> templateMap = new HashMap<String, Object>();
    Writer writer = new StringWriter();
    template.process(templateMap, writer);
    writer.flush();
    String renderedTemplate = writer.toString();
    writer.close();/*  w ww  . ja  va2s .co m*/
    return renderedTemplate;
}

From source file:com.ewcms.component.citizen.web.servlate.JavaScriptServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String encoding = getParameterValue(request, HEADER_ENCODING);
    encoding = (encoding == null ? DEFAULT_ENCODING : encoding);
    initResponseHeader(response, encoding);

    String callback = getParameterValue(request, CALLBACK_PARAMETER_NAME);
    String value;//from w w  w.ja  va2  s .  c  o  m
    if (callback == null) {
        value = "alert('?');";
    } else {
        CitizenService service = getCitizenService();
        String json = service.mainJSON();
        value = String.format("%s(%s);", callback, json);
    }
    Writer writer = response.getWriter();
    writer.write(value);
    writer.flush();
}

From source file:com.ewcms.component.online.web.servlate.JavaScriptServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String encoding = getParameterValue(request, HEADER_ENCODING);
    encoding = (encoding == null ? DEFAULT_ENCODING : encoding);
    initResponseHeader(response, encoding);

    String callback = getParameterValue(request, CALLBACK_PARAMETER_NAME);
    String value;//from w ww .j a  v  a 2s . c om
    if (callback == null) {
        value = "alert('?');";
    } else {
        OnlineService service = getOnlineService();
        String json = service.mainJSON();
        value = String.format("%s(%s);", callback, json);
    }
    Writer writer = response.getWriter();
    writer.write(value);
    writer.flush();
}

From source file:com.ewcms.component.hot.web.JavaScriptServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String encoding = getParameterValue(request, HEADER_ENCODING);
    encoding = (encoding == null ? DEFAULT_ENCODING : encoding);
    initResponseHeader(response, encoding);

    String callback = getParameterValue(request, CALLBACK_PARAMETER_NAME);
    callback = RegexUtil.FilterScriptAndStyle(callback);
    String value;//from   w  w w  .ja v a  2s .  c o m
    if (callback == null) {
        value = "alert('?');";
    } else {
        HotService service = getHotService();
        String json = service.mainJSON();
        value = String.format("%s(%s);", callback, json);
    }
    Writer writer = response.getWriter();
    writer.write(value);
    writer.flush();
}

From source file:dk.ange.octave.util.TeeWriter.java

@Override
public void flush() throws IOException {
    IOException ioe = null;//from w w w  .j  av  a 2 s. c o  m
    for (final Writer writer : writers) {
        try {
            writer.flush();
        } catch (final IOException e) {
            log.debug("Exception during flush()", e);
            ioe = e;
        }
    }
    if (ioe != null) {
        throw ioe;
    }
}

From source file:com.ewcms.component.interaction.web.servlate.JavaScriptServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String encoding = getParameterValue(request, HEADER_ENCODING);
    encoding = (encoding == null ? DEFAULT_ENCODING : encoding);
    initResponseHeader(response, encoding);

    Integer type = 1;// ww w  .  ja v a2s .c o m
    String interaction_type = getParameterValue(request, INTERACTION_TYPE);
    try {
        type = Integer.valueOf(interaction_type);
    } catch (Exception e) {
    }

    String callback = getParameterValue(request, CALLBACK_PARAMETER_NAME);
    String value;
    if (callback == null) {
        value = "alert('?');";
    } else {
        InteractionServiceable service = getInteractionService();
        String json = service.mainJSON(type);
        value = String.format("%s(%s);", callback, json);
    }
    Writer writer = response.getWriter();
    writer.write(value);
    writer.flush();
}

From source file:com.jhkt.playgroundArena.examples.generic.controller.GeneralController.java

@RequestMapping(value = "/sayHello", method = RequestMethod.GET)
public void sample(WebRequest request, Writer writer) {
    try {/*from w  ww  .  j av  a 2  s. c  om*/
        writer.write("I say Hello");
        writer.flush();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void writeDocument(Document doc, Writer out) throws IOException {
    // happy to replace this code w/ the non-deprecated code, but I couldn't get the transformer 
    // approach to work. 
    //    OutputFormat format = new OutputFormat(doc);
    //    format.setIndenting(true);
    //    format.setIndent(2);
    //    XMLSerializer serializer = new XMLSerializer(out, format);
    //    serializer.serialize(doc);

    DOMImplementationLS impl = (DOMImplementationLS) doc.getImplementation();
    LSSerializer writer = impl.createLSSerializer();
    DOMConfiguration config = writer.getDomConfig();

    if (config.canSetParameter("format-pretty-print", Boolean.TRUE)) {
        config.setParameter("format-pretty-print", Boolean.TRUE);
    }/*from  www . j  a v  a2  s  .  c om*/

    // what a crappy way to force the stream to be UTF-8.  yuck!
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    LSOutput output = impl.createLSOutput();
    output.setEncoding("UTF-8");
    output.setByteStream(baos);

    writer.write(doc, output);

    out.write(baos.toString());
    out.flush();
}

From source file:com.ewcms.component.comment.web.CounterServlet.java

private void responseJSON(HttpServletRequest request, HttpServletResponse response, final String encoding,
        final CommentCount count) throws IOException {
    initResponseHeader(response, encoding);
    String callback = request.getParameter("jsoncallback");
    String value = String.format("%s({\"commentCounter\":\"%d\",\"personCounter\":\"%d\"});", callback,
            count.getCommentCounter(), count.getPersonCounter());

    Writer writer = response.getWriter();
    writer.write(value);/*from www.j a  v a2s  .c  om*/
    writer.flush();
}

From source file:com.alvermont.terraj.stargen.ui.TemplateTest.java

/**
 * Run the test/*  w w w . ja va2  s . c om*/
 *
 * @throws java.io.IOException If there is an error writing the output
 * @throws freemarker.template.TemplateException If there is an error in the template
 */
public void go() throws IOException, TemplateException {
    Configuration cfg = new Configuration();
    // Specify the data source where the template files come from.
    cfg.setClassForTemplateLoading(TemplateTest.class, "/com/alvermont/terraj/stargen/templates/");

    // Specify how templates will see the data model. This is an advanced topic...
    // but just use this:
    cfg.setObjectWrapper(new DefaultObjectWrapper());

    // Create the root hash
    Map<String, Object> root = new HashMap<String, Object>();
    // Put string ``user'' into the root
    root.put("user", "Big Joe");
    // Create the hash for ``latestProduct''
    Map<String, Object> latest = new HashMap<String, Object>();
    // and put it into the root
    root.put("latestProduct", latest);
    // put ``url'' and ``name'' into latest
    latest.put("url", "products/greenmouse.html");
    latest.put("name", "green mouse");

    Template temp = cfg.getTemplate("test.ftl");
    Writer out = new OutputStreamWriter(System.out);
    temp.process(root, out);
    out.flush();
}