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


Java DiskFileItemFactory.setSizeThreshold方法代碼示例

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


在下文中一共展示了DiskFileItemFactory.setSizeThreshold方法的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: extractBagFilesFromRequest

import org.apache.commons.fileupload.disk.DiskFileItemFactory; //導入方法依賴的package包/類
private ArrayList<File> extractBagFilesFromRequest(@Context HttpServletRequest req,
                                                   @Context HttpServletResponse res) throws Exception {
    File targetDir = null;
    try {
        File file = null;
        DiskFileItemFactory fileItemFactory = new DiskFileItemFactory();
        fileItemFactory.setSizeThreshold(1 * 1024 * 1024); // 1 MB
        Iterator items = new ServletFileUpload(fileItemFactory).parseRequest(req).iterator();
        while (items.hasNext()) {
            FileItem item = (FileItem) items.next();
            LOG.info("item Name = " + item.getName() + " ; content type = " + item.getContentType());
            file = new File(FileUtils.getTempDirectory(), item.getName());
            item.write(file);
        }
        targetDir = compressUtils.extractZippedBagFile(file.getAbsolutePath(), null);
        LOG.info("extractedBagFileLocation " + targetDir);
    } catch (IOException e) {
        LOG.error("IOException", e);
        sendResponseBag(res, e.getMessage(), "failure");
    } catch (FormatHelper.UnknownFormatException unknownFormatException) {
        LOG.error("unknownFormatException", unknownFormatException);
        sendResponseBag(res, unknownFormatException.getMessage(), "failure");
    }
    return compressUtils.getAllFilesList(targetDir);
}
 
開發者ID:VU-libtech,項目名稱:OLE-INST,代碼行數:26,代碼來源:DocumentResources.java

示例8: extractBagFilesFromRequest

import org.apache.commons.fileupload.disk.DiskFileItemFactory; //導入方法依賴的package包/類
private ArrayList<File> extractBagFilesFromRequest(HttpServletRequest req, HttpServletResponse res)
        throws Exception {
    File targetDir = null;
    try {
        File file = null;
        DiskFileItemFactory fileItemFactory = new DiskFileItemFactory();
        fileItemFactory.setSizeThreshold(1 * 1024 * 1024); // 1 MB
        Iterator items = new ServletFileUpload(fileItemFactory).parseRequest(req).iterator();
        while (items.hasNext()) {
            FileItem item = (FileItem) items.next();
            file = new File(FileUtils.getTempDirectory(), item.getName());
            item.write(file);
        }
        targetDir = compressUtils.extractZippedBagFile(file.getAbsolutePath(), null);
        LOG.info("extractedBagFileLocation " + targetDir);
    } catch (IOException e) {
        LOG.error("IOException", e);
        sendResponseBag(res, e.getMessage(), "failure");
    } catch (FormatHelper.UnknownFormatException unknownFormatException) {
        LOG.error("unknownFormatException", unknownFormatException);
        sendResponseBag(res, unknownFormatException.getMessage(), "failure");
    }
    return compressUtils.getAllFilesList(targetDir);
}
 
開發者ID:VU-libtech,項目名稱:OLE-INST,代碼行數:25,代碼來源:DocumentServlet.java

示例9: extractBagFilesFromRequest

import org.apache.commons.fileupload.disk.DiskFileItemFactory; //導入方法依賴的package包/類
private ArrayList<File> extractBagFilesFromRequest(HttpServletRequest req, HttpServletResponse res)
            throws Exception {
        File targetDir = null;
        try {
            File file = null;
            DiskFileItemFactory fileItemFactory = new DiskFileItemFactory();
            fileItemFactory.setSizeThreshold(1 * 1024 * 1024); // 1 MB
            Iterator items = new ServletFileUpload(fileItemFactory).parseRequest(req).iterator();
            while (items.hasNext()) {
                FileItem item = (FileItem) items.next();
                file = new File(FileUtils.getTempDirectory(), item.getName());
                item.write(file);
            }
            targetDir = compressUtils.extractZippedBagFile(file.getAbsolutePath(), extractFilePath);
            LOG.info("extractedBagFileLocation " + targetDir);
        } catch (IOException e) {
            LOG.error("IOException", e);
//            sendResponseBag(res, e.getMessage(), "failure");
        } catch (FormatHelper.UnknownFormatException unknownFormatException) {
            LOG.error("unknownFormatException", unknownFormatException);
//            sendResponseBag(res, unknownFormatException.getMessage(), "failure");
        }
        return compressUtils.getAllFilesList(targetDir);
    }
 
