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


Java FileUploadBase.isMultipartContent方法代码示例

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


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

示例1: isMultipartContent

import org.apache.commons.fileupload.FileUploadBase; //导入方法依赖的package包/类
public static final boolean isMultipartContent(HttpRequest request) {
    String method = request.getRequestLine().getMethod();
    if (!POST_METHOD.equalsIgnoreCase(method)) {
        return false;
    }
    if (!(request instanceof HttpEntityEnclosingRequest)) {
        return false;
    }
    return FileUploadBase.isMultipartContent(new HttpServRequestContext(
            (HttpEntityEnclosingRequest) request));
}
 
开发者ID:taugin,项目名称:cim,代码行数:12,代码来源:HttpServFileUpload.java

示例2: isMultipart

import org.apache.commons.fileupload.FileUploadBase; //导入方法依赖的package包/类
@Override
public boolean isMultipart(HttpServletRequest request) {
    // support HTTP PUT operation
    String method = request.getMethod().toLowerCase();
    if (S.neq("post", method) && S.neq("put", method)) {
        return false;
    }
    return FileUploadBase.isMultipartContent(new ServletRequestContext(request));
}
 
开发者ID:rythmengine,项目名称:spring-rythm,代码行数:10,代码来源:CommonsMultipartResolver.java

示例3: isMultipartContentRequest

import org.apache.commons.fileupload.FileUploadBase; //导入方法依赖的package包/类
/**
 * Whether to allow the RequestBody with the request.
 */
public static boolean isMultipartContentRequest(HttpRequest request) {
    if (!(request instanceof HttpEntityEnclosingRequest)) return false;
    HttpEntityEnclosingRequest enclosingRequest = (HttpEntityEnclosingRequest) request;
    return isAllowRequestBody(request) && FileUploadBase.isMultipartContent(new HttpUploadContext(enclosingRequest));
}
 
开发者ID:yanzhenjie,项目名称:AndServer,代码行数:9,代码来源:HttpRequestParser.java

示例4: getStreams

import org.apache.commons.fileupload.FileUploadBase; //导入方法依赖的package包/类
/**
 *
 * @param req
 * @param rpcRequest
 * @param service
 * @return
 * @throws Exception
 */
private Map<String, InputStream> getStreams(HttpServletRequest req, RpcRequest rpcRequest, HttpAction service) throws Exception {
    if (!FileUploadBase.isMultipartContent(new ServletRequestContext(req))) {
        return null;
    }
    int streamsNumber = getInputStreamsNumber(rpcRequest, service);
    boolean isResponseStreamed = service.isBinaryResponse();
    FileItemIterator iter = (FileItemIterator) req.getAttribute(REQ_ATT_MULTIPART_ITERATOR);
    int count = 0;
    final Map<String, InputStream> map = new HashMap();
    final File tempDirectory;
    if (streamsNumber > 1 || streamsNumber == 1 && isResponseStreamed) {
        tempDirectory = createTempUploadDirectory();
        req.setAttribute(REQ_ATT_TEMPORARY_FOLDER, tempDirectory);
    } else {
        tempDirectory = null;
    }
    FileItemStream item = (FileItemStream) req.getAttribute(REQ_ATT_MULTIPART_CURRENT_ITEM);
    long availableLength = RpcConfig.getInstance().getMaxRequestSize();
    while (item != null) {
        count++;
        long maxLength = Math.min(availableLength, RpcConfig.getInstance().getMaxFileSize());
        if (count < streamsNumber || isResponseStreamed) { // if response is streamed all inputstreams have to be readed first
            File file = new File(tempDirectory, item.getFieldName());
            FileOutputStream fos = new FileOutputStream(file);
            try {
                Miscellaneous.pipeSynchronously(new LimitedLengthInputStream(item.openStream(), maxLength), fos);
            } catch (MaxLengthExceededException ex) {
                if (maxLength == RpcConfig.getInstance().getMaxFileSize()) {
                    throw new MaxLengthExceededException("Upload part '" + item.getFieldName() + "' exceeds maximum length (" + RpcConfig.getInstance().getMaxFileSize() + " bytes)", RpcConfig.getInstance().getMaxFileSize());
                } else {
                    throw new MaxLengthExceededException("Request exceeds maximum length (" + RpcConfig.getInstance().getMaxRequestSize() + " bytes)", RpcConfig.getInstance().getMaxRequestSize());
                }
            }
            map.put(item.getFieldName(), new MetaDataInputStream(new FileInputStream(file), item.getName(), item.getContentType(), file.length(), null));
            availableLength -= file.length();
        } else if (count == streamsNumber) {
            map.put(item.getFieldName(), new MetaDataInputStream(new LimitedLengthInputStream(item.openStream(), maxLength), item.getName(), item.getContentType(), null, null));
            break;
        }
        req.setAttribute(REQ_ATT_MULTIPART_CURRENT_ITEM, item);
        if (iter.hasNext()) {
            item = iter.next();
        } else {
            item = null;
        }
    }
    if (count != streamsNumber) {
        throw new IllegalArgumentException("Invalid multipart request received. Number of uploaded files (" + count + ") does not match expected (" + streamsNumber + ")");
    }
    return map;
}
 
