File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Problem using Base64 for decoding on Windows client for encoded image of Linux server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Problem using Base64 for decoding on Windows client for encoded image of Linux server " Watch "Problem using Base64 for decoding on Windows client for encoded image of Linux server " New topic
Author

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

Samir Ketan
Greenhorn

Joined: Jun 17, 2012
Posts: 2
//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

Joined: Feb 02, 2009
Posts: 214
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

Joined: Jun 17, 2012
Posts: 2
removed all getBytes() and toString() and the problem was resolved
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem using Base64 for decoding on Windows client for encoded image of Linux server