javax.mail.util.SharedByteArrayInputStream error

Posted on 2008-10-06
Last Modified: 2013-11-23
hi there
i'm trying to get the body of a mimemessage but i get the error javax.mail.util.SharedByteArrayInputStream and i have no idea why it happening

URL url = new URL(sUrl);
InputStream in = url.openStream();
MimeMessage msg  = new MimeMessage(session, in);

String a = msg.getContent().toString();   - I get javax.mail.util.SharedByteArrayInputStream and I have no idea why

Can anyone see what I'm doign wrong.

i've upgraded from java 1.5 to 1.6 and using the latest mail.jar
Question by:csharpperson
  • 2
  • 2
LVL 23

Expert Comment

ID: 22656545
Getting string from getContent is not a good idea, if you look at javadocs


public java.lang.Object getContent()

    Return the content as a Java object. The type of this object is dependent on the content itself. For example, the native format of a "text/plain" content is usually a String object. The native format for a "multipart" message is always a Multipart subclass. For content types that are unknown to the DataHandler system, an input stream is returned as the content.

    This implementation obtains the content from the DataHandler, that is, it invokes getDataHandler().getContent().

    Specified by:
        getContent in interface Part

        MessagingException - - this is typically thrown by the DataHandler. Refer to the documentation for javax.activation.DataHandler for more details.
    See Also:
        Part, DataHandler.getContent()
LVL 23

Expert Comment

ID: 22656556
You need to change the type of the Content and read the data accordingly

Author Comment

ID: 22657390
could you give me an example of how i do this please?

Author Comment

ID: 22666986
I've solved this myself now ny using getInputStream()


Accepted Solution

Computer101 earned 0 total points
ID: 23061466
PAQed with points refunded (30)

EE Admin

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
topping2 challenge 13 80
what is the main difference between git clone and fetch ann pull and push commands 2 67
servlet doXXX methods 3 33
map related example 6 29
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now