本文整理汇总了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 "";
}