开发者ID:brutusin,项目名称:Brutusin-RPC,代码行数:60,代码来源:RpcServlet.java

示例5: isMultipart

import org.apache.commons.fileupload.FileUploadBase; //导入方法依赖的package包/类
/**
 * Determine if given request is multipart.
 */
public static boolean isMultipart(final HttpServletRequest httpRequest) {
  // We're circumventing ServletFileUpload.isMultipartContent as some clients (nuget) use PUT for multipart uploads
  return FileUploadBase.isMultipartContent(new ServletRequestContext(httpRequest));
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:8,代码来源:HttpPartIteratorAdapter.java

示例6: doFilter

import org.apache.commons.fileupload.FileUploadBase; //导入方法依赖的package包/类
/**
 * Filter the current request. If it is a multipart request, parse it and
 * wrap it before chaining to the next filter or servlet. Otherwise, pass
 * it on untouched.
 */
@Override
@SuppressWarnings("unchecked")
public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
	throws IOException, ServletException
{
	if (!FileUploadBase.isMultipartContent(request))
	{
		chain.doFilter(request, response);
		return;
	}

	try
	{
		//FileItemFactory fact = new DiskFileItemFactory();
		//FileUpload upload = new ServletFileUpload(fact);
		DiskFileUpload upload = new DiskFileUpload();
		upload.setSizeMax(MAX_UPLOAD_BYTES);

		List<FileItem> items = upload.parseRequest(request);

		Map<String, String[]> params = new HashMap<String, String[]>();
		List<FileItem> files = new ArrayList<FileItem>(items.size());

		for (FileItem item: items)
		{
			if (item.isFormField())
			{
				// Add it to the array in the params, creating the array if necessary
				String[] array = params.get(item.getFieldName());
				if (array == null)
				{
					array = new String[] { item.getString() };
				}
				else
				{
					String[] newArray = new String[array.length + 1];
					System.arraycopy(array, 0, newArray, 0, array.length);
					newArray[newArray.length - 1] = item.getString();

					array = newArray;
				}

				params.put(item.getFieldName(), array);
			}
			else
				files.add(item);
		}

		request.setAttribute(ATTR_FILES, files);
		HttpServletRequest wrapped = new RequestWrapper(request, params);

		chain.doFilter(wrapped, response);
	}
	catch (FileUploadException ex)
	{
		// Just save the exception for later.
		request.setAttribute(ATTR_EXCEPTION, ex);

		chain.doFilter(request, response);
	}
}
 
开发者ID:voodoodyne,项目名称:subetha,代码行数:67,代码来源:FileUploadFilter.java

示例7: isMultipartContent

import org.apache.commons.fileupload.FileUploadBase; //导入方法依赖的package包/类
/**
 * Utility method that determines whether the request contains multipart
 * content.
 *
 * @param request The servlet request to be evaluated. Must be non-null.
 *
 * @return <code>true</code> if the request is multipart;
 *         <code>false</code> otherwise.
 */
public static final boolean isMultipartContent(
        HttpServletRequest request) {
    if (!POST_METHOD.equalsIgnoreCase(request.getMethod())) {
        return false;
    }
    return FileUploadBase.isMultipartContent(new ServletRequestContext(request));
}
 
开发者ID:PuppyRush,项目名称:WidgetStore,代码行数:17,代码来源:ServletFileUpload.java

示例8: isMultipartContent

import org.apache.commons.fileupload.FileUploadBase; //导入方法依赖的package包/类
/**
 * Utility method that determines whether the request contains multipart
 * content.
 *
 * @param request The portlet request to be evaluated. Must be non-null.
 *
 * @return <code>true</code> if the request is multipart;
 *         <code>false</code> otherwise.
 */
public static final boolean isMultipartContent(ActionRequest request) {
    return FileUploadBase.isMultipartContent(
            new PortletRequestContext(request));
}
 
开发者ID:PuppyRush,项目名称:WidgetStore,代码行数:14,代码来源:PortletFileUpload.java


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