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


Java DiskFileItemFactory.DEFAULT_SIZE_THRESHOLD属性代码示例

本文整理汇总了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);
        }
    }
}
 
开发者ID:thinkhoon,项目名称:tkhoon,代码行数:13,代码来源:UploadHelper.java

示例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);
    }
}
 
开发者ID:edagarli,项目名称:Nicole,代码行数:11,代码来源:UploadHelper.java

示例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);
    }
}
 
开发者ID:wsldl123292,项目名称:testeverything,代码行数:11,代码来源:UploadHelper.java

示例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();
}
 
开发者ID:mindie,项目名称:Cindy,代码行数:39,代码来源:HttpRequestServletImpl.java

示例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;
	}
}
 
开发者ID:lucee,项目名称:Lucee4,代码行数:59,代码来源:FormImpl.java

示例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;
	}
}
 
开发者ID:lucee,项目名称:Lucee,代码行数:60,代码来源:FormImpl.java

示例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 );
}
 
开发者ID:Sauilitired,项目名称:Kvantum,代码行数:9,代码来源:KvantumFileUpload.java


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