Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem using Base64 for decoding on Windows client for encoded image of Linux server

 
Samir Ketan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//Server code to get Image on Linux environment
String strInputImage = getTiffImageInString(); // get Tiff Image
byte[] decodedBytes = Base64.decodeBase64(strInputImage.getBytes());
String strTiffImage = getImageAsString(); // get tiff Image as string after processing to convert multi page Image
String strOutputImage = Base64.encodeBase64String(strImage.getBytes());

//Client code to get Image on Windows environment
String strImageFromServer = getTiffImageFromServer(); // get Tiff Image from Server
byte[] decodedBytes = Base64.decodeBase64(strImageFromServer.getBytes());
saveTiffImage(decodedBytes);// save on disk

When I try to get encoded image of Linux sever on Windows client it gives error as:
Error: Cannot decode the image for the type :
Occurs in: com.sun.media.jai.opimage.CodecRIFUtil
java.io.EOFException
at com.sun.media.jai.codec.SeekableStream.readShort(SeekableStream.java:439)
 
D. Ogranos
Ranch Hand
Posts: 214
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A typical source for this problem is different default charsets between Windows and Linux. You're using the getBytes() method which internally uses the default charset...so you get different results. Try using the getBytes(String charSet) method instead, and use a reasonable common charset (no idea which is best for this as I have no idea how your image is encoded. But you are probably safe with something like UTF-8).
 
Samir Ketan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
removed all getBytes() and toString() and the problem was resolved
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic