You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-user@xml.apache.org by Tom Myers <to...@dreamscape.com> on 2001/07/30 17:52:08 UTC

Re: Binary encoded String to original format, displayed in Browser

At 05:37 PM 7/30/2001 +0200, Stephan Wiesner wrote:
>I have a PDF on the server. I read it into a Base64 encoded String and send
>it with SOAP to the client....
>Base64 bas = new Base64();
>byte[] b = bas.decode(text);
>
>// this works
>   FileOutputStream fo = new FileOutputStream("test.pdf");
>   fo.write(b);
>   fo.close();
>
>// this doesn't
>String aus = new String(b);
>out.print( aus ); // PrintWriter out
>                         // prinltn() doesn't work either.

Why can't you use a ServletOutputStream, via getOutputStream() from your
ServletResponse object? The javadoc says it "Returns a ServletOutputStream 
suitable for writing binary data in the response." whereas the javadoc for
PrintWriter says "Print formatted representations of objects to a text-output 
stream. This class implements all of the print methods found in PrintStream. 
It does not contain methods for writing raw bytes, for which a program 
should use unencoded byte streams."

Tom Myers