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
{
res.setContentType("application/octet-stream");
String fileName = req.getParameter("fileName");
InputStream inputStream = req.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
int fetchedChar;
StringBuffer readData = new StringBuffer();
while ( (fetchedChar = reader.read()) != -1)
{
readData.append( (char)fetchedChar );
}
PrintWriter writer = null;
File file = null;
try
{
file = new File("C:\\" + fileName);
writer = new PrintWriter(new FileWriter(file), true);
String decodedStr = Base64Decoder.decode( readData.toString() );
writer.print( decodedStr );
}
catch(Exception e)
{
e.printStackTrace();
System.out.println(e.getMessage());
}
finally
{
writer.close();
}
}
Appreciate any input.
Thank you.