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


Java FileItem.getInputStream方法代碼示例

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


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

示例1: excelToArrayList

import org.apache.commons.fileupload.FileItem; //導入方法依賴的package包/類
/**
 * 獲取Excel數據,返回List
 * 
 * @param sheetNumber
 *            讀取工作表的下標(從1開始).可有可無,默認讀取所有表單.
 */
public static final List<String[]> excelToArrayList(String fileName, FileItem fileItem, int... sheetNumber)
    throws Exception {
    List<String[]> resultList = null;
    InputStream is = null;
    try {
        is = fileItem.getInputStream();
        resultList = excelToArrayList(fileName, is, sheetNumber);
    } catch (Exception e) {
        throw e;
    } finally {
        if (is != null) {
            is.close();
        }
    }
    return resultList;
}
 
開發者ID:iBase4J,項目名稱:iBase4J-Common,代碼行數:23,代碼來源:ExcelReaderUtil.java

示例2: excelToArrayList

import org.apache.commons.fileupload.FileItem; //導入方法依賴的package包/類
/**
 * 獲取Excel數據,返回List<String[]>
 * 
 * @param sheetNumber
 *            讀取工作表的下標(從1開始).可有可無,默認讀取所有表單.
 */
public static final List<String[]> excelToArrayList(String fileName, FileItem fileItem, int... sheetNumber)
		throws Exception {
	List<String[]> resultList = null;
	InputStream is = null;
	try {
		is = fileItem.getInputStream();
		resultList = excelToArrayList(fileName, is, sheetNumber);
	} catch (Exception e) {
		throw e;
	} finally {
		if (is != null) {
			is.close();
		}
	}
	return resultList;
}
 
開發者ID:guokezheng,項目名稱:automat,代碼行數:23,代碼來源:ExcelReaderUtil.java

示例3: importProject

import org.apache.commons.fileupload.FileItem; //導入方法依賴的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

示例4: importExcelTemplate

import org.apache.commons.fileupload.FileItem; //導入方法依賴的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

示例5: extractAttachments

import org.apache.commons.fileupload.FileItem; //導入方法依賴的package包/類
/**
 * extracts attachments from the http request.
 *
 * @param httpRequest
 *            request containing attachments DefaultMultipartHttpServletRequest is supported
 * @param request
 *            {@link Request}
 * @return ids of extracted attachments
 * @throws IOException
 *             throws exception if problems during attachments accessing occurred
 * @throws FileUploadException
 *             Exception.
 * @throws AttachmentIsEmptyException
 *             Thrown, when the attachment is of zero size.
 * @throws AuthorizationException
 *             in case there is no authenticated user
 */
private List<AttachmentResource> extractAttachments(HttpServletRequest httpRequest,
        Request request) throws FileUploadException, IOException,
        AttachmentIsEmptyException, AuthorizationException {
    List<AttachmentResource> result = new ArrayList<>();
    if (httpRequest.getContentType().startsWith(AttachmentResourceHelper.MULTIPART_FORM_DATA)) {
        FileItemFactory factory = new DiskFileItemFactory();
        FileUpload upload = new FileUpload(factory);
        List<FileItem> items = upload.parseRequest(new ServletRequestContext(httpRequest));
        for (FileItem file : items) {
            if (!file.isFormField()) {
                AttachmentTO attachmentTo = new AttachmentStreamTO(file.getInputStream(),
                        AttachmentStatus.UPLOADED);
                AttachmentResourceHelper.assertAttachmentSize(file.getContentType(),
                        file.getSize(), false);
                attachmentTo.setMetadata(new ContentMetadata());
                attachmentTo.getMetadata().setFilename(getFileName(file.getName()));
                attachmentTo.getMetadata().setContentSize(file.getSize());
                result.add(persistAttachment(request, attachmentTo));
            }
        }
    }
    return result;
}
 
開發者ID:Communote,項目名稱:communote-server,代碼行數:41,代碼來源:AttachmentResourceHandler.java

示例6: extractAttachments

