xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "J. David Eisenberg" <catc...@catcode.com>
Subject Transcoder vs. servlet (continued)
Date Thu, 30 Aug 2001 16:16:37 GMT
I have updated the example of trying to transcode an SVG file to JPG and
send it to the client.  First, I had the wrong MIME type, although fixing
that didn't help.  Second, I realized that the transcoder might close the
output stream, which would be a Bad Thing for a servlet, so I have changed
it to transcode to a ByteArrayOutputStream, which then feeds to the
response. I also added response.reset(), but that didn't help either. I
still get the same "broken pipe" the second time I call on the servlet.

=====================
public void headerInfo( HttpServletRequest request,
    HttpServletResponse response, String contentType)
{
    response.setContentType( contentType );
    response.setHeader("Cache-Control",
        "no-cache, post-check=0, pre-check=0");
    String agent = request.getHeader("User-Agent").toLowerCase();
    // netscape chokes on Pragma no-cache so only send it to explorer
    if (agent.indexOf("explorer") > -1){
      response.setHeader("Pragma", "no-cache");
    }
    response.setHeader("Expires", "Thu, 01 Dec 1994 16:00:00 GMT");
}

public void emitJPG ( HttpServletRequest request,
    HttpServletResponse response, String svgString )
{
    ByteArrayOutputStream baos = new ByteArrayOutputStream(16384);
    response.reset();
    JPEGTranscoder t = new JPEGTranscoder();
    t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY,
                         new Float(.8));
    TranscoderInput input =
        new TranscoderInput( new StringReader(svgString) );
    try {
        TranscoderOutput output =
            new TranscoderOutput(baos);
        t.transcode(input, output);
    }
    catch (Exception e)
    {
        System.err.println("Error in EmitJPG");
        e.printStackTrace();
    }
    headerInfo( request, response, "image/jpeg");
    try
    {
        baos.writeTo(response.getOutputStream());
    }
    catch (Exception e)
    {
        System.err.println("Error in writing output");
        e.printStackTrace();
    }
}
====================

---
J. David Eisenberg  http://catcode.com/



---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org


Mime
View raw message