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:
Closeable
,AutoCloseable
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
FieldsModifier and TypeFieldDescriptionprivate boolean
private final byte[]
private int
private final BufferedLineReaderInputStream
private boolean
private boolean
private int
Store the first buffer length.private boolean
private int
private final boolean
Fields inherited from class java.io.FilterInputStream
in
-
Constructor Summary
ConstructorsConstructorDescriptionMimeBoundaryInputStream
(BufferedLineReaderInputStream inbuffer, String boundary) Creates a new MimeBoundaryInputStream.MimeBoundaryInputStream
(BufferedLineReaderInputStream inbuffer, String boundary, boolean strict) Creates a new MimeBoundaryInputStream. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
void
close()
Closes the underlying stream.private boolean
boolean
eof()
private int
private boolean
hasData()
boolean
boolean
boolean
boolean
int
read()
int
read
(byte[] b, int off, int len) boolean
int
readLine
(ByteArrayBuffer dst) Reads one line of text into the givenByteArrayBuffer
.private void
toString()
boolean
unread
(ByteArrayBuffer buf) Tries to unread the last read line.boolean
private void
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Field Details
-
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
-
initialLength
private int initialLengthStore the first buffer length. Used to distinguish between an empty preamble and no preamble.
-
-
Constructor Details
-
MimeBoundaryInputStream
public MimeBoundaryInputStream(BufferedLineReaderInputStream inbuffer, String boundary, boolean strict) throws IOException Creates a new MimeBoundaryInputStream.- Parameters:
inbuffer
- The underlying stream.boundary
- Boundary string (not including leading hyphens).- Throws:
IllegalArgumentException
- when boundary is too longIOException
-
MimeBoundaryInputStream
public MimeBoundaryInputStream(BufferedLineReaderInputStream inbuffer, String boundary) throws IOException Creates a new MimeBoundaryInputStream.- Parameters:
inbuffer
- The underlying stream.boundary
- Boundary string (not including leading hyphens).- Throws:
IllegalArgumentException
- when boundary is too longIOException
-
-
Method Details
-
close
Closes the underlying stream.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classFilterInputStream
- Throws:
IOException
- on I/O errors.
-
markSupported
public boolean markSupported()- Overrides:
markSupported
in classFilterInputStream
- See Also:
-
readAllowed
- Throws:
IOException
-
read
- Overrides:
read
in classFilterInputStream
- Throws:
IOException
- See Also:
-
read
- Overrides:
read
in classFilterInputStream
- Throws:
IOException
-
readLine
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:
IOException
- in case of an I/O error.
-
verifyEndOfStream
- Throws:
IOException
-
endOfStream
private boolean endOfStream() -
hasData
private boolean hasData() -
fillBuffer
- Throws:
IOException
-
isEmptyStream
public boolean isEmptyStream() -
isFullyConsumed
public boolean isFullyConsumed() -
calculateBoundaryLen
- Throws:
IOException
-
skipBoundary
- Throws:
IOException
-
isLastPart
public boolean isLastPart() -
eof
public boolean eof() -
toString
-
unread
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
- Specified by:
unread
in classLineReaderInputStream
-