wood burning stoves 2.0*
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


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Image file data decoding..." Watch "Image file data decoding..." New topic
Author

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
{
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Image file data decoding...