當前位置: 首頁>>代碼示例>>Java>>正文


Java DiskFileItemFactory.setRepository方法代碼示例

本文整理匯總了Java中org.apache.commons.fileupload.disk.DiskFileItemFactory.setRepository方法的典型用法代碼示例。如果您正苦於以下問題:Java DiskFileItemFactory.setRepository方法的具體用法?Java DiskFileItemFactory.setRepository怎麽用?Java DiskFileItemFactory.setRepository使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.fileupload.disk.DiskFileItemFactory的用法示例。


在下文中一共展示了DiskFileItemFactory.setRepository方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getFileItemList

import org.apache.commons.fileupload.disk.DiskFileItemFactory; //導入方法依賴的package包/類
/** 獲取所有文本域 */
public static final List<?> getFileItemList(HttpServletRequest request, File saveDir) throws FileUploadException {
    if (!saveDir.isDirectory()) {
        saveDir.mkdir();
    }
    List<?> fileItems = null;
    RequestContext requestContext = new ServletRequestContext(request);
    if (FileUpload.isMultipartContent(requestContext)) {
        DiskFileItemFactory factory = new DiskFileItemFactory();
        factory.setRepository(saveDir);
        factory.setSizeThreshold(fileSizeThreshold);
        ServletFileUpload upload = new ServletFileUpload(factory);
        fileItems = upload.parseRequest(request);
    }
    return fileItems;
}
 
開發者ID:iBase4J,項目名稱:iBase4J-Common,代碼行數:17,代碼來源:UploadUtil.java

示例2: getFileItemList

import org.apache.commons.fileupload.disk.DiskFileItemFactory; //導入方法依賴的package包/類
/** 獲取所有文本域 */
public static final List<?> getFileItemList(HttpServletRequest request, File saveDir) throws FileUploadException {
	if (!saveDir.isDirectory()) {
		saveDir.mkdir();
	}
	List<?> fileItems = null;
	RequestContext requestContext = new ServletRequestContext(request);
	if (FileUpload.isMultipartContent(requestContext)) {
		DiskFileItemFactory factory = new DiskFileItemFactory();
		factory.setRepository(saveDir);
		factory.setSizeThreshold(fileSizeThreshold);
		ServletFileUpload upload = new ServletFileUpload(factory);
		fileItems = upload.parseRequest(request);
	}
	return fileItems;
}
 
開發者ID:youngMen1,項目名稱:JAVA-,代碼行數:17,代碼來源:UploadUtil.java

示例3: getFileItemList

import org.apache.commons.fileupload.disk.DiskFileItemFactory; //導入方法依賴的package包/類
/** 獲取所有文本域 */
public static List<?> getFileItemList(HttpServletRequest request, File saveDir) throws FileUploadException {
	if (!saveDir.isDirectory()) {
		saveDir.mkdir();
	}
	List<?> fileItems = null;
	RequestContext requestContext = new ServletRequestContext(request);
	if (FileUpload.isMultipartContent(requestContext)) {
		DiskFileItemFactory factory = new DiskFileItemFactory();
		factory.setRepository(saveDir);
		factory.setSizeThreshold(fileSizeThreshold);
		ServletFileUpload upload = new ServletFileUpload(factory);
		fileItems = upload.parseRequest(request);
	}
	return fileItems;
}
 
開發者ID:haizicq,項目名稱:osframe,代碼行數:17,代碼來源:UploadUtil.java

示例4: createDiskFileItemFactory

import org.apache.commons.fileupload.disk.DiskFileItemFactory; //導入方法依賴的package包/類
protected DiskFileItemFactory createDiskFileItemFactory(String saveDir) {
    DiskFileItemFactory fac = new DiskFileItemFactory();
    // Make sure that the data is written to file
    fac.setSizeThreshold(0);
    if (saveDir != null) {
        fac.setRepository(new File(saveDir));
    }
    return fac;
}
 
開發者ID:txazo,項目名稱:struts2,代碼行數:10,代碼來源:JakartaMultiPartRequest.java

示例5: getMultipartContentItems

