How to correctly use MimeUtility?
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Weiling_Li
Posted On:   Thursday, November 13, 2003 11:02 PM

Could anyone send me a sample of using MimeUtility.encode() and MimeUtility.decode()? Here are my methods for encoding and decoding. However they seem to be missing some bytes: public static String charEncode(String str, String enc) throws IOException, MessagingException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); OutputStream os = MimeUtility.encode((OutputStream)bos, enc); os.write(str.getBytes()); return bos.toString(); } public String charDecode(String str, String enc) throws IOException, MessagingException { ByteArrayInputStream bis = new ByteArrayInp   More>>

Could anyone send me a sample of using MimeUtility.encode() and MimeUtility.decode()? Here are my methods for encoding and decoding. However they seem to be missing some bytes:


public static String charEncode(String str, String enc) throws IOException, MessagingException


{



ByteArrayOutputStream bos = new ByteArrayOutputStream();


OutputStream os = MimeUtility.encode((OutputStream)bos, enc);


os.write(str.getBytes());


return bos.toString();


}



public String charDecode(String str, String enc) throws IOException, MessagingException


{


ByteArrayInputStream bis = new ByteArrayInputStream(str.getBytes());


InputStream is = MimeUtility.decode((InputStream)bis, enc);


byte[] b = new byte[is.available()];


is.read(b);



bis.close();


is.close();



return new String(b);



}

   <<Less
About | Sitemap | Contact