本文整理汇总了Java中org.apache.commons.fileupload.ParameterParser类的典型用法代码示例。如果您正苦于以下问题:Java ParameterParser类的具体用法?Java ParameterParser怎么用?Java ParameterParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ParameterParser类属于org.apache.commons.fileupload包,在下文中一共展示了ParameterParser类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCharSet
import org.apache.commons.fileupload.ParameterParser; //导入依赖的package包/类
/**
* Returns the content charset passed by the agent or <code>null</code> if
* not defined.
*
* @return The content charset passed by the agent or <code>null</code> if
* not defined.
*/
public String getCharSet() {
ParameterParser parser = new ParameterParser();
parser.setLowerCaseNames(true);
// Parameter parser can handle null input
Map<String, String> params = parser.parse(getContentType(), ';');
return params.get("charset");
}
示例2: upload
import org.apache.commons.fileupload.ParameterParser; //导入依赖的package包/类
/**
* ueditor上传文件
*
* @return 上传结果
* @throws IOException 文件上传错误
*/
@RequestMapping(method = RequestMethod.POST, consumes = "multipart/form-data")
@ApiOperation("上传文件")
public String upload(@RequestParam(value = "upfile", required = false) MultipartFile file,HttpServletRequest request) throws IOException {
String fileName = file.getOriginalFilename();
String contentType = Optional.ofNullable(request)
.orElseThrow(UnsupportedOperationException::new)
.getContentType();
ParameterParser parser = new ParameterParser();
Map<String, String> params = parser.parse(contentType, ';');
if (params.get("charset") == null) {
try {
fileName = new String(file.getOriginalFilename().getBytes("ISO-8859-1"), "utf-8");
} catch (@SuppressWarnings("all") UnsupportedEncodingException ignore) {
}
}
String suffix = FileType.getSuffixByFilename(fileName);
String path = fileService.saveStaticFile(file.getInputStream(), System.currentTimeMillis() + suffix);
State state = new BaseState(true);
state.putInfo("size", file.getSize());
state.putInfo("title",fileName);
state.putInfo("url", path);
state.putInfo("type", suffix);
state.putInfo("original",fileName);
return state.toJSONString();
}
示例3: getFileName
import org.apache.commons.fileupload.ParameterParser; //导入依赖的package包/类
private String getFileName(String pContentDisposition) {
String fileName = null;
if (pContentDisposition != null) {
String cdl = pContentDisposition.toLowerCase();
if (cdl.startsWith(FORM_DATA) || cdl.startsWith(ATTACHMENT)) {
ParameterParser parser = new ParameterParser();
parser.setLowerCaseNames(true);
// Parameter parser can handle null input
@SuppressWarnings("unchecked")
Map<String, String> params = parser.parse(pContentDisposition, ';');
// 解决类似Flash上传更改了filename 为 fname 的多客户端支持
for (String key : getFileNameKey()) {
fileName = StringUtils.trimToNull(params.get(key));
if (fileName != null) {
break;
}
}
}
}
return fileName;
}
示例4: getCharSet
import org.apache.commons.fileupload.ParameterParser; //导入依赖的package包/类
/**
* Returns the content charset passed by the agent or <code>null</code> if
* not defined.
*
* @return The content charset passed by the agent or <code>null</code> if
* not defined.
*/
public String getCharSet()
{
ParameterParser parser = new ParameterParser();
parser.setLowerCaseNames(true);
// Parameter parser can handle null input
Map params = parser.parse(getContentType(), ';');
return (String) params.get("charset");
}
示例5: upload
import org.apache.commons.fileupload.ParameterParser; //导入依赖的package包/类
/**
* 上传单个文件
*
* @param file 上传文件
* @return 上传结果
*/
@PostMapping(value = "/upload")
@AccessLogger("上传单个文件")
@Authorize(action = "upload", description = "上传文件")
public ResponseMessage<FileInfoEntity> upload(@RequestPart("file") MultipartFile file) {
List<FileInfoEntity> fileInfoList = new LinkedList<>();
Authentication authentication = Authentication.current().orElse(null);
String creator = authentication == null ? null : authentication.getUser().getId();
if (file.isEmpty()) {
return ResponseMessage.ok();
}
String fileName = file.getOriginalFilename();
String contentType = Optional.ofNullable(WebUtil.getHttpServletRequest())
.orElseThrow(UnsupportedOperationException::new)
.getContentType();
ParameterParser parser = new ParameterParser();
Map<String, String> params = parser.parse(contentType, ';');
if (params.get("charset") == null) {
try {
fileName = new String(file.getOriginalFilename().getBytes("ISO-8859-1"), "utf-8");
} catch (@SuppressWarnings("all") UnsupportedEncodingException ignore) {
}
}
if (logger.isInfoEnabled()) {
logger.info("start write file:{}", fileName);
}
FileInfoEntity fileInfo;
try {
fileInfo = fileService.saveFile(file.getInputStream(), fileName, file.getContentType(), creator);
} catch (IOException e) {
throw new BusinessException("save file error", e);
}
fileInfoList.add(fileInfo);
return ResponseMessage.ok(fileInfo)
.include(FileInfoEntity.class, FileInfoEntity.id,
FileInfoEntity.name,
FileInfoEntity.md5,
FileInfoEntity.size,
FileInfoEntity.type);
}
示例6: parse
import org.apache.commons.fileupload.ParameterParser; //导入依赖的package包/类
/**
* @brief 解析请求的get信息
* @param request Http请求
* @return 名称与值的Map集合
* @throws IOException
* @warning 需保证是post请求且不是multipart的。
*/
public Map<String, String> parse(HttpRequest request) {
ParameterParser parser = new ParameterParser();
parser.setLowerCaseNames(true);
return parser.parse(getContent(request), '&');
}
示例7: parse
import org.apache.commons.fileupload.ParameterParser; //导入依赖的package包/类
/**
* @brief 解析请求的post信息
* @param request Http请求
* @return 名称与值的Map集合
* @throws IOException
* @warning 需保证是post请求且不是multipart的。
*/
public Map<String, String> parse(HttpRequest request) throws IOException {
ParameterParser parser = new ParameterParser();
parser.setLowerCaseNames(true);
return parser.parse(getContent(request), '&');
}