In Java:I am reading an image stream and writing it to file encoded in Base64 using-
-
sun.misc.BASE64Encoder
-
Base64Coder class from here >> http://www.source-code.biz/snippets/java/Base64Coder.html
code snippet:
// Java: ====== reading url stream, converting to base64 and sending it
FileOutputStream fos1 = new FileOutputStream (“c:\test_out_image.jpg”);
InputStream str = vURL.openStream();
byte buffer1 = new byte [1024];
int len1 = 0;
while ( (len1 = str.read(buffer1)) != -1 ) {
// Option 1)
//out = new sun.misc.BASE64Encoder().encode(buffer1);
// Option 2)
out = new String(Base64Coder.encode(buffer1));
fos1.write(buffer1, 0, len1);
output += out + “\r\n”;
}
str.close();
fos1.close();
//And write it to file
writeOutput(output,“c:\tests\out_base64image.txt”,“US-ASCII”);
//=========
Both output files for sun.* package and Base64Coder class are identical and the test output .jpg file is also fine.
Now, Base64 using lotuscript i.e. creating a notesMimeEntity, encoding it using Base64 and writing the stream to file is producing a file different to the ones produced by the java approach.
Both approach are using the same source image, src_image.jpg.
Is this right? I have a problem with this because I want to stream an html mail via smtp including inline images in Java. Now if I:
-
Send through a stream from the NOTES created base64 encoded file, the message goes through fine.
-
Send through a stream from the JAVA created base64 encoded file, the message DOES NOT go through: icon is displayed in yahoo and gmail simply returns the mail with router msg that says “…Illegal Attachment k9si207037nfc (in reply to end of DATA command)”
This has left me wondering if I am doing the JAVA encoding correctly or whether the packages I am using are doing the job correctly and thinking that the NOTES encoder is doing a good job as content is understood my the mail clients, gmail & yahoo etc.
So why not do everthing using lotuscript? Well, I could only if I can find a way of doing something like:
Call stream.Open( “http://hostname/mydb.nsf/src_image.jpg?OpenImageResource”)
as thus far this hasn’t work for me unless if I read from disk, something I don’t have control over.
Any help/pointers/etc, greatly appreaciated.
Jay