Class MultipartStream.ItemInputStream

java.lang.Object
java.io.InputStream
org.apache.commons.fileupload.MultipartStream.ItemInputStream
All Implemented Interfaces:
Closeable, AutoCloseable, Closeable
Enclosing class:
MultipartStream

public class MultipartStream.ItemInputStream extends InputStream implements Closeable
An InputStream for reading an items contents.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final int
    Offset when converting negative bytes to integers.
    private boolean
    Whether the stream is already closed.
    private int
    The number of bytes, which must be hold, because they might be a part of the boundary.
    private int
    The current offset in the buffer.
    private long
    The number of bytes, which have been read so far.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the number of bytes, which are currently available, without blocking.
    void
    Closes the input stream.
    void
    close(boolean closeUnderlying)
    Closes the input stream.
    private void
    Called for finding the separator.
    long
    Returns the number of bytes, which have been read by the stream.
    boolean
    Returns, whether the stream is closed.
    private int
    Attempts to read more data.
    int
    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.

    Methods inherited from class java.io.InputStream

    mark, markSupported, read, reset

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • BYTE_POSITIVE_OFFSET

      private static final int BYTE_POSITIVE_OFFSET
      Offset when converting negative bytes to integers.
      See Also:
    • 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.
  • Constructor Details

    • ItemInputStream

      ItemInputStream()
      Creates a new instance.
  • Method Details

    • available

      public int available() throws IOException
      Returns the number of bytes, which are currently available, without blocking.
      Overrides:
      available in class InputStream
      Returns:
      Number of bytes in the buffer.
      Throws:
      IOException - An I/O error occurs.
    • close

      public void close() throws IOException
      Closes the input stream.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class InputStream
      Throws:
      IOException - An I/O error occurred.
    • close

      public void close(boolean closeUnderlying) throws IOException
      Closes the input stream.
      Parameters:
      closeUnderlying - Whether to close the underlying stream (hard close)
      Throws:
      IOException - An I/O error occurred.
    • 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.
    • isClosed

      public boolean isClosed()
      Returns, whether the stream is closed.
      Specified by:
      isClosed in interface Closeable
      Returns:
      True, if the stream is closed, otherwise false.
    • makeAvailable

      private int makeAvailable() throws IOException
      Attempts to read more data.
      Returns:
      Number of available bytes
      Throws:
      IOException - An I/O error occurred.
    • read

      public int read() throws IOException
      Returns the next byte in the stream.
      Specified by:
      read in class InputStream
      Returns:
      The next byte in the stream, as a non-negative integer, or -1 for EOF.
      Throws:
      IOException - An I/O error occurred.
    • read

      public int read(byte[] b, int off, int len) throws IOException
      Reads bytes into the given buffer.
      Overrides:
      read in class 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:
      IOException - An I/O error occurred.
    • skip

      public long skip(long bytes) throws IOException
      Skips the given number of bytes.
      Overrides:
      skip in class InputStream
      Parameters:
      bytes - Number of bytes to skip.
      Returns:
      The number of bytes, which have actually been skipped.
      Throws:
      IOException - An I/O error occurred.