Package net.fortuna.mstor.data
Class MboxFile
- java.lang.Object
-
- 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MboxFile.BufferStrategy
Strategy for I/O buffers.
-
Field Summary
Fields Modifier and Type Field Description static String
FROM__PREFIX
The prefix for all "From_" lines in an mbox file.static String
READ_ONLY
Indicates a file should be opened for reading only.static String
READ_WRITE
Indicates a file should be opened for reading and writing.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.
-
-
-
Field Detail
-
READ_ONLY
public static final String READ_ONLY
Indicates a file should be opened for reading only.- See Also:
- Constant Field Values
-
READ_WRITE
public static final String READ_WRITE
Indicates a file should be opened for reading and writing.- 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
-
-
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
-
-