本文整理匯總了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;
}
示例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;
}
示例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");
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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();
}
示例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;
}
示例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 "";
}