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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Checkbox and ListView in Android Layout 4 65
Need to track down Infection in a Server 2008 domain user profile 7 51
eclipse java  build path 6 56
factorial example 4 39
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

815 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

11 Experts available now in Live!

Get 1:1 Help Now