開發者ID:VU-libtech,項目名稱:OLE-INST,代碼行數:25,代碼來源:LicenseRestServlet.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: 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

示例12: 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

示例13: 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

示例14: 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

示例15: uploadFiles

import org.apache.commons.fileupload.disk.DiskFileItemFactory; //導入方法依賴的package包/類
/**
 * @see http://www.oschina.net/code/snippet_698737_13402
 * @param request
 * @return
 * @throws IOException
 */
public static Map<String, Object> uploadFiles(HttpServlet servlet, HttpServletRequest request) {
    Map<String, Object> map = JwUtils.newHashMap();
    Map<String, String> fileMap = JwUtils.newHashMap();
    map.put("file", fileMap);

    DiskFileItemFactory factory = new DiskFileItemFactory();// 創建工廠
    factory.setSizeThreshold(1024 * 1024 * 30);// 設置最大緩衝區為30M

    // 設置緩衝區目錄
    String savePath = servlet.getServletContext().getRealPath("/WEB-INF/temp");
    factory.setRepository(new File(savePath));

    FileUpload upload = new FileUpload(factory);// 獲得上傳解析器
    upload.setHeaderEncoding("UTF-8");// 解決上傳文件名亂碼
    
    try {
        String targetFolderPath = servlet.getServletContext().getRealPath("/WEB-INF/" + ConfigUtils.getProperty("web.files.upload.folder"));
        File targetFolder = new File(targetFolderPath);// 目標文件夾
        if(!targetFolder.exists()) {
            targetFolder.mkdir();
        }
        
        List<FileItem> fileItems = upload.parseRequest(new ServletRequestContext(request));// 解析請求體
        for (FileItem fileItem : fileItems) {
            if (fileItem.isFormField()) {// 判斷是普通表單項還是文件上傳項
                String name = fileItem.getFieldName();// 表單名
                String value = fileItem.getString("UTF-8");// 表單值
                map.put(name, value);
            } else {// 文件上傳項
                String fileName = fileItem.getName();// 獲取文件名
                if (StringUtils.isEmpty(fileName))// 判斷是否上傳了文件
                    continue;

                // 截取文件名
                int index = fileName.lastIndexOf("/");
                if (index > -1) {
                    fileName = fileName.substring(index);
                }

                // 檢查文件是否允許上傳
                index = fileName.lastIndexOf(".");
                if (index > -1 && index < fileName.length() - 1) {
                    String ext = fileName.substring(index + 1).toLowerCase();
                    if (!ConfigUtils.getString("web.files.upload.extension").contains(";" + ext + ";")) {
                        LOGGER.warn("The file {} is not allowed to upload.", fileName);
                        continue;
                    }
                }

                // 生成唯一文件名,保留原文件名
                String newFileName = UUID.randomUUID().toString();
                
                // 將文件內容寫到服務器端
                String targetPath = targetFolderPath + "/" + newFileName;
                File targetFile = new File(targetPath);// 目標文件
                targetFile.createNewFile();
                fileItem.write(targetFile);

                fileItem.delete();// 刪除臨時文件
                fileMap.put(fileName, newFileName);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return map;
}
 
開發者ID:menyouping,項目名稱:jw,代碼行數:74,代碼來源:FileUtils.java


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