• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Image file data decoding...

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
{
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.
reply
    Bookmark Topic Watch Topic
  • New Topic