import org.apache.commons.fileupload.FileItem; //導入方法依賴的package包/類
/**
 * extracts attachments from the http request.
 *
 * @param httpRequest
 *            request containing attachments DefaultMultipartHttpServletRequest is supported
 * @param request
 *            {@link Request}
 * @return ids of extracted attachments
 * @throws MaxLengthReachedException
 *             attachment size is to large
 * @throws IOException
 *             throws exception if problems during attachments accessing occurred
 * @throws FileUploadException
 *             Exception.
 * @throws AttachmentIsEmptyException
 *             Thrown, when the attachment is of zero size.
 * @throws AuthorizationException
 *             in case there is no authenticated user
 */
private List<AttachmentResource> extractAttachments(HttpServletRequest httpRequest,
        Request request) throws MaxLengthReachedException, FileUploadException, IOException,
        AttachmentIsEmptyException, AuthorizationException {
    List<AttachmentResource> result = new ArrayList<AttachmentResource>();
    if (httpRequest.getContentType().startsWith(AttachmentResourceHelper.MULTIPART_FORM_DATA)) {
        FileItemFactory factory = new DiskFileItemFactory();
        FileUpload upload = new FileUpload(factory);
        List<FileItem> items = upload.parseRequest(new ServletRequestContext(httpRequest));
        for (FileItem file : items) {
            if (!file.isFormField()) {
                AttachmentTO attachmentTo = new AttachmentStreamTO(file.getInputStream(),
                        AttachmentStatus.UPLOADED);
                AttachmentResourceHelper.assertAttachmentSize(file.getContentType(),
                        file.getSize(), false);
                attachmentTo.setMetadata(new ContentMetadata());
                attachmentTo.getMetadata().setFilename(getFileName(file.getName()));
                attachmentTo.getMetadata().setContentSize(file.getSize());
                result.add(persistAttachment(request, attachmentTo));
            }
        }
    }
    return result;
}
 
開發者ID:Communote,項目名稱:communote-server,代碼行數:43,代碼來源:AttachmentResourceHandler.java

示例7: extractAttachments

import org.apache.commons.fileupload.FileItem; //導入方法依賴的package包/類
/**
 * extracts attachments from the http request.
 *
 * @param httpRequest
 *            request containing attachments DefaultMultipartHttpServletRequest is supported
 * @param request
 *            {@link Request}
 * @return ids of extracted attachments
 * @throws MaxLengthReachedException
 *             attachment size is to large
 * @throws IOException
 *             throws exception if problems during attachments accessing occurred
 * @throws FileUploadException
 *             Exception.
 * @throws AuthorizationException
 *             in case there is no authenticated user
 */
private List<AttachmentResource> extractAttachments(HttpServletRequest httpRequest,
        Request request) throws MaxLengthReachedException, FileUploadException, IOException,
        AuthorizationException {
    List<AttachmentResource> result = new ArrayList<AttachmentResource>();
    if (httpRequest.getContentType().startsWith(AttachmentResourceHelper.MULTIPART_FORM_DATA)) {
        FileItemFactory factory = new DiskFileItemFactory();
        FileUpload upload = new FileUpload(factory);
        List<FileItem> items = upload.parseRequest(new ServletRequestContext(httpRequest));
        for (FileItem file : items) {
            if (!file.isFormField()) {
                AttachmentTO attachmentTo = new AttachmentStreamTO(file.getInputStream(),
                        AttachmentStatus.UPLOADED);
                AttachmentResourceHelper.assertAttachmentSize(file.getContentType(),
                        file.getSize(), false);
                attachmentTo.setMetadata(new ContentMetadata());
                attachmentTo.getMetadata().setFilename(getFileName(file.getName()));
                attachmentTo.getMetadata().setContentSize(file.getSize());
                result.add(persistAttachment(request, attachmentTo));
            }
        }
    }
    return result;
}
 
開發者ID:Communote,項目名稱:communote-server,代碼行數:41,代碼來源:AttachmentResourceHandler.java

示例8: extractAttachments