import org.apache.commons.fileupload.disk.DiskFileItemFactory; //導入方法依賴的package包/類
private List<FileItem> getMultipartContentItems() throws IOException, FileUploadException {
  List<FileItem> items = null;
  boolean isMultipart = ServletFileUpload.isMultipartContent(req);    
  if (isMultipart) {
    DiskFileItemFactory factory = new DiskFileItemFactory();
    factory.setSizeThreshold(0);
    reposDir = new File(FileUtils.getTempDirectory(), File.separatorChar + UUID.randomUUID().toString());
    if (!reposDir.mkdirs()) {
      throw new XSLWebException(String.format("Could not create DiskFileItemFactory repository directory (%s)", reposDir.getAbsolutePath()));
    }
    factory.setRepository(reposDir);
    ServletFileUpload upload = new ServletFileUpload(factory);
    upload.setSizeMax(1024 * 1024 * webApp.getMaxUploadSize());
    items = upload.parseRequest(req);      
  }
  return items;
}
 
開發者ID:Armatiek,項目名稱:xslweb,代碼行數:18,代碼來源:RequestSerializer.java

示例6: parseRequestMultiPartItems

import org.apache.commons.fileupload.disk.DiskFileItemFactory; //導入方法依賴的package包/類
/**
 * Gets the FileItemIterator of the input.
 * 
 * Can be used to process uploads in a streaming fashion. Check out:
 * http://commons.apache.org/fileupload/streaming.html
 * 
 * @return the FileItemIterator of the request or null if there was an
 *         error.
 */
public Optional<List<FormItem>> parseRequestMultiPartItems(String encoding) {
    DiskFileItemFactory factory = new DiskFileItemFactory();
    factory.setSizeThreshold(properties.getInt(Constants.PROPERTY_UPLOADS_MAX_SIZE/*Constants.Params.maxUploadSize.name()*/));//Configuration.getMaxUploadSize());
    factory.setRepository(new File(System.getProperty("java.io.tmpdir"))); //Configuration.getTmpDir());
    //README the file for tmpdir *MIGHT* need to go into Properties
    
    ServletFileUpload upload = new ServletFileUpload(factory);
    
    if(encoding != null)
        upload.setHeaderEncoding(encoding);
    upload.setFileSizeMax(properties.getInt(Constants.PROPERTY_UPLOADS_MAX_SIZE));
    
    try {
        List<FormItem> items = upload.parseRequest(request)
                .stream()
                .map(item -> new ApacheFileItemFormItem(item))
                .collect(Collectors.toList());
        return Optional.of(items);
    } catch (FileUploadException e) {
        //"Error while trying to process mulitpart file upload"
        //README: perhaps some logging
    }
    return Optional.empty();
}
 
開發者ID:MTDdk,項目名稱:jawn,代碼行數:34,代碼來源:JawnServletContext.java

示例7: process

import org.apache.commons.fileupload.disk.DiskFileItemFactory; //導入方法依賴的package包/類
@Override
public void process(Exchange exchange) throws Exception {
    DiskFileItemFactory factory = new DiskFileItemFactory();
    factory.setRepository(new File(System.getProperty("java.io.tmpdir")));

    ExchangeFileUpload upload = new ExchangeFileUpload(factory);

    java.util.List<FileItem> items = upload.parseExchange(exchange);

    if(items.size() >= 1){
        exchange.getIn().setBody(items.get(0).getInputStream());

        for (int i = 1; i < items.size(); i++) {
            exchange.setProperty(items.get(i).getName(), items.get(i).getInputStream());
        }
    }
}
 
開發者ID:drinkwater-io,項目名稱:drinkwater-java,代碼行數:18,代碼來源:FileUploadProcessor.java

示例8: importProject

import org.apache.commons.fileupload.disk.DiskFileItemFactory; //導入方法依賴的package包/類
public void importProject(HttpServletRequest req, HttpServletResponse resp) throws Exception {
	DiskFileItemFactory factory = new DiskFileItemFactory();
	ServletContext servletContext = req.getSession().getServletContext();
	File repository = (File) servletContext.getAttribute("javax.servlet.context.tempdir");
	factory.setRepository(repository);
	ServletFileUpload upload = new ServletFileUpload(factory);
	InputStream inputStream=null;
	boolean overwriteProject=true;
	List<FileItem> items = upload.parseRequest(req);
	if(items.size()==0){
		throw new ServletException("Upload file is invalid.");
	}
	for(FileItem item:items){
		String name=item.getFieldName();
		if(name.equals("overwriteProject")){
			String overwriteProjectStr=new String(item.get());
			overwriteProject=Boolean.valueOf(overwriteProjectStr);
		}else if(name.equals("file")){
			inputStream=item.getInputStream();
		}
	}
	repositoryService.importXml(inputStream,overwriteProject);
	IOUtils.closeQuietly(inputStream);
	resp.sendRedirect(req.getContextPath()+"/urule/frame");
}
 
