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