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 + ")");
}
Aggregations