當前位置: 首頁>>代碼示例>>Java>>正文


Java StringUtils.addStringToArray方法代碼示例

本文整理匯總了Java中org.springframework.util.StringUtils.addStringToArray方法的典型用法代碼示例。如果您正苦於以下問題:Java StringUtils.addStringToArray方法的具體用法?Java StringUtils.addStringToArray怎麽用?Java StringUtils.addStringToArray使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.util.StringUtils的用法示例。


在下文中一共展示了StringUtils.addStringToArray方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: parseFileItems

import org.springframework.util.StringUtils; //導入方法依賴的package包/類
/**
 * Parse the given List of Commons FileItems into a Spring MultipartParsingResult,
 * containing Spring MultipartFile instances and a Map of multipart parameter.
 * @param fileItems the Commons FileIterms to parse
 * @param encoding the encoding to use for form fields
 * @return the Spring MultipartParsingResult
 * @see CommonsMultipartFile#CommonsMultipartFile(org.apache.commons.fileupload.FileItem)
 */
protected MultipartParsingResult parseFileItems(List<FileItem> fileItems, String encoding) {
	MultiValueMap<String, MultipartFile> multipartFiles = new LinkedMultiValueMap<String, MultipartFile>();
	Map<String, String[]> multipartParameters = new HashMap<String, String[]>();
	Map<String, String> multipartParameterContentTypes = new HashMap<String, String>();

	// 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) {
					if (logger.isWarnEnabled()) {
						logger.warn("Could not decode multipart item '" + fileItem.getFieldName() +
								"' with encoding '" + partEncoding + "': using platform default");
					}
					value = fileItem.getString();
				}
			}
			else {
				value = fileItem.getString();
			}
			String[] curParam = multipartParameters.get(fileItem.getFieldName());
			if (curParam == null) {
				// simple form field
				multipartParameters.put(fileItem.getFieldName(), new String[] {value});
			}
			else {
				// array of simple form fields
				String[] newParam = StringUtils.addStringToArray(curParam, value);
				multipartParameters.put(fileItem.getFieldName(), newParam);
			}
			multipartParameterContentTypes.put(fileItem.getFieldName(), fileItem.getContentType());
		}
		else {
			// multipart file field
			CommonsMultipartFile file = new CommonsMultipartFile(fileItem);
			multipartFiles.add(file.getName(), file);
			if (logger.isDebugEnabled()) {
				logger.debug("Found multipart file [" + file.getName() + "] of size " + file.getSize() +
						" bytes with original filename [" + file.getOriginalFilename() + "], stored " +
						file.getStorageDescription());
			}
		}
	}
	return new MultipartParsingResult(multipartFiles, multipartParameters, multipartParameterContentTypes);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:59,代碼來源:CommonsFileUploadSupport.java


注:本文中的org.springframework.util.StringUtils.addStringToArray方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。