In this project you will extend your mail-system
from the Email Attachment Project to use File
I/O to write email to a file and read it from a file.
Part 1
Add two methods to your MailServer class:
public void shutdown() throws ShutdownException
This method should save the details of all the MailItems
(excluding
attachments) stored on the MailServer to a file named
mail.csv in the
project directory. You may borrow the methods makeAbsoluteFilename
and
getProjectFolder from the address-book-io project. Each
MailItem should be
written to one line in the file, with the fields in comma-separated
value
(csv) format (you can assume that none of the fields in
the MailItem contain
commas):
from,to,subject,message
Make sure you handle exceptions appropriately. You must
create the
ShutdownException class, which should contain a String describing
why the
shut down procedure failed.
private void restore() throws RestoreException
This method
should read the details of the MailItems stored in mail.csv
and
restore the state of the MailServer. The MailItems for
each user should be
queued in the same order as they were received by the MailServer
before the
MailServer was shut down.
Make sure you handle exceptions appropriately. You must
create the
RestoreException class, which should contain a String describing
why the
restore procedure failed.
Now modify the MailServer class so that when the MailServer
is created, it
checks to see if it needs to restore its state from mail.csv.
Part 2
Now update the shutdown and restore methods so that they
handle attachments.
Do this by adding a fifth field to each line of the mail.csv
file, denoting
the number of attachments on the MailItem:
from,to,subject,message,num_of_attachments
Then write the details of each Attachment on the following
lines, one to a
line. You will need to figure out an appropriate format for
writing
attachments. |