import org.apache.commons.fileupload.FileItem; //導入方法依賴的package包/類
/**
 * extracts attachments from the http request.
 *
 * @param httpRequest
 *            request containing attachments DefaultMultipartHttpServletRequest is supported
 * @param request
 *            {@link Request}
 * @return ids of extracted attachments
 * @throws MaxLengthReachedException
 *             attachment size is to large
 * @throws IOException
 *             throws exception if problems during attachments accessing occurred
 * @throws FileUploadException
 *             Exception.
 * @throws AuthorizationException
 *             in case there is no authenticated user
 */
private List<AttachmentResource> extractAttachments(HttpServletRequest httpRequest,
        Request request) throws MaxLengthReachedException, FileUploadException, IOException,
        AuthorizationException {
    List<AttachmentResource> result = new ArrayList<AttachmentResource>();
    if (httpRequest.getContentType().startsWith(AttachmentResourceHelper.MULTIPART_FORM_DATA)) {
        FileItemFactory factory = new DiskFileItemFactory();
        FileUpload upload = new FileUpload(factory);
        List<FileItem> items = upload.parseRequest(new ServletRequestContext(httpRequest));
        for (FileItem file : items) {
            if (!file.isFormField()) {
                AttachmentTO attachmentTo = new AttachmentStreamTO(file.getInputStream(),
                        AttachmentStatus.UPLOADED);
                AttachmentResourceHelper.checkAttachmentSize(file);
                attachmentTo.setMetadata(new ContentMetadata());
                attachmentTo.getMetadata().setFilename(getFileName(file.getName()));
                attachmentTo.getMetadata().setContentSize(file.getSize());
                result.add(persistAttachment(request, attachmentTo));
            }
        }
    }
    return result;
}
 
開發者ID:Communote,項目名稱:communote-server,代碼行數:40,代碼來源:AttachmentResourceHandler.java

示例9: makeTempFromFileItem

import org.apache.commons.fileupload.FileItem; //導入方法依賴的package包/類
/**
	 * {@inheritDoc}
	 * <pre>
	 * BLOBに保存するためヘッダ情報 + ファイル本體の形式の一時ファイルを作成します。
	 * </pre>
	 */
	@Override
	protected File makeTempFromFileItem(final FileItem fileItem) throws Exception {
//		log.error("makeTempFromFileItem", new Exception());
		String fileName = FileUtil.getFileName(fileItem.getName());
		long length = fileItem.getSize();
		File file = null;
		InputStream is = fileItem.getInputStream();
		try {
			file = this.makeBlobTempFile(fileName, length, is);
		} finally {
			is.close();
		}
//		this.tempFile = file;
		return file;
	}
 
開發者ID:takayanagi2087,項目名稱:dataforms,代碼行數:22,代碼來源:BlobFileStore.java

示例10: makeTempFromFileItem

import org.apache.commons.fileupload.FileItem; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 * <pre>
 * 一時ファイルの保存処理ですが、性能を考慮し本來のフォルダに保存します。
 * </pre>
 */
@Override
public File makeTempFromFileItem(final FileItem fileItem) throws Exception {
	this.fileName = FileUtil.getFileName(fileItem.getName());

	File file = this.makeUniqFile();
	FileOutputStream os = new FileOutputStream(file);
	try {
		InputStream is = fileItem.getInputStream();
		try {
			FileUtil.copyStream(is, os);
		} finally {
			is.close();
		}
	} finally {
		os.close();
	}
	return file;
}
 
開發者ID:takayanagi2087,項目名稱:dataforms,代碼行數:25,代碼來源:FolderFileStore.java

示例11: unpackRestoreFile

import org.apache.commons.fileupload.FileItem; //導入方法依賴的package包/類
/**
 * バックアップファイルを解凍します。
 * @param fileItem バックアップファイル。
 * @return 展開されたディレクトリのパス。
 * @throws Exception 例外。
 */
public String unpackRestoreFile(final FileItem fileItem) throws Exception {
	InputStream is = fileItem.getInputStream();
	String ret = null;
	try {
		File bkdir = new File(DataFormsServlet.getTempDir() + "/restore");
		if (!bkdir.exists()) {
			bkdir.mkdirs();
		}
		Path backup = FileUtil.createTempDirectory(bkdir.getAbsolutePath(), "restore");
		FileUtil.unpackZipFile(is, backup.toString());
		ret = backup.toString();
	} finally {
		is.close();
	}
	return ret;
}
 
