當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。