File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other JSE/JEE APIs and the fly likes Javamail base64decoderstream instead String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Javamail base64decoderstream instead String" Watch "Javamail base64decoderstream instead String" New topic

Javamail base64decoderstream instead String

Francesco Biegi

Joined: Oct 29, 2013
Posts: 3
Hi all,

i've a program to precess email and put them on DB. Since my provider has changed the login security (now its SSL connection), i've modified the connection config.

Now the problem its really strange: if i run my program from Eclipse (Run -> Run), all works fine.

First i get the content: Object content = message.getContent(); and on next i verify it
example: if (content instanceof String) {}

In this case, all works well.

If from Eclipse i create a runnable JAR (i need it to launch my program from batch file (.bat) ) and then i launch it, when i retrieve the content, i dont get an String from getContent(). but i get an BASE64DecoderStream.

I've tried to launch the program from the same machine, and from Eclipse i get String, and from a DOS .bat file, i get an BASE64DecoderStream.

Could you help me to understand this ?
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46380
Welcome to the Ranch

I shall move this discussion; it is too difficult for “beginning”, and you might get better attention elsewhere.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
The explanation is in the javadocs of Part and Part.getContent(): the type depends on the setup of the DataHandler mechanism, and that can differ between machines and between JVMs. Apparently Eclipse sets it up differently than a standalone JVM (no surprise there, really, as IDE environment frequently differ from non-IDE environments).
Francesco Biegi

Joined: Oct 29, 2013
Posts: 3
Thank you Campbell :-)

So, i'll try to understand how setup the DataHandler and i will test again.

If i will find some solution, i'll post there.
Francesco Biegi

Joined: Oct 29, 2013
Posts: 3
Hi All,

i havent find a real solution about this problem. I have simply do this:

1) If statement to check if the content ( Object content = message.getContent(); ) is instanceof InputStream
2) Read the stream and place it on String (or String buffer maybe is better for performance)
3) Getting byte from String created and create new one with format UTF-8:

I agree. Here's the link:
subject: Javamail base64decoderstream instead String
It's not a secret anymore!