Package org.apache.commons.fileupload
Class MultipartStream.ItemInputStream
- java.lang.Object
-
- java.io.InputStream
-
- org.apache.commons.fileupload.MultipartStream.ItemInputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,Closeable
- Enclosing class:
- MultipartStream
public class MultipartStream.ItemInputStream extends java.io.InputStream implements Closeable
AnInputStream
for reading an items contents.
-
-
Field Summary
Fields Modifier and Type Field Description private static int
BYTE_POSITIVE_OFFSET
Offset when converting negative bytes to integers.private boolean
closed
Whether the stream is already closed.private int
pad
The number of bytes, which must be hold, because they might be a part of the boundary.private int
pos
The current offset in the buffer.private long
total
The number of bytes, which have been read so far.
-
Constructor Summary
Constructors Constructor Description ItemInputStream()
Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
available()
Returns the number of bytes, which are currently available, without blocking.void
close()
Closes the input stream.void
close(boolean pCloseUnderlying)
Closes the input stream.private void
findSeparator()
Called for finding the separator.long
getBytesRead()
Returns the number of bytes, which have been read by the stream.boolean
isClosed()
Returns, whether the stream is closed.private int
makeAvailable()
Attempts to read more data.int
read()
Returns the next byte in the stream.int
read(byte[] b, int off, int len)
Reads bytes into the given buffer.long
skip(long bytes)
Skips the given number of bytes.
-
-
-
Field Detail
-
total
private long total
The number of bytes, which have been read so far.
-
pad
private int pad
The number of bytes, which must be hold, because they might be a part of the boundary.
-
pos
private int pos
The current offset in the buffer.
-
closed
private boolean closed
Whether the stream is already closed.
-
BYTE_POSITIVE_OFFSET
private static final int BYTE_POSITIVE_OFFSET
Offset when converting negative bytes to integers.- See Also:
- Constant Field Values
-
-
Method Detail
-
findSeparator
private void findSeparator()
Called for finding the separator.
-
getBytesRead
public long getBytesRead()
Returns the number of bytes, which have been read by the stream.- Returns:
- Number of bytes, which have been read so far.
-
available
public int available() throws java.io.IOException
Returns the number of bytes, which are currently available, without blocking.- Overrides:
available
in classjava.io.InputStream
- Returns:
- Number of bytes in the buffer.
- Throws:
java.io.IOException
- An I/O error occurs.
-
read
public int read() throws java.io.IOException
Returns the next byte in the stream.- Specified by:
read
in classjava.io.InputStream
- Returns:
- The next byte in the stream, as a non-negative integer, or -1 for EOF.
- Throws:
java.io.IOException
- An I/O error occurred.
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException
Reads bytes into the given buffer.- Overrides:
read
in classjava.io.InputStream
- Parameters:
b
- The destination buffer, where to write to.off
- Offset of the first byte in the buffer.len
- Maximum number of bytes to read.- Returns:
- Number of bytes, which have been actually read, or -1 for EOF.
- Throws:
java.io.IOException
- An I/O error occurred.
-
close
public void close() throws java.io.IOException
Closes the input stream.
-
close
public void close(boolean pCloseUnderlying) throws java.io.IOException
Closes the input stream.- Parameters:
pCloseUnderlying
- Whether to close the underlying stream (hard close)- Throws:
java.io.IOException
- An I/O error occurred.
-
skip
public long skip(long bytes) throws java.io.IOException
Skips the given number of bytes.- Overrides:
skip
in classjava.io.InputStream
- Parameters:
bytes
- Number of bytes to skip.- Returns:
- The number of bytes, which have actually been skipped.
- Throws:
java.io.IOException
- An I/O error occurred.
-
makeAvailable
private int makeAvailable() throws java.io.IOException
Attempts to read more data.- Returns:
- Number of available bytes
- Throws:
java.io.IOException
- An I/O error occurred.
-
-