Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Servlets and the fly likes Image file data decoding... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Servlets
Bookmark "Image file data decoding..." Watch "Image file data decoding..." New topic

Image file data decoding...

Mandy Smith
Ranch Hand

Joined: Jun 26, 2001
Posts: 62
I am trying to read the .JPEG's encoded file data from the http header passed from other application. In the process i am trying to decode to write the decoded file data into an image file. I am using com.oreilly's package to do the encoding and decoding part. Encoding seem to be working fine, but there is a problem with decoding part. It can't recognize those chars from range 130-161, up higger it can.
For these extended special chars, it's inserting '?' marks. As a result, i am seeing a garbled image.
My problem is how do i make this decode part to work? Is there something that i am doing wrong in my code? Could someone, please take a look at this example.
Here is my code
public void doPost( HttpServletRequest req,
HttpServletResponse res )
throws ServletException, IOException
String fileName = req.getParameter("fileName");
InputStream inputStream = req.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
int fetchedChar;
StringBuffer readData = new StringBuffer();
while ( (fetchedChar = != -1)
readData.append( (char)fetchedChar );

PrintWriter writer = null;
File file = null;
file = new File("C:\\" + fileName);
writer = new PrintWriter(new FileWriter(file), true);

String decodedStr = Base64Decoder.decode( readData.toString() );

writer.print( decodedStr );
catch(Exception e)
Appreciate any input.
Thank you.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Image file data decoding...
It's not a secret anymore!