Class FileUploadUtil


  • public class FileUploadUtil
    extends Object
    Utility class for file uploading.
    Author:
    ehugonnet
    • Method Detail

      • isRequestMultipart

        public static boolean isRequestMultipart​(javax.servlet.http.HttpServletRequest request)
      • parseRequest

        public static List<org.apache.commons.fileupload.FileItem> parseRequest​(javax.servlet.http.HttpServletRequest request)
                                                                         throws UtilException
        Parses the multipart stream in the specified request to fetch the file items. This method shouldn't be used directly; instead use the HttpRequest instance.
        Parameters:
        request - the HTTP servlet request.
        Returns:
        a list of file items encoded into the multipart stream of the request.
        Throws:
        UtilException - if an error occurs while fetching the file items.
      • getParameter

        public static String getParameter​(List<org.apache.commons.fileupload.FileItem> items,
                                          String parameterName,
                                          String defaultValue,
                                          String encoding)
        Get the parameter value from the list of FileItems. Returns the defaultValue if the parameter is not found.
        Parameters:
        items - the items resulting from parsing the request.
        parameterName -
        defaultValue - the value to be returned if the parameter is not found.
        encoding - the request encoding.
        Returns:
        the parameter value from the list of FileItems. Returns the defaultValue if the parameter is not found.
      • getParameterValues

        public static List<String> getParameterValues​(List<org.apache.commons.fileupload.FileItem> items,
                                                      String parameterName,
                                                      String encoding)
      • getParameter

        public static String getParameter​(List<org.apache.commons.fileupload.FileItem> items,
                                          String parameterName,
                                          String defaultValue)
        Get the parameter value from the list of FileItems. Returns the defaultValue if the parameter is not found.
        Parameters:
        items - the items resulting from parsing the request.
        parameterName -
        defaultValue - the value to be returned if the parameter is not found.
        Returns:
        the parameter value from the list of FileItems. Returns the defaultValue if the parameter is not found.
      • getParameter

        public static String getParameter​(List<org.apache.commons.fileupload.FileItem> items,
                                          String parameterName)
        Get the parameter value from the list of FileItems. Returns null if the parameter is not found.
        Parameters:
        items - the items resulting from parsing the request.
        parameterName -
        Returns:
        the parameter value from the list of FileItems. Returns null if the parameter is not found.
      • getOldParameter

        public static String getOldParameter​(List items,
                                             String parameterName)
      • getOldParameter

        public static String getOldParameter​(List items,
                                             String parameterName,
                                             String defaultValue)
      • getOldFile

        public static org.apache.commons.fileupload.FileItem getOldFile​(List items,
                                                                        String parameterName)
      • getFile

        public static org.apache.commons.fileupload.FileItem getFile​(List<org.apache.commons.fileupload.FileItem> items,
                                                                     String parameterName)
      • getFile

        public static org.apache.commons.fileupload.FileItem getFile​(List<org.apache.commons.fileupload.FileItem> items)
      • getFile

        public static org.apache.commons.fileupload.FileItem getFile​(javax.servlet.http.HttpServletRequest request)
                                                              throws UtilException
        Throws:
        UtilException
      • getFileName

        public static String getFileName​(org.apache.commons.fileupload.FileItem file)
      • saveToFile

        public static void saveToFile​(File file,
                                      org.apache.commons.fileupload.FileItem item)
                               throws IOException
        Throws:
        IOException