FileItemIteratorImpl (Apache Tomcat 9.0.119 API Documentation)
Description: declaration: package: org.apache.tomcat.util.http.fileupload.impl, class: FileItemIteratorImpl

# Class FileItemIteratorImpl

java.lang.Object
org.apache.tomcat.util.http.fileupload.impl.FileItemIteratorImpl

All Implemented Interfaces:
  `FileItemIterator`

public class FileItemIteratorImpl extends Object implements FileItemIterator
The iterator, which is returned by `FileUploadBase.getItemIterator(RequestContext)`.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `FileItemIteratorImpl(FileUploadBase fileUploadBase, RequestContext requestContext)`
  Creates a new instance.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `List<FileItem>`
  `getFileItems()`
  Returns all file items by iterating through the entire request.
  `long`
  `getFileSizeMax()`
  Returns the maximum size of a single file.
  `MultipartStream`
  `getMultiPartStream()`
  Returns the underlying MultipartStream, initializing it if necessary.
  `long`
  `getSizeMax()`
  Returns the maximum size of the complete HTTP request.
  `boolean`
  `hasNext()`
  Returns, whether another instance of `FileItemStream` is available.
  `protected void`
  `init(FileUploadBase fileUploadBase, RequestContext pRequestContext)`
  Initializes the multipart stream for processing the request.
  `FileItemStream`
  `next()`
  Returns the next available `FileItemStream`.
  `void`
  `setFileSizeMax(long fileSizeMax)`
  Sets the maximum size of a single file.
  `void`
  `setSizeMax(long sizeMax)`
  Returns the maximum size of the complete HTTP request.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### FileItemIteratorImpl

    public FileItemIteratorImpl(FileUploadBase fileUploadBase, RequestContext requestContext) throws FileUploadException, IOException
    Creates a new instance.
    Parameters:
      `fileUploadBase` - Main processor.
      `requestContext` - The request context.
    Throws:
      `FileUploadException` - An error occurred while parsing the request.
      `IOException` - An I/O error occurred.

- ## Method Details

  - ### getSizeMax

    public long getSizeMax()
    Description copied from interface: `FileItemIterator`
    Returns the maximum size of the complete HTTP request. A `SizeLimitExceededException` will be thrown, if the HTTP request will exceed this value. By default, this value will be copied from the `FileUploadBase` object, however, the user may replace the default value with a request specific value by invoking `FileItemIterator.setSizeMax(long)` on this object.
    Specified by:
      `getSizeMax` in interface `FileItemIterator`
    Returns:
      The maximum size of the complete HTTP request. The value -1 indicates "unlimited".

  - ### setSizeMax

    public void setSizeMax(long sizeMax)
    Description copied from interface: `FileItemIterator`
    Returns the maximum size of the complete HTTP request. A `SizeLimitExceededException` will be thrown, if the HTTP request will exceed this value. By default, this value will be copied from the `FileUploadBase` object, however, the user may replace the default value with a request specific value by invoking `FileItemIterator.setSizeMax(long)` on this object. Note: Setting the maximum size on this object will work only, if the iterator is not yet initialized. In other words: If the methods `FileItemIterator.hasNext()`, `FileItemIterator.next()` have not yet been invoked.
    Specified by:
      `setSizeMax` in interface `FileItemIterator`
    Parameters:
      `sizeMax` - The maximum size of the complete HTTP request. The value -1 indicates "unlimited".

  - ### getFileSizeMax

    public long getFileSizeMax()
    Description copied from interface: `FileItemIterator`
    Returns the maximum size of a single file. An `FileSizeLimitExceededException` will be thrown, if there is an uploaded file, which is exceeding this value. By default, this value will be copied from the `FileUploadBase` object, however, the user may replace the default value with a request specific value by invoking `FileItemIterator.setFileSizeMax(long)` on this object.
    Specified by:
      `getFileSizeMax` in interface `FileItemIterator`
    Returns:
      The maximum size of a single, uploaded file. The value -1 indicates "unlimited".

  - ### setFileSizeMax

    public void setFileSizeMax(long fileSizeMax)
    Description copied from interface: `FileItemIterator`
    Sets the maximum size of a single file. An `FileSizeLimitExceededException` will be thrown, if there is an uploaded file, which is exceeding this value. By default, this value will be copied from the `FileUploadBase` object, however, the user may replace the default value with a request specific value by invoking `FileItemIterator.setFileSizeMax(long)` on this object, so there is no need to configure it here. Note:Changing this value doesn't affect files, that have already been uploaded.
    Specified by:
      `setFileSizeMax` in interface `FileItemIterator`
    Parameters:
      `fileSizeMax` - The maximum size of a single, uploaded file. The value -1 indicates "unlimited".

  - ### init

    protected void init(FileUploadBase fileUploadBase, RequestContext pRequestContext) throws FileUploadException, IOException
    Initializes the multipart stream for processing the request.
    Parameters:
      `fileUploadBase` - The file upload base configuration
      `pRequestContext` - The request context - unused
    Throws:
      `FileUploadException` - If the request content type is invalid or size exceeds limits
      `IOException` - If an I/O error occurs

  - ### getMultiPartStream

    public MultipartStream getMultiPartStream() throws FileUploadException, IOException
    Returns the underlying MultipartStream, initializing it if necessary.
    Returns:
      The MultipartStream for this iterator
    Throws:
      `FileUploadException` - If the request content type is invalid or size exceeds limits
      `IOException` - If an I/O error occurs

  - ### hasNext

    public boolean hasNext() throws FileUploadException, IOException
    Returns, whether another instance of `FileItemStream` is available.
    Specified by:
      `hasNext` in interface `FileItemIterator`
    Returns:
      True, if one or more additional file items are available, otherwise false.
    Throws:
      `FileUploadException` - Parsing or processing the file item failed.
      `IOException` - Reading the file item failed.

  - ### next

    public FileItemStream next() throws FileUploadException, IOException
    Returns the next available `FileItemStream`.
    Specified by:
      `next` in interface `FileItemIterator`
    Returns:
      FileItemStream instance, which provides access to the next file item.
    Throws:
      `NoSuchElementException` - No more items are available. Use `hasNext()` to prevent this exception.
      `FileUploadException` - Parsing or processing the file item failed.
      `IOException` - Reading the file item failed.

  - ### getFileItems

    public List<FileItem> getFileItems() throws FileUploadException, IOException
    Description copied from interface: `FileItemIterator`
    Returns all file items by iterating through the entire request.
    Specified by:
      `getFileItems` in interface `FileItemIterator`
    Returns:
      The list of all file items
    Throws:
      `FileUploadException` - Parsing or processing the file item failed
      `IOException` - Reading the file item failed