Java 类org.apache.commons.fileupload.ParameterParser 实例源码

项目:gitplex-mit    文件:DiskFileItem.java   
/**
 * 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");
}
项目:hsweb-framework    文件:UeditorController.java   
/**
 * 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();
}
项目:WidgetStore    文件:DiskFileItem.java   
/**
 * 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");
}
项目:wmix    文件:ServletFileUpload.java   
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;
}
项目:cim    文件:DiskFileItem.java   
/**
 * 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");
}
项目:AndroidWebServ    文件:DiskFileItem.java   
/**
 * 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");
}
项目:gae-java-template    文件:InMemoryFileItem.java   
/**
 * 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");
}
项目:hsweb-framework    文件:FileController.java   
/**
 * 上传单个文件
 *
 * @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);
}
项目:cim    文件:HttpGetParser.java   
/**
 * @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), '&');
}
项目:cim    文件:HttpPostParser.java   
/**
 * @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), '&');
}
项目:AndroidWebServ    文件:HttpGetParser.java   
/**
 * @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), '&');
}
项目:AndroidWebServ    文件:HttpPostParser.java   
/**
 * @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), '&');
}