com.ericdaugherty.mail.server.utils
Class DelimitedInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by java.io.PushbackInputStream
              extended by com.ericdaugherty.mail.server.utils.DelimitedInputStream
All Implemented Interfaces:
java.io.Closeable

public class DelimitedInputStream
extends java.io.PushbackInputStream

This class adds to another InputStream the ability to read a line of bytes off the underlying stream source. The assumption is that the source bytes correspond to a sequence of characters. It is desirable in certain situations to be able to read a delimited series of bytes rather than have them converted to a stream of characters first, since it might be possible that the character set is unknown at a stage of the process or that the overhead needed to use the proper one is unacceptable or that it simply is not neccessary to have the bytes converted to characters. One such case is when JES reads a message from an I/O source where the EOL is platform-dependent.

Author:
Andreas Kyrmegalos

Field Summary
protected  byte[] delimiter
          A byte array corresponding to an EOL
protected  int maxBufferSize
          The size of the pushback buffer
protected  boolean twoByteDelimiter
          A flag to indicate the size of the EOL
 
Fields inherited from class java.io.PushbackInputStream
buf, pos
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
DelimitedInputStream(java.io.InputStream in)
          A constructor using a fixed buffer size
DelimitedInputStream(java.io.InputStream in, byte[] delimiter)
          A constructor using an application defined delimiter and a fixed buffer size
DelimitedInputStream(java.io.InputStream in, int maxBufferSize)
          A constructor using an application defined buffer size
DelimitedInputStream(java.io.InputStream in, int maxBufferSize, byte[] delimiter)
          A constructor using an application defined buffer size and delimiter
 
Method Summary
 byte[] readLine()
          The method to extract a single line of bytes
 
Methods inherited from class java.io.PushbackInputStream
available, close, mark, markSupported, read, read, reset, skip, unread, unread, unread
 
Methods inherited from class java.io.FilterInputStream
read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

delimiter

protected final byte[] delimiter
A byte array corresponding to an EOL


twoByteDelimiter

protected final boolean twoByteDelimiter
A flag to indicate the size of the EOL


maxBufferSize

protected final int maxBufferSize
The size of the pushback buffer

Constructor Detail

DelimitedInputStream

public DelimitedInputStream(java.io.InputStream in)
                     throws java.io.IOException
A constructor using a fixed buffer size

Throws:
java.io.IOException

DelimitedInputStream

public DelimitedInputStream(java.io.InputStream in,
                            byte[] delimiter)
                     throws java.io.IOException
A constructor using an application defined delimiter and a fixed buffer size

Throws:
java.io.IOException

DelimitedInputStream

public DelimitedInputStream(java.io.InputStream in,
                            int maxBufferSize)
                     throws java.io.IOException
A constructor using an application defined buffer size

Throws:
java.io.IOException

DelimitedInputStream

public DelimitedInputStream(java.io.InputStream in,
                            int maxBufferSize,
                            byte[] delimiter)
                     throws java.io.IOException
A constructor using an application defined buffer size and delimiter

Throws:
java.io.IOException
Method Detail

readLine

public byte[] readLine()
                throws java.io.IOException
The method to extract a single line of bytes

Returns:
byte[] a line of bytes without a trailing EOL
Throws:
java.io.IOException