xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Boon, David" <david_b...@xelus.com>
Subject RE: Transcoder vs. servlet
Date Fri, 31 Aug 2001 18:09:58 GMT
You may want to grab the servlet response OutputStream like this instead:

OutputStream out = response.getOutputStream();
TranscoderOutput output =  new TranscoderOutput( out );
t.transcode(input, output);
output.flush();
output.close();

-----Original Message-----
From: J. David Eisenberg [mailto:catcode@catcode.com]
Sent: Thursday, August 30, 2001 1:06 AM
To: batik-users@xml.apache.org
Subject: Transcoder vs. servlet


I'm trying to transcode an SVG file (in a string buffer) to
JPG and send it out in a sevlet with this code:
==================================
	public void headerInfo( HttpServletRequest request,
		HttpServletResponse response, String contentType)
	{
 		response.setContentType( contentType );
		response.setHeader("Cache-Control",
			"no-cache, post-check=0, pre-check=0");
		String agent =
request.getHeader("User-Agent").toLowerCase();
		// netscape chokes on Pragma no-cahe 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 )
	{

		JPEGTranscoder t = new JPEGTranscoder();
		t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY,
                             new Float(.8));
		TranscoderInput input =
			new TranscoderInput( new StringReader(svgString)
);
		try {
			headerInfo( request, response, "image/jpeg");
	        TranscoderOutput output =
				new
TranscoderOutput(response.getOutputStream());
        	t.transcode(input, output);
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}

==================================
The first time I make the request, I seem to get a good
response.

The second time I make the request, I get this error:

Exception in thread "Thread-9" java.io.IOException: Broken pipe
        at java.net.SocketOutputStream.socketWrite(Native Method)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:83)
        at
org.apache.tomcat.service.http.HttpResponseAdapter.doWrite(HttpResponseAdapt
er.java:162)
        at
org.apache.tomcat.core.BufferedServletOutputStream.doWrite(BufferedServletOu
tputStream.java:121)
        at
org.apache.tomcat.core.BufferedServletOutputStream.write(BufferedServletOutp
utStream.java:192)
        at sun.awt.image.codec.JPEGImageEncoderImpl.writeJPEGStream(Native
Method)
        at
sun.awt.image.codec.JPEGImageEncoderImpl.encode(JPEGImageEncoderImpl.java:47
5)
        at
sun.awt.image.codec.JPEGImageEncoderImpl.encode(JPEGImageEncoderImpl.java:23
1)
        at
sun.awt.image.codec.JPEGImageEncoderImpl.encode(JPEGImageEncoderImpl.java:23
8)
        at
org.apache.batik.transcoder.image.JPEGTranscoder.writeImage(JPEGTranscoder.j
ava:72)
        at
org.apache.batik.transcoder.image.ImageTranscoder.transcode(ImageTranscoder.
java:262)
        at
org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(XMLAbstractTrans
coder.java:126)
        at Transform.emitJPG(Transform.java:312)
        at Transform.doPost(Transform.java:137)
        at Transform.doGet(Transform.java:164)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)
        at
[snip of other HttpServlet stack entries]
---
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

Mime
View raw message