Class IMAPInputStream
- java.lang.Object
-
- java.io.InputStream
-
- com.sun.mail.imap.IMAPInputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class IMAPInputStream extends java.io.InputStream
This class implements an IMAP data stream.
-
-
Field Summary
Fields Modifier and Type Field Description private int
blksize
private byte[]
buf
private int
bufcount
private int
bufpos
private boolean
lastBuffer
private int
max
private IMAPMessage
msg
private boolean
peek
private int
pos
private ByteArray
readbuf
private java.lang.String
section
private static int
slop
-
Constructor Summary
Constructors Constructor Description IMAPInputStream(IMAPMessage msg, java.lang.String section, int max, boolean peek)
Create an IMAPInputStream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
available()
Returns the number of bytes that can be read from this input stream without blocking.private void
checkSeen()
Normally the SEEN flag will have been set by now, but if not, force it to be set (as long as the folder isn't open read-only and we're not peeking).private void
fill()
Fetch more data from the server.private void
forceCheckExpunged()
Do a NOOP to force any untagged EXPUNGE responses and then check if this message is expunged.int
read()
Reads the next byte of data from this buffered input stream.int
read(byte[] b)
Reads up tob.length
bytes of data from this input stream into an array of bytes.int
read(byte[] b, int off, int len)
Reads up tolen
bytes of data from this input stream into the given buffer.
-
-
-
Field Detail
-
msg
private IMAPMessage msg
-
section
private java.lang.String section
-
pos
private int pos
-
blksize
private int blksize
-
max
private int max
-
buf
private byte[] buf
-
bufcount
private int bufcount
-
bufpos
private int bufpos
-
lastBuffer
private boolean lastBuffer
-
peek
private boolean peek
-
readbuf
private ByteArray readbuf
-
slop
private static final int slop
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
IMAPInputStream
public IMAPInputStream(IMAPMessage msg, java.lang.String section, int max, boolean peek)
Create an IMAPInputStream.- Parameters:
msg
- the IMAPMessage the data will come fromsection
- the IMAP section/part identifier for the datamax
- the number of bytes in this sectionpeek
- peek instead of fetch?
-
-
Method Detail
-
forceCheckExpunged
private void forceCheckExpunged() throws MessageRemovedIOException, FolderClosedIOException
Do a NOOP to force any untagged EXPUNGE responses and then check if this message is expunged.
-
fill
private void fill() throws java.io.IOException
Fetch more data from the server. This method assumes that all data has already been read in, hence bufpos > bufcount.- Throws:
java.io.IOException
-
read
public int read() throws java.io.IOException
Reads the next byte of data from this buffered input stream. If no byte is available, the value-1
is returned.- Specified by:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException
Reads up tolen
bytes of data from this input stream into the given buffer.Returns the total number of bytes read into the buffer, or
-1
if there is no more data.Note that this method mimics the "weird !" semantics of BufferedInputStream in that the number of bytes actually returned may be less that the requested value. So callers of this routine should be aware of this and must check the return value to insure that they have obtained the requisite number of bytes.
- Overrides:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
read
public int read(byte[] b) throws java.io.IOException
Reads up tob.length
bytes of data from this input stream into an array of bytes.Returns the total number of bytes read into the buffer, or
-1
is there is no more data.Note that this method mimics the "weird !" semantics of BufferedInputStream in that the number of bytes actually returned may be less that the requested value. So callers of this routine should be aware of this and must check the return value to insure that they have obtained the requisite number of bytes.
- Overrides:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
available
public int available() throws java.io.IOException
Returns the number of bytes that can be read from this input stream without blocking.- Overrides:
available
in classjava.io.InputStream
- Throws:
java.io.IOException
-
checkSeen
private void checkSeen()
Normally the SEEN flag will have been set by now, but if not, force it to be set (as long as the folder isn't open read-only and we're not peeking). And of course, if there's no folder (e.g., a nested message) don't do anything.
-
-