rzvika2
asked on
When can I delete the physical file when using javax.mail MimeBodyPart
Hi!
I'm using the MimeBodyPart to add files as attachments.
The point is that I want to delete the files before sending the message.
Can you let me know if and when I can delete it?
The code that I'm talking about (from the javax.mail example) is:
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(mess ageBodyPar t);
// Part two is attachment
messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(filename);
messageBodyPart.setDataHan dler(new DataHandler(source));
messageBodyPart.setFileNam e(filename );
multipart.addBodyPart(mess ageBodyPar t);
Thanks!
I'm using the MimeBodyPart to add files as attachments.
The point is that I want to delete the files before sending the message.
Can you let me know if and when I can delete it?
The code that I'm talking about (from the javax.mail example) is:
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(mess
// Part two is attachment
messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(filename);
messageBodyPart.setDataHan
messageBodyPart.setFileNam
multipart.addBodyPart(mess
Thanks!
after you have sent it I'd say.
ASKER
No, I need a way to delete it before sending.
Then read it into memory, and use a memory based DataSource.
ASKER
Can you give me an example please?
there's an example of ByteArrayDataSource in the examples that come with javamail...
ASKER
Thanks, I have another related issue,
I need to convert my Multipart to a byte array and the easiest thing is using serialization.
I can't do it because the Multipart is not serializable.
What is your best solution?
Thanks!
I need to convert my Multipart to a byte array and the easiest thing is using serialization.
I can't do it because the Multipart is not serializable.
What is your best solution?
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I have class A that has String, and I have class B that extends A and has Integer and Multipart.
I need 2 methods in class B, one to load the object according to byte[] and one to save to byte[].
The easiest way was to do:
on save:
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);
out.writeObject(this);
out.close();
return bos.toByteArray();
on load:
ByteArrayInputStream bis = new ByteArrayInputStream(byteA rray);
ObjectInputStream in = new ObjectInputStream(bis);
Can you please answer again to my last question
(sorry for the bothering... :-) )
I need 2 methods in class B, one to load the object according to byte[] and one to save to byte[].
The easiest way was to do:
on save:
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);
out.writeObject(this);
out.close();
return bos.toByteArray();
on load:
ByteArrayInputStream bis = new ByteArrayInputStream(byteA
ObjectInputStream in = new ObjectInputStream(bis);
Can you please answer again to my last question
(sorry for the bothering... :-) )
3 questions in one? ;-)
What's the question for the last part?
Why are you trying to serialize the Multipart?
What's the question for the last part?
Why are you trying to serialize the Multipart?
ASKER
Yes, one thing leads to another ;-) (but I raise the points each time...)
The actual question deals with saving and loading an object to byte[], where not all the objects that it contains, are serialized.
The actual question deals with saving and loading an object to byte[], where not all the objects that it contains, are serialized.
use the code i posted above to serialize your multipart.
I don't think you can... That's the point of the Serializable interface, it stops you serializing things that cannot be serialized...
So, you can save the data by using writeTo() as objects showed you, but not load it back in...
Again, why are you serializing the Multipart object? Why not send the data needed to create it, to the place where it is to be used instead?
So, you can save the data by using writeTo() as objects showed you, but not load it back in...
Again, why are you serializing the Multipart object? Why not send the data needed to create it, to the place where it is to be used instead?
ASKER
I must save and load object B to byte array (this is not an option).
I save it because I'm not sending it immediately and I don't want to use the files.
I save it because I'm not sending it immediately and I don't want to use the files.
Why don't you save the message details *before* you create your Multipart.
ie. save what you need to create the multipart.
ie. save what you need to create the multipart.
I don't believe this can be done... I *think* that you will have to create it when you want to send (as it is not serializable)
I may be wrong though...
Hopefully objects can show you how :-)
I may be wrong though...
Hopefully objects can show you how :-)
ASKER
Someone packs for me this multipart according to a user selection (of files).
I have to save it for a later usage.
I think the most convenient way is to work with serialized object.
Can't I just derive from MimeBodyPart and Multipart and implement them as serializable?
I have to save it for a later usage.
I think the most convenient way is to work with serialized object.
Can't I just derive from MimeBodyPart and Multipart and implement them as serializable?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.