xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Javid Alimohideen" <javid...@gmail.com>
Subject RE: Streaming SVG Document without creating temporary file
Date Mon, 19 Jun 2006 16:38:42 GMT
Hi Dylan,
When you say streaming, do you mean something like streaming animation, or
its just a dynamic document that is rendered on the server side.. The way I
do it in my application I render the SVG on the server side and just stream
the pixels to the client side (application, or a browser window). You could
acheive the same with servlet too. If you would like to do offscreen server
side rendering, take a look at the Batik wiki pages.

  -----Original Message-----
  From: Dylan Browne [mailto:dbrowne@mango-solutions.com]
  Sent: Monday, June 19, 2006 6:26 AM
  To: batik-users@xmlgraphics.apache.org
  Subject: Streaming SVG Document without creating temporary file


  I was looking for way to improve my code where I stream an SVG Document
(created using Batik DOM) to a browser. So basically I need to get from SVG
Document to a byte[] which can be passed via Servlet which sets the Mime
type, and so displayed.

  Currently I use my method below, but as part of this method I am creating
a file object and retrieving my byte[] from that. Ideally (it may actually
become a requirement) I'd like to avoid this step and be able to retrieve a
byte[] without creating a file object.

  Thanks in advance for any help,



      public static void streamSVGIntoImageFormat(HttpSession session,
Document doc, String mimeType) {

          try {

              ImageTranscoder t = null;

              if (mimeType.equals(Config.JPEG)) {

                  t = new JPEGTranscoder();

                  t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new

              } else if (mimeType.equals(Config.PNG)) {

                  t = new PNGTranscoder();

              } else if (mimeType.equals(Config.TIFF)) {

                  t = new TIFFTranscoder();

              } else {

                  System.out.println("ERROR: A request to stream an image
was recieved with an unsupported mime type: " + mimeType);



              TranscoderInput input = new TranscoderInput(doc);

              OutputStream ostream = new FileOutputStream("c:\\out." +

              TranscoderOutput output = new TranscoderOutput(ostream);

              t.transcode(input, output);



              byte[] bytes = getBytesFromFile(new File("c:\\out." +

              session.setAttribute("jpegbytes", bytes);

              session.setAttribute("mimeType", mimeType);

          } catch (Exception e) {


              System.out.println("Error in streaming SVG because " +



View raw message