Good afternoon in my timezone.
I am working with JavaMail api with exJello Provider. I am using SearchTerm class to filter the retrieved messages but it takes in average more than 1 minute to the search method returns results.So i decided to serialize a set of messages this way i did not have to wait so long.so i have one theoretical issue and one specif issue.
1) Only the classes that implements the Serializable interface could be serialize so the way i use to “serialize” this messages is not a “really” serialization, right ?
Snippet of my code : message.writeTo(“OutputStream”);
2) Now the problem that i am dealing with:
Snippet of code:
messages = inbox.search(new AndTerm(terms));
ObjectOutputStream stream = new ObjectOutputStream(new FileOutputStream("serializer.txt"));
for(Message msg : messages){
msg.writeTo(stream);
}
In the end of the process i had serialize more than one message in the file “serializer.txt”. My question is how can i deserialize those messages.I already am able to deserialize one messeage , but if the file contains more than one message only the first one get deserialize.
Code:
ObjectInputStream file = new ObjectInputStream(new FileInputStream("serializer.txt"));
new MimeMessage(session,file);
This code will deserialize just one message , but if i make a cicle only the first one will be again deserialize. So any body had face the same issue.
PS-> If i try to use the method readObject from any InputStream it will retrieve an exception, the only way is to use the Message constructor.
With the best regards
You can try ObjectInputStream.readObject()