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

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

Introduction

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

Prototype

public abstract void write(byte[] array, int offset, int length);

Source Link

Document

Writes the buffer to output.

Usage

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

License:Apache License

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

        @Override//  www  .  jav  a  2s  . c om
        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

        }
    });
}