Example usage for org.apache.wicket.request.http WebResponse flush

List of usage examples for org.apache.wicket.request.http WebResponse flush

Introduction

In this page you can find the example usage for org.apache.wicket.request.http WebResponse flush.

Prototype

public abstract void flush();

Source Link

Document

Flushes the response.

Usage

From source file:com.apachecon.memories.link.ImageLink.java

License:Apache License

public void onClick() {
    RequestCycle.get().scheduleRequestHandlerAfterCurrent(new IRequestHandler() {

        @Override//from   ww  w  .j  ava 2s  .  co m
        public void respond(IRequestCycle requestCycle) {
            WebResponse response = (WebResponse) requestCycle.getResponse();
            response.setContentType(getModelObject().getContentType());

            try {
                InputStream is = getModelObject().getInputStream();

                byte[] buffer = new byte[512];
                int length = 0;
                while ((length = is.read(buffer)) > 0) {
                    response.write(buffer, 0, length);
                }
                response.flush();

                is.close();
            } catch (Exception e) {
                response.flush();
            }
        }

        @Override
        public void detach(IRequestCycle requestCycle) {
            // TODO Auto-generated method stub

        }
    });
}

From source file:org.opensingular.form.wicket.mapper.attachment.DownloadSupportedBehavior.java

License:Apache License

private void writeResponse(String url) throws IOException {
    JSONObject jsonFile = new JSONObject();
    jsonFile.put("url", url);
    WebResponse response = (WebResponse) RequestCycle.get().getResponse();
    response.setContentType("application/json");
    response.setHeader("Cache-Control", "no-store, no-cache");
    response.getOutputStream().write(jsonFile.toString().getBytes(StandardCharsets.UTF_8));
    response.flush();
}