Class AdaptiveFileUpload


  • public class AdaptiveFileUpload
    extends FileUpload
    Smart FileUpload implementation that defer the action of what to do with uploaded file for later. Internally, it stores uploaded file either in memory if it is small, or, in all other cases, it stores them in TEMP folder.
    • Field Detail

      • TMP_FILE_SUFFIX

        protected static final java.lang.String TMP_FILE_SUFFIX
        See Also:
        Constant Field Values
      • memoryThreshold

        protected final int memoryThreshold
      • uploadPath

        protected final java.io.File uploadPath
      • breakOnError

        protected final boolean breakOnError
      • fileExtensions

        protected final java.lang.String[] fileExtensions
      • allowFileExtensions

        protected final boolean allowFileExtensions
      • tempFile

        protected java.io.File tempFile
      • data

        protected byte[] data
    • Constructor Detail

      • AdaptiveFileUpload

        AdaptiveFileUpload​(MultipartRequestInputStream input,
                           int memoryThreshold,
                           java.io.File uploadPath,
                           int maxFileSize,
                           boolean breakOnError,
                           java.lang.String[] extensions,
                           boolean allowed)
    • Method Detail

      • getMemoryThreshold

        public int getMemoryThreshold()
      • getUploadPath

        public java.io.File getUploadPath()
      • isBreakOnError

        public boolean isBreakOnError()
      • getFileExtensions

        public java.lang.String[] getFileExtensions()
      • isAllowFileExtensions

        public boolean isAllowFileExtensions()
      • isInMemory

        public boolean isInMemory()
        Returns true if file upload resides in memory.
        Specified by:
        isInMemory in class FileUpload
      • matchFileExtension

        protected boolean matchFileExtension()
                                      throws java.io.IOException
        Throws:
        java.io.IOException
      • checkUpload

        protected boolean checkUpload()
                               throws java.io.IOException
        Determines if upload is allowed.
        Throws:
        java.io.IOException
      • processStream

        protected void processStream()
                              throws java.io.IOException
        Description copied from class: FileUpload
        Process request input stream. Note that file size is unknown at this point. Therefore, the implementation should set the size attribute after successful processing. This method also must set the valid attribute.
        Specified by:
        processStream in class FileUpload
        Throws:
        java.io.IOException
        See Also:
        MultipartRequestInputStream
      • delete

        public void delete()
        Deletes file uploaded item from disk or memory.
      • write

        public java.io.File write​(java.lang.String destination)
                           throws java.io.IOException
        Writes file uploaded item.
        Throws:
        java.io.IOException
      • write

        public java.io.File write​(java.io.File destination)
                           throws java.io.IOException
        Writes file upload item to destination folder or to destination file. Returns the destination file.
        Throws:
        java.io.IOException
      • getFileContent

        public byte[] getFileContent()
                              throws java.io.IOException
        Returns the content of file upload item.
        Specified by:
        getFileContent in class FileUpload
        Throws:
        java.io.IOException
      • getFileInputStream

        public java.io.InputStream getFileInputStream()
                                               throws java.io.IOException
        Description copied from class: FileUpload
        Returns input stream of uploaded file.
        Specified by:
        getFileInputStream in class FileUpload
        Throws:
        java.io.IOException