当前位置: 首页>>代码示例>>Java>>正文


Java FileItem.getContentType方法代码示例

本文整理汇总了Java中org.apache.commons.fileupload.FileItem.getContentType方法的典型用法代码示例。如果您正苦于以下问题:Java FileItem.getContentType方法的具体用法?Java FileItem.getContentType怎么用?Java FileItem.getContentType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.fileupload.FileItem的用法示例。


在下文中一共展示了FileItem.getContentType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: FileData

import org.apache.commons.fileupload.FileItem; //导入方法依赖的package包/类
FileData(FileItem item)
{
	this.fileName = item.getName();
	this.type = item.getContentType();
	this.data = item.get();
	
	if(fileName != null)
	{
		int i = fileName.lastIndexOf("/");
		if(i>0)
		{
			fileName = fileName.substring(i+1);
		}
		else
		{
			i = fileName.lastIndexOf("\\");
			if(i>0)
    		{
    			fileName = fileName.substring(i+1);
    		}
		}
	}
	
	this.item = item;
}
 
开发者ID:fancimage,项目名称:tern,代码行数:26,代码来源:FileData.java

示例2: HttpUploadReader

import org.apache.commons.fileupload.FileItem; //导入方法依赖的package包/类
HttpUploadReader(FileItem item) throws IOException {
    this.item = item;
    fieldName = item.getFieldName();
    fileName = item.getName();
    contentType = item.getContentType();
    size = item.getSize();
    inputStream = item.getInputStream();
}
 
开发者ID:heisedebaise,项目名称:tephra,代码行数:9,代码来源:HttpUploadReader.java

示例3: createParam

import org.apache.commons.fileupload.FileItem; //导入方法依赖的package包/类
/**
 * 创建请求对象
 */
public static Param createParam(HttpServletRequest request) throws IOException {
    List<FormParam> formParamList = new ArrayList<FormParam>();
    List<FileParam> fileParamList = new ArrayList<FileParam>();
    try{
        Map<String, List<FileItem>> fileItemListMap = servletFileUpload.parseParameterMap(request);
        if (CollectionUtil.isNotEmpty(fileItemListMap)) {
            for (Map.Entry<String, List<FileItem>> fileItemListEntry : fileItemListMap.entrySet()) {
                String fieldName = fileItemListEntry.getKey();
                List<FileItem> fileItemList = fileItemListEntry.getValue();
                if (CollectionUtil.isNotEmpty(fileItemList)) {
                    for (FileItem fileItem : fileItemList) {
                        if(fileItem.isFormField()){
                            String fieldValue = fileItem.getString("UTF-8");
                            formParamList.add(new FormParam(fieldName, fieldValue));
                        } else{
                            String fileName = FileUtil.getRealFileName(new String(fileItem.getName().getBytes(), "UTF-8"));
                            if (StringUtil.isNotEmpty(fileName)) {
                                long fileSize = fileItem.getSize();
                                String contentType = fileItem.getContentType();
                                InputStream inputSteam = fileItem.getInputStream();
                                fileParamList.add(new FileParam(fieldName, fileName, fileSize, contentType, inputSteam));
                            }
                        }
                    }
                }
            }
        }
    }catch (FileUploadException e){
        LOGGER.error("create param failure", e);
        throw new RuntimeException(e);
    }
    return new Param(formParamList, fileParamList);
}
 
开发者ID:edagarli,项目名称:Nicole,代码行数:37,代码来源:UploadHelper.java

示例4: createMultipartParamList

import org.apache.commons.fileupload.FileItem; //导入方法依赖的package包/类
public static List<Object> createMultipartParamList(HttpServletRequest request) throws Exception {
    // 定义参数列表
    List<Object> paramList = new ArrayList<Object>();
    // 创建两个对象,分别对应 普通字段 与 文件字段
    Map<String, String> fieldMap = new HashMap<String, String>();
    List<Multipart> multipartList = new ArrayList<Multipart>();
    // 获取并遍历表单项
    List<FileItem> fileItemList;
    try {
        fileItemList = fileUpload.parseRequest(request);
    } catch (FileUploadBase.FileSizeLimitExceededException e) {
        // 异常转换(抛出自定义异常)
        throw new UploadException(e);
    }
    for (FileItem fileItem : fileItemList) {
        // 分两种情况处理表单项
        String fieldName = fileItem.getFieldName();
        if (fileItem.isFormField()) {
            // 处理普通字段
            String fieldValue = fileItem.getString(FrameworkConstant.DEFAULT_CHARSET);
            fieldMap.put(fieldName, fieldValue);
        } else {
            // 处理文件字段
            String originalFileName = FileUtil.getRealFileName(fileItem.getName());
            String uploadedFileName = FileUtil.getEncodedFileName(originalFileName);
            String contentType = fileItem.getContentType();
            long fileSize = fileItem.getSize();
            InputStream inputSteam = fileItem.getInputStream();
            // 创建 Multipart 对象,并将其添加到 multipartList 中
            Multipart multipart = new Multipart(uploadedFileName, contentType, fileSize, inputSteam);
            multipartList.add(multipart);
            // 将所上传文件的文件名存入 fieldMap 中
            fieldMap.put(fieldName, uploadedFileName);
        }
    }
    // 初始化参数列表
    paramList.add(fieldMap);
    if (multipartList.size() > 1) {
        paramList.add(multipartList);
    } else if (multipartList.size() == 1) {
        paramList.add(multipartList.get(0));
    } else {
        paramList.add(null);
    }
    // 返回参数列表
    return paramList;
}
 
开发者ID:thinkhoon,项目名称:tkhoon,代码行数:48,代码来源:UploadHelper.java

示例5: getFileParameterValue

import org.apache.commons.fileupload.FileItem; //导入方法依赖的package包/类
/**
 * Responsible for constructing a FileBean object for the named file parameter. If there is no
 * file parameter with the specified name this method should return null.
 *
 * @param name the name of the file parameter
 * @return a FileBean object wrapping the uploaded file
 */
public FileBean getFileParameterValue(String name) {
    final FileItem item = this.files.get(name);
    if (item == null
            || ((item.getName() == null || item.getName().length() == 0) && item.getSize() == 0)) {
        return null;
    }
    else {
        // Attempt to ensure the file name is just the basename with no path included
        String filename = item.getName();
        int index;
        if (WINDOWS_PATH_PREFIX_PATTERN.matcher(filename).find())
            index = filename.lastIndexOf('\\');
        else
            index = filename.lastIndexOf('/');
        if (index >= 0 && index + 1 < filename.length() - 1)
            filename = filename.substring(index + 1);

        // Use an anonymous inner subclass of FileBean that overrides all the
        // methods that rely on having a File present, to use the FileItem
        // created by commons upload instead.
        return new FileBean(null, item.getContentType(), filename, this.charset) {
            @Override public long getSize() { return item.getSize(); }

            @Override public InputStream getInputStream() throws IOException {
                return item.getInputStream();
            }

            @Override public void save(File toFile) throws IOException {
                try {
                    item.write(toFile);
                    delete();
                }
                catch (Exception e) {
                    if (e instanceof IOException) throw (IOException) e;
                    else {
                        IOException ioe = new IOException("Problem saving uploaded file.");
                        ioe.initCause(e);
                        throw ioe;
                    }
                }
            }

            @Override
            public void delete() throws IOException { item.delete(); }
        };
    }
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:55,代码来源:CommonsMultipartWrapper.java


注:本文中的org.apache.commons.fileupload.FileItem.getContentType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。