FileDocCategorySizeDatePackage
RootInputStream.javaAPI DocAndroid 1.5 API3682Wed May 06 22:42:46 BST 2009org.apache.james.mime4j

RootInputStream

public class RootInputStream extends InputStream
InputStream used by the parser to wrap the original user supplied stream. This stream keeps track of the current line number and can also be truncated. When truncated the stream will appear to have reached end of file. This is used by the parser's {@link org.apache.james.mime4j.MimeStreamParser#stop()} method.
version
$Id: RootInputStream.java,v 1.2 2004/10/02 12:41:10 ntherning Exp $

Fields Summary
private InputStream
is
private int
lineNumber
private int
prev
private boolean
truncated
Constructors Summary
public RootInputStream(InputStream is)
Creates a new RootInputStream.

param
in the stream to read from.


                     
       
        this.is = is;
    
Methods Summary
public intgetLineNumber()
Gets the current line number starting at 1 (the number of \r\n read so far plus 1).

return
the current line number.

        return lineNumber;
    
public intread()

see
java.io.InputStream#read()

        if (truncated) {
            return -1;
        }
        
        int b = is.read();
        if (prev == '\r" && b == '\n") {
            lineNumber++;
        }
        prev = b;
        return b;
    
public intread(byte[] b, int off, int len)

see
java.io.InputStream#read(byte[], int, int)

        if (truncated) {
            return -1;
        }
        
        int n = is.read(b, off, len);
        for (int i = off; i < off + n; i++) {
            if (prev == '\r" && b[i] == '\n") {
                lineNumber++;
            }
            prev = b[i];
        }
        return n;
    
public intread(byte[] b)

see
java.io.InputStream#read(byte[])

        return read(b, 0, b.length);
    
public voidtruncate()
Truncates this InputStream. After this call any call to {@link #read()}, {@link #read(byte[]) or {@link #read(byte[], int, int)} will return -1 as if end-of-file had been reached.

        this.truncated = true;