Class 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.
    • Constructor Detail

      • MboxFile

        public MboxFile​(File file)
        Parameters:
        file - a reference to an mbox data file
      • MboxFile

        public MboxFile​(File file,
                        String mode)
        Parameters:
        file - a reference to an mbox data file
        mode - the mode used to open the file
    • Method Detail

      • getMessageCount

        public final int getMessageCount()
                                  throws IOException
        Returns the total number of messages in the mbox file.
        Returns:
        an int
        Throws:
        IOException - where an error occurs reading messages
      • 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 - where an error occurs reading the message
      • 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 - where an error occurs reading the message
      • 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 - where an error occurs writing the message data
      • 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 - where an error occurs updating the data file
      • close

        public final void close()
                         throws IOException
        Close the mbox file and release any system resources.
        Throws:
        IOException - where an error occurs closing the data file
      • 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.
        Parameters:
        file - an mbox file reference
        Returns:
        true if the specified file is a valid mbox file