Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.knowgate.hipermail
Class MboxFile

    java.lang.Object
      com.knowgate.hipermail.MboxFile

    public class MboxFile

extends java.lang.Object

Provides access to an mbox-formatted file.

Field Summary
`static java.lang.String` | `READ_ONLY`
`static java.lang.String` | `READ_WRITE`

Constructor Summary
`MboxFile(java.io.File file)` Constructor.
`MboxFile(java.io.File file, java.lang.String mode)` Constructor.
`MboxFile(java.lang.String filepath)` Constructor.
`MboxFile(java.lang.String filepath, java.lang.String mode)` Constructor.

Method Summary
`long` | `appendMessage(java.lang.CharSequence message)` Appends the specified message (represented by a CharSequence) to the mbox file.
`long` | `appendMessage(MboxFile source, int index)` Appends the specified message from another mbox file
`long` | `appendMessage(MboxFile source, long srcpos, int srcsize)` Appends the specified message from another mbox file
`void` | `close()` Close the mbox file and release any system resources.
`java.lang.CharSequence` | `getMessage(int index)` Returns a CharSequence containing the data for the message at the specified index.
`java.io.InputStream` | `getMessageAsStream(int index)` Opens an input stream to the specified message data.
`java.io.InputStream` | `getMessageAsStream(long begin, int size)` Get message as stream
`int` | `getMessageCount()` Returns the total number of messages in the mbox file.
`long` | `getMessagePosition(int index)` Get byte offset position of a given message inside the mbox file This method is slow when called for the first time, as it has to parse the whole Mbox file for finding each message index.
`long[]` | `getMessagePositions()` Returns an initialised array of file positions for all messages in the mbox file.
`int` | `getMessageSize(int index)` Get size of a message in bytes
`java.io.InputStream` | `getPartAsStream(long begin, long offset, int size)`
`void` | `purge(int[] messageNumbers)` Purge the specified messages from the file.
`long` | `size()` Return MBox file size in bytes

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 java.lang.String READ_ONLY

See Also:
  Constant Field Values

### READ_WRITE

    public static final java.lang.String READ_WRITE

See Also:
  Constant Field Values

Constructor Detail

### MboxFile

    public MboxFile(java.io.File file)
             throws java.io.FileNotFoundException,
                    java.io.IOException

  Constructor.

  Throws:
    `java.io.FileNotFoundException`
    `java.io.IOException`

### MboxFile

    public MboxFile(java.io.File file,
                    java.lang.String mode)
             throws java.io.FileNotFoundException,
                    java.io.IOException

  Constructor.

  Parameters:
    `file` -
    `mode` - Either MboxFile.READ_ONLY or MboxFile.READ_WRITE
  Throws:
    `java.io.FileNotFoundException`
    `java.io.IOException`

### MboxFile

    public MboxFile(java.lang.String filepath)

  Constructor.

  Parameters:
    `filepath` -
    `mode` - Either MboxFile.READ_ONLY or MboxFile.READ_WRITE

### MboxFile

    public MboxFile(java.lang.String filepath,
                    java.lang.String mode)
             throws java.io.FileNotFoundException,
                    java.io.IOException

  Constructor.

  Parameters:
    `filepath` -
    `mode` - Either MboxFile.READ_ONLY or MboxFile.READ_WRITE
  Throws:
    `java.io.FileNotFoundException`
    `java.io.IOException`

Method Detail

### size

    public long size()
              throws java.io.IOException

  Return MBox file size in bytes

  Returns:
    long
  Throws:
    `java.io.IOException`

### getMessagePositions

    public long[] getMessagePositions()
                               throws java.io.IOException

  Returns an initialised array of file positions for all messages in the mbox file.

  Returns:
    a long array
  Throws:
    `java.io.IOException` - thrown when unable to read from the specified file channel

### getMessagePosition

    public long getMessagePosition(int index)
                            throws java.io.IOException,
                                   java.lang.ArrayIndexOutOfBoundsException

  Get byte offset position of a given message inside the mbox file

  This method is slow when called for the first time, as it has to parse the whole Mbox file for finding each message index.

  Parameters:
    `index` - Message Index
  Returns:
    message byte offset position inside the mbox file
  Throws:
    `java.io.IOException`
    `java.lang.ArrayIndexOutOfBoundsException`

### getMessageSize

    public int getMessageSize(int index)
                       throws java.io.IOException,
                              java.lang.ArrayIndexOutOfBoundsException

  Get size of a message in bytes

  Parameters:
    `index` - Message Index
  Throws:
    `java.io.IOException`
    `java.lang.ArrayIndexOutOfBoundsException`

### getMessageCount

    public int getMessageCount()
                        throws java.io.IOException

  Returns the total number of messages in the mbox file.

  Returns:
    an int
  Throws:
    `java.io.IOException`

### getMessage

    public java.lang.CharSequence getMessage(int index)
                                      throws java.io.IOException

  Returns a CharSequence containing the data for the message at the specified index.

  Parameters:
    `index` - the index of the message to retrieve
  Returns:
    a CharSequence
  Throws:
    `java.io.IOException`

### getMessageAsStream

    public java.io.InputStream getMessageAsStream(long begin,
                                                  int size)
                                           throws java.io.IOException

  Get message as stream

  Parameters:
    `begin` - long Byte offset position for message
    `size` - int Number of bytes to be readed
  Returns:
    InputStream
  Throws:
    `java.io.IOException`

### getPartAsStream

    public java.io.InputStream getPartAsStream(long begin,
                                               long offset,
                                               int size)
                                        throws java.io.IOException

  Throws:
    `java.io.IOException`

### getMessageAsStream

    public java.io.InputStream getMessageAsStream(int index)
                                           throws java.io.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:
    `java.io.IOException`

### appendMessage

    public final long appendMessage(MboxFile source,
                                    long srcpos,
                                    int srcsize)
                             throws java.io.IOException

  Appends the specified message from another mbox file

  Parameters:
    `source` - Source mbox file
    `srcpos` - Byte offset position of message at source mbox file
    `srcsize` - Size of source message in bytes
  Returns:
    byte offset position where message is appended on this mbox file
  Throws:
    `java.io.IOException`

### appendMessage

    public final long appendMessage(MboxFile source,
                                    int index)
                             throws java.io.IOException

  Appends the specified message from another mbox file

  Parameters:
    `source` - Source mbox file
    `index` - Index of message to be appended at the source file
  Returns:
    byte offset position where message is appended on this mbox file
  Throws:
    `java.io.IOException`

### appendMessage

    public final long appendMessage(java.lang.CharSequence message)
                             throws java.io.IOException

  Appends the specified message (represented by a CharSequence) to the mbox file.

  Parameters:
    `message` -
  Throws:
    `java.io.IOException`

### purge

    public void purge(int[] messageNumbers)
               throws java.io.IOException,
                      java.lang.IllegalArgumentException

  Purge the specified messages from the file.

  Parameters:
    `messageNumbers` - int[]
  Throws:
    `java.io.IOException`
    `java.lang.IllegalArgumentException`

### close

    public void close()
               throws java.io.IOException

  Close the mbox file and release any system resources.

  Throws:
    `java.io.IOException`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD