本文整理汇总了Java中org.apache.commons.fileupload.disk.DiskFileItemFactory.DEFAULT_SIZE_THRESHOLD属性的典型用法代码示例。如果您正苦于以下问题:Java DiskFileItemFactory.DEFAULT_SIZE_THRESHOLD属性的具体用法?Java DiskFileItemFactory.DEFAULT_SIZE_THRESHOLD怎么用?Java DiskFileItemFactory.DEFAULT_SIZE_THRESHOLD使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.commons.fileupload.disk.DiskFileItemFactory
的用法示例。
在下文中一共展示了DiskFileItemFactory.DEFAULT_SIZE_THRESHOLD属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
public static void init(ServletContext servletContext) {
// 获取一个临时目录(使用 Tomcat 的 work 目录)
File repository = (File) servletContext.getAttribute("javax.servlet.context.tempdir");
// 创建 FileUpload 对象
fileUpload = new ServletFileUpload(new DiskFileItemFactory(DiskFileItemFactory.DEFAULT_SIZE_THRESHOLD, repository));
// 设置上传限制
if (uploadLimit != 0) {
fileUpload.setFileSizeMax(uploadLimit * 1024 * 1024); // 单位为 M
if (logger.isDebugEnabled()) {
logger.debug("[Smart] limit of uploading: {}M", uploadLimit);
}
}
}
示例2: init
/**
* 初始化
*/
public static void init(ServletContext servletContext) {
File repository = (File) servletContext.getAttribute("javax.servlet.context.tempdir");
servletFileUpload = new ServletFileUpload(new DiskFileItemFactory(DiskFileItemFactory.DEFAULT_SIZE_THRESHOLD, repository));
int uploadLimit = ConfigHelper.getAppUploadLimit();
if (uploadLimit != 0) {
servletFileUpload.setFileSizeMax(uploadLimit * 1024 * 1024);
}
}
示例3: init
public static void init(ServletContext servletContext) {
// 获取一个临时目录(使用 Tomcat 的 work 目录)
File repository = (File) servletContext.getAttribute("javax.servlet.context.tempdir");
// 创建 FileUpload 对象
fileUpload = new ServletFileUpload(new DiskFileItemFactory(DiskFileItemFactory.DEFAULT_SIZE_THRESHOLD, repository));
// 设置上传限制
int uploadLimit = FrameworkConstant.UPLOAD_LIMIT;
if (uploadLimit != 0) {
fileUpload.setFileSizeMax(uploadLimit * 1024 * 1024);
}
}
示例4: HttpRequestServletImpl
public HttpRequestServletImpl(HttpMethod httpMethod, HttpServletRequest request) throws IOException {
this.request = request;
this.httpMethod = httpMethod;
if (ServletFileUpload.isMultipartContent(request)) {
FileItemFactory fileItemFactory = new DiskFileItemFactory(
DiskFileItemFactory.DEFAULT_SIZE_THRESHOLD,
new File(System.getProperty("java.io.tmpdir"))
);
ServletFileUpload fileUpload = new ServletFileUpload(fileItemFactory);
try {
this.bodyParameters = fileUpload.parseParameterMap(request);
} catch (FileUploadException e) {
throw new IOException(e);
}
} else {
if (request.getMethod().equals("POST") || request.getMethod().equals("PUT")) {
String contentType = request.getHeader("Content-Type");
if (contentType != null && contentType.contains("application/x-www-form-urlencoded")) {
this.bodyParameters = new HashMap<>();
String[] parameters = IOUtils.readStreamAsString(request.getInputStream()).split("&");
for (String parameter : parameters) {
String[] keyVal = parameter.split("=");
if (keyVal.length == 2) {
String key = keyVal[0];
String value = URLDecoder.decode(keyVal[1], "UTF-8");
List<FileItem> items = new ArrayList<>();
items.add(new FormFileItem(key, value));
this.bodyParameters.put(key, items);
}
}
} else {
this.inputStream = request.getInputStream();
}
}
}
this.queryParameters = request.getParameterMap();
}
示例5: initializeMultiPart
private void initializeMultiPart(PageContext pc, boolean scriptProteced) {
// get temp directory
Resource tempDir = ((ConfigImpl)pc.getConfig()).getTempDirectory();
Resource tempFile;
// Create a new file upload handler
final String encoding=getEncoding();
FileItemFactory factory = tempDir instanceof File?
new DiskFileItemFactory(DiskFileItemFactory.DEFAULT_SIZE_THRESHOLD,(File)tempDir):
new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setHeaderEncoding(encoding);
//ServletRequestContext c = new ServletRequestContext(pc.getHttpServletRequest());
HttpServletRequest req = pc.getHttpServletRequest();
ServletRequestContext context = new ServletRequestContext(req) {
public String getCharacterEncoding() {
return encoding;
}
};
// Parse the request
try {
FileItemIterator iter = upload.getItemIterator(context);
//byte[] value;
InputStream is;
ArrayList<URLItem> list=new ArrayList<URLItem>();
String fileName;
while (iter.hasNext()) {
FileItemStream item = iter.next();
is=IOUtil.toBufferedInputStream(item.openStream());
if (item.getContentType()==null || StringUtil.isEmpty(item.getName())) {
list.add(new URLItem(item.getFieldName(),new String(IOUtil.toBytes(is),encoding),false));
}
else {
fileName=getFileName();
tempFile=tempDir.getRealResource(fileName);
_fileItems.put(fileName,
new Item(tempFile,item.getContentType(),item.getName(),item.getFieldName()));
String value=tempFile.toString();
IOUtil.copy(is, tempFile,true);
list.add(new URLItem(item.getFieldName(),value,false));
}
}
raw= list.toArray(new URLItem[list.size()]);
fillDecoded(raw,encoding,scriptProteced,pc.getApplicationContext().getSameFieldAsArray(SCOPE_FORM));
}
catch (Exception e) {
//throw new PageRuntimeException(Caster.toPageException(e));
fillDecodedEL(new URLItem[0],encoding,scriptProteced,pc.getApplicationContext().getSameFieldAsArray(SCOPE_FORM));
initException=e;
}
}
示例6: initializeMultiPart
private void initializeMultiPart(PageContext pc, boolean scriptProteced) {
// get temp directory
Resource tempDir = ((ConfigImpl)pc.getConfig()).getTempDirectory();
Resource tempFile;
// Create a new file upload handler
final String encoding=getEncoding();
FileItemFactory factory = tempDir instanceof File?
new DiskFileItemFactory(DiskFileItemFactory.DEFAULT_SIZE_THRESHOLD,(File)tempDir):
new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setHeaderEncoding(encoding);
//ServletRequestContext c = new ServletRequestContext(pc.getHttpServletRequest());
HttpServletRequest req = pc.getHttpServletRequest();
ServletRequestContext context = new ServletRequestContext(req) {
@Override
public String getCharacterEncoding() {
return encoding;
}
};
// Parse the request
try {
FileItemIterator iter = upload.getItemIterator(context);
//byte[] value;
InputStream is;
ArrayList<URLItem> list=new ArrayList<URLItem>();
String fileName;
while (iter.hasNext()) {
FileItemStream item = iter.next();
is=IOUtil.toBufferedInputStream(item.openStream());
if (item.getContentType()==null || StringUtil.isEmpty(item.getName())) {
list.add(new URLItem(item.getFieldName(),new String(IOUtil.toBytes(is),encoding),false));
}
else {
fileName=getFileName();
tempFile=tempDir.getRealResource(fileName);
_fileItems.put(fileName,
new Item(tempFile,item.getContentType(),item.getName(),item.getFieldName()));
String value=tempFile.toString();
IOUtil.copy(is, tempFile,true);
list.add(new URLItem(item.getFieldName(),value,false));
}
}
raw= list.toArray(new URLItem[list.size()]);
fillDecoded(raw,encoding,scriptProteced,pc.getApplicationContext().getSameFieldAsArray(SCOPE_FORM));
}
catch (Exception e) {
//throw new PageRuntimeException(Caster.toPageException(e));
fillDecodedEL(new URLItem[0],encoding,scriptProteced,pc.getApplicationContext().getSameFieldAsArray(SCOPE_FORM));
initException=e;
}
}
示例7: KvantumFileUpload
/**
* Initialize a new file upload handler that stores the uploaded
* file in a temporary file, with the default {@link DiskFileItemFactory#DEFAULT_SIZE_THRESHOLD}
* size threshold
*/
public KvantumFileUpload()
{
this( DiskFileItemFactory.DEFAULT_SIZE_THRESHOLD );
}