本文整理汇总了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));
}
示例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));
}
示例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));
}
示例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;
}
示例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));
}
示例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);
}
}
示例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));
}
示例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));
}