protected MultipartParsingResult parseFileItems ( List < FileItem > fileItems , String encoding ) { MultiValueMap < String , MultipartFile > multipartFiles = new LinkedMultiValueMap <> ( ) ; MultiValueMap < String , String > multipartParameters = new LinkedMultiValueMap <> ( ) ; Map < String , String > multipartContentTypes = new HashMap <> ( ) ; // Extract multipart files and multipart parameters. for ( FileItem fileItem : fileItems ) { if ( fileItem . isFormField ( ) ) { String value ; String partEncoding = determineEncoding ( fileItem . getContentType ( ) , encoding ) ; if ( partEncoding != null ) { try { value = fileItem . getString ( partEncoding ) ; } catch ( UnsupportedEncodingException ex ) { value = fileItem . getString ( ) ; } } else { value = fileItem . getString ( ) ; } List < String > curParam = multipartParameters . get ( fileItem . getFieldName ( ) ) ; if ( curParam == null ) { // Simple form field. curParam = new LinkedList <> ( ) ; curParam . add ( value ) ; multipartParameters . put ( fileItem . getFieldName ( ) , curParam ) ; } else { // Array of simple form fields. curParam . add ( value ) ; } multipartContentTypes . put ( fileItem . getFieldName ( ) , fileItem . getContentType ( ) ) ; } else { StandardMultipartFile file = createMultipartFile ( fileItem ) ; multipartFiles . add ( file . getName ( ) , file ) ; } } return new MultipartParsingResult ( multipartFiles , multipartParameters , multipartContentTypes ) ; }
Parse the given List of Commons FileItems into a MultipartParsingResult containing MultipartFile instances and a Map of multipart parameter .