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 uetac <fr...@compas-tis.com> on 2007/10/25 11:05:26 UTC

use the SVGTranscoder with GzipOutPutStream?

Hi!

 i'm writing a web app that load an svg file and send it to a web client
with some transformation.  there is two servlets :

- one to load and transform the SVGDocument and write it in the disk as a
temp file
- one to load the temp svg file and return it to the client 



I'm using the svgTranscoder to write the temp file. the svg files can be
compressed in a svgz format. so i'm trying to use it. My first idea is to
produce a gzip temp file like that :

[code]
		SVGTranscoder trans = new SVGTranscoder();

		trans.addTranscodingHint(SVGTranscoder.KEY_XML_DECLARATION,
				"<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
		trans.addTranscodingHint(SVGTranscoder.KEY_DOCTYPE,
				SVGTranscoder.VALUE_DOCTYPE_CHANGE);
		trans.addTranscodingHint(SVGTranscoder.KEY_FORMAT,
SVGTranscoder.VALUE_FORMAT_OFF);

		TranscoderInput input = new TranscoderInput(theTransformedSVGDocument);
		GZIPOutputStream gz = new GZIPOutputStream(new
FileOutputStream(tempFile));
		
		TranscoderOutput output = new TranscoderOutput(gz);
		try {

			trans.transcode(input,output);
		} catch (TranscoderException ex) {
			ex.printStackTrace();
		}

[/code]

The type tempfile  is File.
When executing this code i have an exception : 
java.lang.Error: Writer expected
	org.apache.batik.transcoder.svg2svg.SVGTranscoder.transcode(Unknown Source)

The TranscoderOutPut can be either an OutputStream or an outPutStreamWriter. 
can you help me? thank you!


-- 
View this message in context: http://www.nabble.com/use-the-SVGTranscoder-with-GzipOutPutStream--tf4689465.html#a13402722
Sent from the Batik - Users mailing list archive at Nabble.com.


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


Re: use the SVGTranscoder with GzipOutPutStream?

Posted by uetac <fr...@compas-tis.com>.


Tonny Kohar-2 wrote:
> 
> Hi,
> 
>> it's compiling but the svgz file is empty. may i use the wrapper
>> incorrectly?
> 
> It seem your code is ok, did you try to flush and close the
> fileOutputStream or writer, to make sure the content is written ?
> 
> Regards
> Tonny Kohar
> -- 
> Inspiration and Expression
> http://blogs.kiyut.com/tonny/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 
> 

shame on me ...
i'm sorry to spend your time with this error...
thank you to have spend some times for me !


-- 
View this message in context: http://www.nabble.com/use-the-SVGTranscoder-with-GzipOutPutStream--tf4689465.html#a13421815
Sent from the Batik - Users mailing list archive at Nabble.com.


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


Re: use the SVGTranscoder with GzipOutPutStream?

Posted by Tonny Kohar <to...@gmail.com>.
Hi,

> it's compiling but the svgz file is empty. may i use the wrapper
> incorrectly?

It seem your code is ok, did you try to flush and close the
fileOutputStream or writer, to make sure the content is written ?

Regards
Tonny Kohar
-- 
Inspiration and Expression
http://blogs.kiyut.com/tonny/

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


Re: use the SVGTranscoder with GzipOutPutStream?

Posted by uetac <fr...@compas-tis.com>.


thomas.deweese wrote:
> 
> Hi Frank,
> 
> uetac <fr...@compas-tis.com> wrote on 10/25/2007 05:05:26 AM:
> 
>> I'm using the svgTranscoder to write the temp file. the svg files can be
>> compressed in a svgz format. so i'm trying to use it. My first idea is 
> to
>> produce a gzip temp file like that :
>> 
>>       GZIPOutputStream gz = new GZIPOutputStream(new
>> FileOutputStream(tempFile));
>>       TranscoderOutput output = new TranscoderOutput(gz);
> 
>> The type tempfile  is File.
>> When executing this code i have an exception : 
>> java.lang.Error: Writer expected
>>    org.apache.batik.transcoder.svg2svg.SVGTranscoder.transcode(Unknown 
> Source)
> 
>    This should be easy enough to fix by simply wrapping the 
> GZIPOutputStream
> with a java.io.OutputStreamWriter and pass that to the TranscoderOutput
> constructor.
> 

ok, i have done it :
[code]
		GZIPOutputStream gz = new GZIPOutputStream(new
FileOutputStream(tempFile));

//		TranscoderOutput output = new TranscoderOutput(new
OutputStreamWriter(new FileOutputStream(tempFile), "UTF-8"));
		TranscoderOutput output = new TranscoderOutput(new OutputStreamWriter(gz,
"UTF-8"));
				
		try {

			trans.transcode(input, output);
		} catch (TranscoderException ex) {
			ex.printStackTrace();
		}

[/code]

it's compiling but the svgz file is empty. may i use the wrapper
incorrectly?
thank you

i have found something to help me but not to give a solution of that. My
servlet generates real svg files
and when the second servlet is called to send the svg file to the web
client, i "gzip" the outputsteam of the  HttpServletResponse. it works.

-- 
View this message in context: http://www.nabble.com/use-the-SVGTranscoder-with-GzipOutPutStream--tf4689465.html#a13409164
Sent from the Batik - Users mailing list archive at Nabble.com.


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


Re: use the SVGTranscoder with GzipOutPutStream?

Posted by th...@kodak.com.
Hi Frank,

uetac <fr...@compas-tis.com> wrote on 10/25/2007 05:05:26 AM:

> I'm using the svgTranscoder to write the temp file. the svg files can be
> compressed in a svgz format. so i'm trying to use it. My first idea is 
to
> produce a gzip temp file like that :
> 
>       GZIPOutputStream gz = new GZIPOutputStream(new
> FileOutputStream(tempFile));
>       TranscoderOutput output = new TranscoderOutput(gz);

> The type tempfile  is File.
> When executing this code i have an exception : 
> java.lang.Error: Writer expected
>    org.apache.batik.transcoder.svg2svg.SVGTranscoder.transcode(Unknown 
Source)

   This should be easy enough to fix by simply wrapping the 
GZIPOutputStream
with a java.io.OutputStreamWriter and pass that to the TranscoderOutput
constructor.