Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Image file data decoding...  RSS feed

Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!