public PNGMessageBodyWriter implements MessageBodyWriter<MyPNG> {
....
boolean isWriteable(java.lang.Class<?> type,
java.lang.reflect.Type genericType,
java.lang.annotation.Annotation[] annotations,
MediaType mediaType)
{
return mediaType.toString.equals("image/png");
}
....
void writeTo(MyJPEG instance, java.lang.Class<?> type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations,
MediaType mediaType, MultivaluedMap<java.lang.String,java.lang.Object> httpHeaders, java.io.OutputStream entityStream) throws java.io.IOException,
WebApplicationException
{
JPEGTranscoder t = new JPEGTranscoder();
t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(.8));
InputStream is = new ByteArrayInputStream(instance.getBytes());
TranscoderInput input = new TranscoderInput(is);
TranscoderOutput output = new TranscoderOutput(entityStream);
t.transcode(input, output);
httpHeaders.put("Content-Disposition", ""attachment;filename=" + instance.getFilename());
httpHeaders.put("whatever else", "some other value");
}