Package org.apache.james.mime4j.io
Class MimeBoundaryInputStream
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- org.apache.james.mime4j.io.LineReaderInputStream
-
- org.apache.james.mime4j.io.MimeBoundaryInputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class MimeBoundaryInputStream extends LineReaderInputStream
Stream that constrains itself to a single MIME body part. After the stream ends (i.e. read() returns -1)isLastPart()
can be used to determine if a final boundary has been seen or not.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
atBoundary
private byte[]
boundary
private int
boundaryLen
private BufferedLineReaderInputStream
buffer
private boolean
completed
private boolean
eof
private int
initialLength
Store the first buffer length.private boolean
lastPart
private int
limit
private boolean
strict
-
Constructor Summary
Constructors Constructor Description MimeBoundaryInputStream(BufferedLineReaderInputStream inbuffer, java.lang.String boundary)
Creates a new MimeBoundaryInputStream.MimeBoundaryInputStream(BufferedLineReaderInputStream inbuffer, java.lang.String boundary, boolean strict)
Creates a new MimeBoundaryInputStream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
calculateBoundaryLen()
void
close()
Closes the underlying stream.private boolean
endOfStream()
boolean
eof()
private int
fillBuffer()
private boolean
hasData()
boolean
isEmptyStream()
boolean
isFullyConsumed()
boolean
isLastPart()
boolean
markSupported()
int
read()
int
read(byte[] b, int off, int len)
boolean
readAllowed()
int
readLine(ByteArrayBuffer dst)
Reads one line of text into the givenByteArrayBuffer
.private void
skipBoundary()
java.lang.String
toString()
boolean
unread(ByteArrayBuffer buf)
Tries to unread the last read line.boolean
unread(RecycledByteArrayBuffer buf)
private void
verifyEndOfStream()
-
-
-
Field Detail
-
boundary
private final byte[] boundary
-
strict
private final boolean strict
-
eof
private boolean eof
-
limit
private int limit
-
atBoundary
private boolean atBoundary
-
boundaryLen
private int boundaryLen
-
lastPart
private boolean lastPart
-
completed
private boolean completed
-
buffer
private final BufferedLineReaderInputStream buffer
-
initialLength
private int initialLength
Store the first buffer length. Used to distinguish between an empty preamble and no preamble.
-
-
Constructor Detail
-
MimeBoundaryInputStream
public MimeBoundaryInputStream(BufferedLineReaderInputStream inbuffer, java.lang.String boundary, boolean strict) throws java.io.IOException
Creates a new MimeBoundaryInputStream.- Parameters:
inbuffer
- The underlying stream.boundary
- Boundary string (not including leading hyphens).- Throws:
java.lang.IllegalArgumentException
- when boundary is too longjava.io.IOException
-
MimeBoundaryInputStream
public MimeBoundaryInputStream(BufferedLineReaderInputStream inbuffer, java.lang.String boundary) throws java.io.IOException
Creates a new MimeBoundaryInputStream.- Parameters:
inbuffer
- The underlying stream.boundary
- Boundary string (not including leading hyphens).- Throws:
java.lang.IllegalArgumentException
- when boundary is too longjava.io.IOException
-
-
Method Detail
-
close
public void close() throws java.io.IOException
Closes the underlying stream.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
- on I/O errors.
-
markSupported
public boolean markSupported()
- Overrides:
markSupported
in classjava.io.FilterInputStream
- See Also:
InputStream.markSupported()
-
readAllowed
public boolean readAllowed() throws java.io.IOException
- Throws:
java.io.IOException
-
read
public int read() throws java.io.IOException
- Overrides:
read
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
- See Also:
InputStream.read()
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException
- Overrides:
read
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
-
readLine
public int readLine(ByteArrayBuffer dst) throws java.io.IOException
Description copied from class:LineReaderInputStream
Reads one line of text into the givenByteArrayBuffer
.- Specified by:
readLine
in classLineReaderInputStream
- Parameters:
dst
- Destination- Returns:
- number of bytes copied or
-1
if the end of the stream has been reached. - Throws:
MaxLineLimitException
- if the line exceeds a limit on the line length imposed by a subclass.java.io.IOException
- in case of an I/O error.
-
verifyEndOfStream
private void verifyEndOfStream() throws java.io.IOException
- Throws:
java.io.IOException
-
endOfStream
private boolean endOfStream()
-
hasData
private boolean hasData()
-
fillBuffer
private int fillBuffer() throws java.io.IOException
- Throws:
java.io.IOException
-
isEmptyStream
public boolean isEmptyStream()
-
isFullyConsumed
public boolean isFullyConsumed()
-
calculateBoundaryLen
private void calculateBoundaryLen() throws java.io.IOException
- Throws:
java.io.IOException
-
skipBoundary
private void skipBoundary() throws java.io.IOException
- Throws:
java.io.IOException
-
isLastPart
public boolean isLastPart()
-
eof
public boolean eof()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
unread
public boolean unread(ByteArrayBuffer buf)
Description copied from class:LineReaderInputStream
Tries to unread the last read line. Implementation may refuse to unread a new buffer until the previous unread one has been competely consumed. Implementations will directly use the byte array backed by buf, so make sure to not alter it anymore once this method has been called.- Specified by:
unread
in classLineReaderInputStream
- Returns:
- true if the unread has been succesfull.
-
unread
public boolean unread(RecycledByteArrayBuffer buf)
- Specified by:
unread
in classLineReaderInputStream
-
-