開發者ID:youseries,項目名稱:urule,代碼行數:26,代碼來源:FrameServletHandler.java

示例9: handleFileUpload

import org.apache.commons.fileupload.disk.DiskFileItemFactory; //導入方法依賴的package包/類
private void handleFileUpload(PoseidonRequest request, HttpServletRequest httpRequest) throws IOException {
    // If uploaded file size is more than 10KB, will be stored in disk
    DiskFileItemFactory factory = new DiskFileItemFactory();
    File repository = new File(FILE_UPLOAD_TMP_DIR);
    if (repository.exists()) {
        factory.setRepository(repository);
    }

    // Currently we don't impose max file size at container layer. Apps can impose it by checking FileItem
    // Apps also have to delete tmp file explicitly (if at all it went to disk)
    ServletFileUpload upload = new ServletFileUpload(factory);
    List<FileItem> fileItems = null;
    try {
        fileItems = upload.parseRequest(httpRequest);
    } catch (FileUploadException e) {
        throw new IOException(e);
    }
    for (FileItem fileItem : fileItems) {
        String name = fileItem.getFieldName();
        if (fileItem.isFormField()) {
            request.setAttribute(name, new String[] { fileItem.getString() });
        } else {
            request.setAttribute(name, fileItem);
        }
    }
}
 
開發者ID:flipkart-incubator,項目名稱:Poseidon,代碼行數:27,代碼來源:PoseidonServlet.java

示例10: doPost

