xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sébastien Regnoult <sebastien.regno...@otake.fr>
Subject RE : SVGz
Date Tue, 09 Apr 2002 07:44:08 GMT
Hi !!
 
I got the answer, the difficulty is to get the resulting XML in memory
to then be able to gzip it 
 
I use a ByteArrayOutputStream to get it in memory, then I read the array
with a ByteArrayInputStream.
 
I hope it will work for you too ;-)
 
// Source code
 
OutputStream out = null;
out = new FileOutputStream("myfile.svgz");
 
ByteArrayOutputStream out2 = new ByteArrayOutputStream();
OutputStreamWriter writer = new OutputStreamWriter(out2,"ISO-8859-1");
 
SVGGraphics2D svgGenerator = new SVGGraphics2D(ctx, false);
chart.draw(svgGenerator, new Rectangle2D.Double(0, 0, 500, 400), null);
svgGenerator.stream(writer, false);
 
ByteArrayInputStream bai = new
ByteArrayInputStream(out2.toString().getBytes());
BufferedInputStream bis = new BufferedInputStream( bai );
GZIPOutputStream gzos = new GZIPOutputStream(new
BufferedOutputStream(out));
byte b[] = new byte[4096];
int c = 0;
 
while ((c = bis.read(b)) != -1)
{
    gzos.write(b, 0, c);
}
gzos.finish();
gzos.close();
out.close();

-----Message d'origine-----
De : ma zhenduo [mailto:mazd_work@yahoo.com] 
Envoyé : mardi 9 avril 2002 04:52
À : Batik Users
Objet : Re: SVGz


  public static void main4(String[] args) throws Exception{
    java.io.FileInputStream fis= new FileInputStream("c:\\test.svg");
    java.util.zip.GZIPOutputStream zos= new
java.util.zip.GZIPOutputStream(
      new FileOutputStream("c:\\test.svgz")
    );
    int n = -1;
    while( (n=fis.read())!=-1){
      zos.write(n);
    }
    zos.flush();
    zos.close();
  }
so, I think, when print the Document to .svgz, only replease the
FileOuputStream to GZIPOutputStream.


Mime
View raw message