Class MultiPartFormInputStream


  • public class MultiPartFormInputStream
    extends java.lang.Object
    MultiPartInputStream

    Handle a MultiPart Mime input stream, breaking it up on the boundary into files and strings.

    Deleting the parts can be done from a different thread if the parts are parsed asynchronously. Because of this we use the state to fail the parsing and coordinate which thread will delete any remaining parts. The deletion of parts is done by the cleanup thread in all cases except the transition from DELETING->DELETED which is done by the parsing thread.

    
     UNPARSED - Parsing has not started, there are no parts which need to be cleaned up.
     PARSING  - The parsing thread is reading from the InputStream and generating parts.
     PARSED   - Parsing has complete and no more parts will be generated.
     DELETING - deleteParts() has been called while we were in PARSING state, parsing thread will do the delete.
     DELETED  - The parts have been deleted, this is the terminal state.
    
                                  deleteParts()
         +--------------------------------------------------------------+
         |                                                              |
         |                                          deleteParts()       v
      UNPARSED -------> PARSING --------> PARSED  ------------------>DELETED
                          |                                             ^
                          |                                             |
                          +---------------> DELETING -------------------+
                            deleteParts()               parsing thread
     
    See Also:
    https://tools.ietf.org/html/rfc7578
    • Constructor Summary

      Constructors 
      Constructor Description
      MultiPartFormInputStream​(java.io.InputStream in, java.lang.String contentType, jakarta.servlet.MultipartConfigElement config, java.io.File contextTmpDir)  
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      void deleteParts()
      Delete any tmp storage for parts, and clear out the parts list.
      int getBufferSize()  
      jakarta.servlet.http.Part getPart​(java.lang.String name)
      Get the named Part.
      java.util.Collection<jakarta.servlet.http.Part> getParts()
      Parse, if necessary, the multipart data and return the list of Parts.
      boolean isDeleteOnExit()
      Deprecated.
      no replacement provided
      boolean isEmpty()
      Deprecated.
      use getParts().isEmpty()
      boolean isWriteFilesWithFilenames()  
      protected void parse()
      Parse, if necessary, the multipart stream.
      void setBufferSize​(int bufferSize)  
      void setDeleteOnExit​(boolean deleteOnExit)
      Deprecated.
      no replacement provided.
      void setWriteFilesWithFilenames​(boolean writeFilesWithFilenames)  
      protected void throwIfError()
      Throws an exception if one has been latched.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MultiPartFormInputStream

        public MultiPartFormInputStream​(java.io.InputStream in,
                                        java.lang.String contentType,
                                        jakarta.servlet.MultipartConfigElement config,
                                        java.io.File contextTmpDir)
        Parameters:
        in - Request input stream
        contentType - Content-Type header
        config - MultipartConfigElement
        contextTmpDir - jakarta.servlet.context.tempdir
    • Method Detail

      • isEmpty

        @Deprecated
        public boolean isEmpty()
        Deprecated.
        use getParts().isEmpty()
        Returns:
        whether the list of parsed parts is empty
      • deleteParts

        public void deleteParts()
        Delete any tmp storage for parts, and clear out the parts list.
      • getParts

        public java.util.Collection<jakarta.servlet.http.Part> getParts()
                                                                 throws java.io.IOException
        Parse, if necessary, the multipart data and return the list of Parts.
        Returns:
        the parts
        Throws:
        java.io.IOException - if unable to get the parts
      • getPart

        public jakarta.servlet.http.Part getPart​(java.lang.String name)
                                          throws java.io.IOException
        Get the named Part.
        Parameters:
        name - the part name
        Returns:
        the parts
        Throws:
        java.io.IOException - if unable to get the part
      • throwIfError

        protected void throwIfError()
                             throws java.io.IOException
        Throws an exception if one has been latched.
        Throws:
        java.io.IOException - the exception (if present)
      • parse

        protected void parse()
        Parse, if necessary, the multipart stream.
      • setDeleteOnExit

        @Deprecated
        public void setDeleteOnExit​(boolean deleteOnExit)
        Deprecated.
        no replacement provided.
      • setWriteFilesWithFilenames

        public void setWriteFilesWithFilenames​(boolean writeFilesWithFilenames)
      • isWriteFilesWithFilenames

        public boolean isWriteFilesWithFilenames()
      • isDeleteOnExit

        @Deprecated
        public boolean isDeleteOnExit()
        Deprecated.
        no replacement provided
      • getBufferSize

        public int getBufferSize()
        Returns:
        the size of buffer used to read data from the input stream
      • setBufferSize

        public void setBufferSize​(int bufferSize)
        Parameters:
        bufferSize - the size of buffer used to read data from the input stream