Search in sources :

Example 1 with ChunkedResponseOutputStream

use of org.polymap.core.data.util.ChunkedResponseOutputStream in project polymap4-core by Polymap4.

the class ImageEncodeProcessor method encodeImageResponse.

@Consumes(ImageResponse.class)
@Produces({ EncodedImageResponse.class, EndOfProcessing.class })
public void encodeImageResponse(ImageResponse response, ProcessorContext context) throws Exception {
    Timer timer = new Timer();
    // chunked reponse output stream
    ChunkedResponseOutputStream out = new ChunkedResponseOutputStream(context) {

        protected ProcessorResponse createResponse(byte[] buf, int buflen) {
            // log.debug( "sending: buflen= " + buflen );
            return new EncodedImageResponse(buf, buflen);
        }
    };
    // load image data
    // new javax.swing.ImageIcon( image ).getImage();
    String format = (String) context.get("format");
    if ("image/jpeg".equals(format)) {
        imageioEncodeJPEG(response.getImage(), out);
    } else {
        opEncodePNG(response.getImage(), out);
    }
    log.debug("encode: ready. (" + timer.elapsedTime() + "ms)");
    out.flush();
    context.sendResponse(ProcessorResponse.EOP);
    log.debug("...all data sent. (" + out.getTotalSent() + " bytes " + format + ")");
}
Also used : Timer(org.polymap.core.runtime.Timer) ChunkedResponseOutputStream(org.polymap.core.data.util.ChunkedResponseOutputStream) Consumes(org.polymap.core.data.pipeline.Consumes) Produces(org.polymap.core.data.pipeline.Produces)

Aggregations

Consumes (org.polymap.core.data.pipeline.Consumes)1 Produces (org.polymap.core.data.pipeline.Produces)1 ChunkedResponseOutputStream (org.polymap.core.data.util.ChunkedResponseOutputStream)1 Timer (org.polymap.core.runtime.Timer)1