I am getting unsupport encodeing exceptions when I try to decode a message. Can any one show me what I am doing wrong
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   James_Kelley
Posted On:   Wednesday, December 5, 2001 03:57 PM

I am having problems decode attachments that are not base64, but are 7 bit 8 bit, ... What am I doing wrong? Do I have to modify my code (below)to use InputStream in=mbp.getInputStream(); String[] encoding=mbp.getHeader("Content-Transfer-Encoding"); if(encoding!=null && encoding.length>0){ in=MimeUtility.decode(in,encoding[0]); } or should writing the input stream to the out do an automatic decode for me? Thanks for the help my code String fileName = p.getFileName(); String disposition = p.getDisposition(); String contentType = p.getContentType(); String encoding = p.getEncoding();   More>>

I am having problems decode attachments that are not base64, but are 7 bit 8 bit, ... What am I doing wrong? Do I have to modify my code (below)to use


			

InputStream in=mbp.getInputStream();
String[] encoding=mbp.getHeader("Content-Transfer-Encoding");
if(encoding!=null && encoding.length>0){
in=MimeUtility.decode(in,encoding[0]);
}


or should writing the input stream to the out do an automatic decode for me?

Thanks for the help





my code

			
String fileName = p.getFileName();
String disposition = p.getDisposition();
String contentType = p.getContentType();
String encoding = p.getEncoding();

File attachmentDir = new File(attachmentDirStr);

if(!attachmentDir.exists())
attachmentDir.mkdirs();

if (fileName == null && (disposition.equals(Part.ATTACHMENT) || !contentType.equals("text/plain")))
{
// pick a random file name. This requires Java 1.2 or later.
fileName = File.createTempFile("attachment", ".txt",attachmentDir).getName();
//we need this to return a file name
newName = fileName.toString();
}

if (fileName == null)
{ // likely inline
p.writeTo(System.out);
}
else
{

File f = new File(attachmentDir,fileName);
int i = 0;
// find a version that does not yet exist attachment directory
newName = fileName;


while (f.exists())
{
i++;
newName = i + fileName;
f = new File(attachmentDir,newName);

}


FileOutputStream out = new FileOutputStream(f);

// We can't just use p.writeTo() here because it doesn't
// decode the attachment. Instead we copy the input stream
// onto the output stream which does automatically decode
// Base-64, quoted printable, and a variety of other formats.
InputStream in = new BufferedInputStream(p.getInputStream());
int b;
while ((b = in.read()) != -1)
{
out.write(b);
}
out.flush();
out.close();
in.close();
}
   <<Less

Re: I am getting unsupport encodeing exceptions when I try to decode a message. Can any one show me what I am doing wrong

Posted By:   Gianluca_Sartori  
Posted On:   Thursday, January 17, 2002 12:55 AM

You need an international version of JRE. The default version supports only the following encodings:


  • US-ASCII
  • ISO-8859-1
  • ISO-8859-2
  • UTF-8
  • UTF-16BE
  • UTF-16LE
  • UTF-16 with byte order mark

You can find an international version of JRE on the sun site.
About | Sitemap | Contact