You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Sébastien Regnoult <se...@otake.fr> on 2002/04/09 09:44:08 UTC
RE : SVGz
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.