net.fortuna.mstor.data
Class MboxFile

java.lang.Object
  extended by net.fortuna.mstor.data.MboxFile

public class MboxFile
extends Object

Provides access to an mbox-formatted file. To read an mbox file using a non-standard file encoding you may specify the following system property:

       -Dmstor.mbox.encoding=<some_encoding>
 
If no encoding system property is specified the default file encoding will be used.

Author:
Ben Fortuna

Field Summary
static String FROM__PREFIX
          The prefix for all "From_" lines in an mbox file.
static String READ_ONLY
           
static String READ_WRITE
           
 
Constructor Summary
MboxFile(File file)
          Constructor.
MboxFile(File file, String mode)
          Constructor.
 
Method Summary
 void appendMessage(byte[] message)
          Appends the specified message (represented by a CharSequence) to the mbox file.
 void close()
          Close the mbox file and release any system resources.
 byte[] getMessage(int index)
          Convenience method that returns a message as a byte array containing the data for the message at the specified index.
 InputStream getMessageAsStream(int index)
          Opens an input stream to the specified message data.
 int getMessageCount()
          Returns the total number of messages in the mbox file.
static boolean isValid(File file)
          Indicates whether the specified file appears to be a valid mbox file.
 void purge(int[] msgnums)
          Purge the specified messages from the file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

READ_ONLY

public static final String READ_ONLY
See Also:
Constant Field Values

READ_WRITE

public static final String READ_WRITE
See Also:
Constant Field Values

FROM__PREFIX

public static final String FROM__PREFIX
The prefix for all "From_" lines in an mbox file.

See Also:
Constant Field Values
Constructor Detail

MboxFile

public MboxFile(File file)
         throws FileNotFoundException
Constructor.

Throws:
FileNotFoundException

MboxFile

public MboxFile(File file,
                String mode)
Constructor.

Method Detail

getMessageCount

public final int getMessageCount()
                          throws IOException
Returns the total number of messages in the mbox file.

Returns:
an int
Throws:
IOException

getMessageAsStream

public final InputStream getMessageAsStream(int index)
                                     throws IOException
Opens an input stream to the specified message data.

Parameters:
index - the index of the message to open a stream to
Returns:
an input stream
Throws:
IOException

getMessage

public final byte[] getMessage(int index)
                        throws IOException
Convenience method that returns a message as a byte array containing the data for the message at the specified index.

Parameters:
index - the index of the message to retrieve
Returns:
a byte array
Throws:
IOException

appendMessage

public final void appendMessage(byte[] message)
                         throws IOException
Appends the specified message (represented by a CharSequence) to the mbox file.

Parameters:
message -
Throws:
IOException

purge

public final void purge(int[] msgnums)
                 throws IOException
Purge the specified messages from the file.

Parameters:
msgnums - the indices of the messages to purge
Throws:
IOException

close

public final void close()
                 throws IOException
Close the mbox file and release any system resources.

Throws:
IOException

isValid

public static boolean isValid(File file)
Indicates whether the specified file appears to be a valid mbox file. Note that this method does not check the entire file for validity, but rather checks the first line for indication that this is an mbox file.