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


Java DiskFileItemFactory類代碼示例

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


DiskFileItemFactory類屬於org.apache.commons.fileupload.disk包,在下文中一共展示了DiskFileItemFactory類的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: handleMultipartPost

import org.apache.commons.fileupload.disk.DiskFileItemFactory; //導入依賴的package包/類
/**
 * Sets up the given {@link org.apache.commons.httpclient.methods.PostMethod} to send the same multipart POST data
 * as was sent in the given {@link HttpServletRequest}
 *
 * @param postMethodProxyRequest The {@link org.apache.commons.httpclient.methods.PostMethod} that we are configuring to send a
 * multipart POST request
 * @param httpServletRequest The {@link HttpServletRequest} that contains the multipart
 * POST data to be sent via the {@link org.apache.commons.httpclient.methods.PostMethod}
 */
@SuppressWarnings("unchecked")
public static void handleMultipartPost(
    EntityEnclosingMethod postMethodProxyRequest,
    HttpServletRequest httpServletRequest,
    DiskFileItemFactory diskFileItemFactory)
    throws ServletException {
    // TODO: this function doesn't set any history data
    try {
        // just pass back the binary data
        InputStreamRequestEntity ire = new InputStreamRequestEntity(httpServletRequest.getInputStream());
        postMethodProxyRequest.setRequestEntity(ire);
        postMethodProxyRequest.setRequestHeader(STRING_CONTENT_TYPE_HEADER_NAME, httpServletRequest.getHeader(STRING_CONTENT_TYPE_HEADER_NAME));
    } catch (Exception e) {
        throw new ServletException(e);
    }
}
 
開發者ID:groupon,項目名稱:odo,代碼行數:26,代碼來源:HttpUtilities.java

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

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

示例11: importExcelTemplate

import org.apache.commons.fileupload.disk.DiskFileItemFactory; //導入依賴的package包/類
public void importExcelTemplate(HttpServletRequest req, HttpServletResponse resp) throws Exception {
	DiskFileItemFactory factory=new DiskFileItemFactory();
	ServletFileUpload upload = new ServletFileUpload(factory);
	List<FileItem> items = upload.parseRequest(req);
	Iterator<FileItem> itr = items.iterator();
	List<Map<String,Object>> mapData=null;
	while (itr.hasNext()) {
		FileItem item = (FileItem) itr.next();
		String name=item.getFieldName();
		if(!name.equals("file")){
			continue;
		}
		InputStream stream=item.getInputStream();
		mapData=parseExcel(stream);
		httpSessionKnowledgeCache.put(req, IMPORT_EXCEL_DATA, mapData);
		stream.close();
		break;
	}
	httpSessionKnowledgeCache.put(req, IMPORT_EXCEL_DATA, mapData);
	writeObjectToJson(resp, mapData);
}
 
開發者ID:youseries,項目名稱:urule,代碼行數:22,代碼來源:PackageServletHandler.java

示例12: getServiceResult

import org.apache.commons.fileupload.disk.DiskFileItemFactory; //導入依賴的package包/類
protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
	// Check that we have a file upload request
	boolean isMultipart = ServletFileUpload.isMultipartContent(request);

	if (!isMultipart)
		throw new IllegalArgumentException("Not multipart content!");

	FileItemFactory factory = new DiskFileItemFactory();

	// Create a new file upload handler
	ServletFileUpload upload = new ServletFileUpload(factory);

	// Parse the request
	List<FileItem> items = GenericUtils.cast(upload.parseRequest(request));

	// Process the uploaded items
	handleFormFields(request);
	for (FileItem item : items) {
		doUpload(request, document, item);
	}
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:22,代碼來源:UploadService.java

示例13: parseMultipartWithCommonsFileUpload

import org.apache.commons.fileupload.disk.DiskFileItemFactory; //導入依賴的package包/類
private Collection<Part> parseMultipartWithCommonsFileUpload(HttpServletRequest request) throws IOException {
  if (sharedFileItemFactory.get() == null) {
    // Not a big deal if two threads actually set this up
    DiskFileItemFactory fileItemFactory = new DiskFileItemFactory(
        1 << 16, (File) servletContext.getAttribute("javax.servlet.context.tempdir"));
    fileItemFactory.setFileCleaningTracker(
        FileCleanerCleanup.getFileCleaningTracker(servletContext));
    sharedFileItemFactory.compareAndSet(null, fileItemFactory);
  }

  try {
    return new ServletFileUpload(sharedFileItemFactory.get()).parseRequest(request)
        .stream().map(FileItemPart::new).collect(Collectors.toList());
  } catch (FileUploadException e) {
    throw new IOException(e.getMessage());
  }
}
 
開發者ID:oncewang,項目名稱:oryx2,代碼行數:18,代碼來源:AbstractOryxResource.java

示例14: map

import org.apache.commons.fileupload.disk.DiskFileItemFactory; //導入依賴的package包/類
public Map<String, Object> map(HttpServletRequest request) {
    ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
    upload.setSizeMax(20 * 1024);
    upload.setFileSizeMax(10 * 1024);

    List<FileItem> items;
    try {
        items = upload.parseRequest(request);
    } catch (FileUploadException e) {
        throw new RequestMappingException("", e);
    }

    return items.stream().map(item -> {
        String key = item.getFieldName();
        if (item.isFormField()) {
            String value = item.getString();
            return new SimpleKeyValue<String, Object>(key, value);
        } else {
            return new SimpleKeyValue<String, Object>(key, item);
        }
    }).collect(Collectors.toMap(
            SimpleKeyValue::getKey,
            SimpleKeyValue::getValue
    ));
}
 
開發者ID:ShotaOd,項目名稱:carbon,代碼行數:26,代碼來源:MultipartFormKeyValueRequestMapper.java

示例15: VariablesBase

import org.apache.commons.fileupload.disk.DiskFileItemFactory; //導入依賴的package包/類
/**
 * Basic constructor that takes the request object and saves it to be used by the subsequent
 * methods
 * 
 * @param request
 *          HttpServletRequest object originating from the user request.
 */
@SuppressWarnings("unchecked")
public VariablesBase(HttpServletRequest request) {
  if (request == null) {
    // logging exception to obtain stack trace to pinpoint the cause
    log4j.warn("Creating a VariablesBase with a null request", new Exception());
    this.session = new HttpSessionWrapper();
    this.isMultipart = false;
  } else {
    this.session = request.getSession(true);
    this.httpRequest = request;
    this.isMultipart = ServletFileUpload.isMultipartContent(new ServletRequestContext(request));
    if (isMultipart) {
      DiskFileItemFactory factory = new DiskFileItemFactory();
      // factory.setSizeThreshold(yourMaxMemorySize);
      // factory.setRepositoryPath(yourTempDirectory);
      ServletFileUpload upload = new ServletFileUpload(factory);
      // upload.setSizeMax(yourMaxRequestSize);
      try {
        items = upload.parseRequest(request);
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    }
  }
}
 
開發者ID:mauyr,項目名稱:openbravo-brazil,代碼行數:33,代碼來源:VariablesBase.java


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