import org.apache.commons.fileupload.disk.DiskFileItemFactory; //導入方法依賴的package包/類
/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	try {
		DiskFileItemFactory factory = new DiskFileItemFactory();
		factory.setSizeThreshold(4096);
		factory.setRepository(tempPathFile);
		
		ServletFileUpload upload = new ServletFileUpload(factory);
		upload.setSizeMax(4194304); // 設置最大文件尺寸,這裏是4MB
		List<FileItem> items = upload.parseRequest(request);// 得到所有的文件
		Iterator<FileItem> i = items.iterator();
		while (i.hasNext()) {
		    FileItem fi = (FileItem) i.next();
		    String fileName = fi.getName();
		    if (fileName != null) {
		     File fullFile = new File(fi.getName());
		     File savedFile = new File(uploadPath, fullFile.getName());
		     fi.write(savedFile);
		    }
		 }

	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:henrybit,項目名稱:bird,代碼行數:28,代碼來源:UploadImage.java

示例11: contextInitialized

import org.apache.commons.fileupload.disk.DiskFileItemFactory; //導入方法依賴的package包/類
@Override
public void contextInitialized(ServletContextEvent arg0) {
	System.out.println("context initialized");
	this.start();

	final ServletContext context = arg0.getServletContext();
	context.setAttribute("server", this);

	// load status update types
	try {
		System.out.println("loading status update templates");
		StatusUpdateManager.loadStatusUpdateTemplates(
				context.getRealPath("/") + "WEB-INF/", this.config,
				this.graphDatabase);
		System.out.println("status update templates loaded");
	} catch (ParserConfigurationException | SAXException | IOException e) {
		System.err.println("failed to load status update templates!");
		e.printStackTrace();
	}

	final File tmpDir = (File) context
			.getAttribute("javax.servlet.context.tempdir");
	final DiskFileItemFactory factory = new DiskFileItemFactory();
	factory.setRepository(tmpDir);
	Create.setDiskFileItemFactory(factory);
}
 
開發者ID:renepickhardt,項目名稱:metalcon,代碼行數:27,代碼來源:Server.java

示例12: MultiPartParamSourceHandle

import org.apache.commons.fileupload.disk.DiskFileItemFactory; //導入方法依賴的package包/類
public MultiPartParamSourceHandle(MultiPartOption multiPartOption, boolean dealNormalPut)
{
    this.multiPartOption = multiPartOption;
    this.dealNormalPut = dealNormalPut;
    factory = new DiskFileItemFactory();
    if (multiPartOption.tempDir != null)
    {
        factory.setRepository(new File(multiPartOption.tempDir));
    }
    factory.setSizeThreshold(multiPartOption.cacheSize);
}
 
開發者ID:gzxishan,項目名稱:OftenPorter,代碼行數:12,代碼來源:MultiPartParamSourceHandle.java

示例13: configFileUpload

import org.apache.commons.fileupload.disk.DiskFileItemFactory; //導入方法依賴的package包/類
@Override
public void configFileUpload( DiskFileItemFactory fileItemFactory,
        ServletFileUpload servletFileUpload )
{
    fileItemFactory.setSizeThreshold( BYTE_M * 10 );
    fileItemFactory.setRepository( new File( "D:\\appUploads" ) );
    servletFileUpload.setFileSizeMax( BYTE_M * 100 );
}
 
開發者ID:guanhaobi,項目名稱:DataStage,代碼行數:9,代碼來源:ExcelUploadService.java

示例14: FileHttpFilter

import org.apache.commons.fileupload.disk.DiskFileItemFactory; //導入方法依賴的package包/類
/**
 * 初始化緩存文件夾
 */
public FileHttpFilter() {
	tempPath = HttpConfig.PROJECT_PATH + "/" + HttpConfig.PROJECT_NAME + "_TEMP";
	if (HttpConfig.log != null) {
		HttpConfig.log.info("緩存文件路徑為:" + tempPath);
	}
	File file = new File(tempPath);
	if (!file.exists()) {
		file.mkdirs();
	}
	diskFileItemFactory = new DiskFileItemFactory();
	diskFileItemFactory.setSizeThreshold(1024);
	diskFileItemFactory.setRepository(file);
}
 
開發者ID:dianbaer,項目名稱:grain,代碼行數:17,代碼來源:FileHttpFilter.java

示例15: receiveFile

import org.apache.commons.fileupload.disk.DiskFileItemFactory; //導入方法依賴的package包/類
@SuppressWarnings({ "unchecked" })
	private void receiveFile(HttpServletRequest request, OnFileReceiveListener listener) throws Exception{
		
		DiskFileItemFactory factory = new DiskFileItemFactory();

		// 臨時文件夾路徑
		String repositoryPath = ConfigManager.getManager().FILE_TEMP_PATH;
		// 設定臨時文件夾為repositoryPath
		File fileTempFolder = new File(repositoryPath);
		if(!fileTempFolder.exists())fileTempFolder.mkdirs();
		factory.setRepository(fileTempFolder);

		// 設定上傳文件的閾值,如果上傳文件大於1M,就可能在repository
		// 所代 表的文件夾中產生臨時文件,否則直接在內存中進行處理
		factory.setSizeThreshold(1024 * 1024);

		// 創建一個ServletFileUpload對象
		ServletFileUpload uploader = new ServletFileUpload(factory);

			// 調用uploader中的parseRequest方法,可以獲得請求中的相關內容,
			// 即一個FileItem類型的ArrayList。FileItem是在
			// org.apache.commons.fileupload中定義的,它可以代表一個文件,
			// 也可以代表一個普通的form field
			ArrayList<FileItem> list = (ArrayList<FileItem>) uploader.parseRequest(request);
			for (FileItem fileItem : list){
				if (!fileItem.isFormField()){ // 如果是文件
					String fileName = fileItem.getName() + UUID.randomUUID();
					// 將其中包含的內容寫到指定目錄下名為fileName的文件中
					File file = new File(ConfigManager.getManager().FILE_SAVE_PATH + File.separator + fileName);
					file.createNewFile();
//					System.out.println(file.getPath());
					fileItem.write(file);
					
					listener.onFinished(MD5.getMD5CodeByFile(file),fileName,file.length());
					break;//一次請求隻接受一個文件
				}
			}
	}
 
開發者ID:landriesnidis,項目名稱:PCloud_Server_v3,代碼行數:39,代碼來源:UploadAction.java


注:本文中的org.apache.commons.fileupload.disk.DiskFileItemFactory.setRepository方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。