Writing bytes to a java.io.Writer
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Andy_Jefferies
Posted On:   Tuesday, December 18, 2001 07:51 AM

I'm trying to write a PDF File to a JSPWriter, but have found that character encoding is getting in the way. I have Buffered the file from disc with either a BufferedReader or BufferedInputStream where approriate, and loop until the input dries up. Using a FileReader, the bytes get all screwed up and so writing to the JSPWriter produces a bad result. A FileInputStream with an InputStreamReader and encoding set to default, "ASCII", and "US-ASCII" all failed too. I have succeeded by using two buffers, one byte[] and one char[] and after each read from a FileInputStream loop though the buffer and cast each individual byte to char before writing to the JSPWriter, but it seems to me that   More>>

I'm trying to write a PDF File to a JSPWriter, but have found that character encoding is getting in the way. I have Buffered the file from disc with either a BufferedReader or BufferedInputStream where approriate, and loop until the input dries up.


Using a FileReader, the bytes get all screwed up and so writing to the JSPWriter produces a bad result.


A FileInputStream with an InputStreamReader and encoding set to default, "ASCII", and "US-ASCII" all failed too.


I have succeeded by using two buffers, one byte[] and one char[] and after each read from a FileInputStream loop though the buffer and cast each individual byte to char before writing to the JSPWriter, but it seems to me that this might be a poor way of doing it.


Any better solutions?

   <<Less

Re: Writing bytes to a java.io.Writer

Posted By:   Christopher_Schultz  
Posted On:   Tuesday, December 18, 2001 09:29 AM

Are you using a JSP to serve your PDF content, and that's why you are using a JSPWriter? Instead, consider using a servlet (not JSP) and use the getOutputStream method to get a stream to which you can write your raw bytes. Remember to set the content-type!



Hope that helps,

-chris
About | Sitemap | Contact