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 );
        "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);
    JPEGTranscoder t = new JPEGTranscoder();
                         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");
    headerInfo( request, response, "image/jpeg");
    catch (Exception e)
        System.err.println("Error in writing output");

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

View raw message