開發者ID:takayanagi2087,項目名稱:dataforms,代碼行數:23,代碼來源:RestoreForm.java

示例12: readImage

import org.apache.commons.fileupload.FileItem; //導入方法依賴的package包/類
protected BufferedImage readImage(FileItem file) throws IOException {
    InputStream in = file.getInputStream();
    if (in == null) {
        return null;
    }
    return ImageIO.read(in);
}
 
開發者ID:devefx,項目名稱:validator-web,代碼行數:8,代碼來源:CommonsImageMultipartFile.java

示例13: HttpUploadReader

import org.apache.commons.fileupload.FileItem; //導入方法依賴的package包/類
HttpUploadReader(FileItem item) throws IOException {
    this.item = item;
    fieldName = item.getFieldName();
    fileName = item.getName();
    contentType = item.getContentType();
    size = item.getSize();
    inputStream = item.getInputStream();
}
 
開發者ID:heisedebaise,項目名稱:tephra,代碼行數:9,代碼來源:HttpUploadReader.java

示例14: performImport

import org.apache.commons.fileupload.FileItem; //導入方法依賴的package包/類
private String performImport(List<FileItem> files)  {
    //import certificate
    String status = "";
    InputStream filecontent = null;
    Integer id = null;

    try {
        for (FileItem item : files) {
            if (!item.isFormField()) {
                // Process form file field (input type="file").
                filecontent = item.getInputStream();
            } else {
                // Process regular form field (input type="text|radio|checkbox|etc", select, etc).
                String fieldname = item.getFieldName();
                String fieldvalue = item.getString();

                if (fieldname.equals("id")) {
                    id = Integer.parseInt(fieldvalue);
                }
            }
        }
        if (id != null && filecontent != null) {
            status = importCertificates(id, filecontent);
        }
    } catch (Exception ex) {
        LOGGER.info(ex);
    }

    return "/sharingcenter/security/import.jsp?id=" + id + "&" + status;
}
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:31,代碼來源:SecurityInfrastructureServlet.java

示例15: uploadImage

import org.apache.commons.fileupload.FileItem; //導入方法依賴的package包/類
/**
 * 上傳圖片,並返回對應圖片的訪問地址
 * 
 * @param request
 * @param fileItem
 * @return
 * @throws IOException
 */
private String uploadImage(HttpServletRequest request, FileItem fileItem)
		throws IOException {
	// 將獲得一個磁盤路徑
	String uploadPath = getServletContext().getRealPath("/upload");
	File uploadDir = new File(uploadPath);
	// 如果文件目錄不存在,則創建之
	if (!uploadDir.exists()) {
		uploadDir.mkdirs();
	}
	// 圖片類型的文件,其他類型的不以處理
	if (fileItem != null && fileItem.getContentType().startsWith("image")) {
		// 獲得文件後綴名
		String suffix = fileItem.getName().substring(
				fileItem.getName().lastIndexOf("."));
		// 為保證圖片名稱唯一性,在前麵拚接當前時間
		String fileName = fileItem.getName().replace(suffix,
				getFormatNowDate() + suffix);
		InputStream is = fileItem.getInputStream();
		FileOutputStream fos = new FileOutputStream(uploadPath + "/"
				+ fileName);
		byte[] b = new byte[1024];
		int len = 0;
		while ((len = is.read(b)) > 0) {
			fos.write(b, 0, len);
			fos.flush();
		}
		fos.close();
		is.close();
		// 當前服務器域名
		String serverName = request.getServerName();
		// 端口號
		int serverPort = request.getServerPort();
		String imageUrl = "http://" + serverName + ":" + serverPort
				+ "/upload/" + fileName;
		System.out.println("imageUrl:" + imageUrl);
		return imageUrl;
	}
	return "";
}
 
開發者ID:lijian17,項目名稱:androidpn-server,代碼行數:48,代碼來源:NotificationController.java


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