本文整理汇总了Java中org.apache.commons.fileupload.disk.DiskFileItemFactory.setRepository方法的典型用法代码示例。如果您正苦于以下问题:Java DiskFileItemFactory.setRepository方法的具体用法?Java DiskFileItemFactory.setRepository怎么用?Java DiskFileItemFactory.setRepository使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.fileupload.disk.DiskFileItemFactory
的用法示例。
在下文中一共展示了DiskFileItemFactory.setRepository方法的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: 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());
}
}
}
示例8: 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");
}
示例9: handleFileUpload
import org.apache.commons.fileupload.disk.DiskFileItemFactory; //导入方法依赖的package包/类
private void handleFileUpload(PoseidonRequest request, HttpServletRequest httpRequest) throws IOException {
// If uploaded file size is more than 10KB, will be stored in disk
DiskFileItemFactory factory = new DiskFileItemFactory();
File repository = new File(FILE_UPLOAD_TMP_DIR);
if (repository.exists()) {
factory.setRepository(repository);
}
// Currently we don't impose max file size at container layer. Apps can impose it by checking FileItem
// Apps also have to delete tmp file explicitly (if at all it went to disk)
ServletFileUpload upload = new ServletFileUpload(factory);
List<FileItem> fileItems = null;
try {
fileItems = upload.parseRequest(httpRequest);
} catch (FileUploadException e) {
throw new IOException(e);
}
for (FileItem fileItem : fileItems) {
String name = fileItem.getFieldName();
if (fileItem.isFormField()) {
request.setAttribute(name, new String[] { fileItem.getString() });
} else {
request.setAttribute(name, fileItem);
}
}
}
示例10: doPost
import org.apache.commons.fileupload.disk.DiskFileItemFactory; //导入方法依赖的package包/类
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold(4096);
factory.setRepository(tempPathFile);
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setSizeMax(4194304); // 设置最大文件尺寸,这里是4MB
List<FileItem> items = upload.parseRequest(request);// 得到所有的文件
Iterator<FileItem> i = items.iterator();
while (i.hasNext()) {
FileItem fi = (FileItem) i.next();
String fileName = fi.getName();
if (fileName != null) {
File fullFile = new File(fi.getName());
File savedFile = new File(uploadPath, fullFile.getName());
fi.write(savedFile);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例11: contextInitialized
import org.apache.commons.fileupload.disk.DiskFileItemFactory; //导入方法依赖的package包/类
@Override
public void contextInitialized(ServletContextEvent arg0) {
System.out.println("context initialized");
this.start();
final ServletContext context = arg0.getServletContext();
context.setAttribute("server", this);
// load status update types
try {
System.out.println("loading status update templates");
StatusUpdateManager.loadStatusUpdateTemplates(
context.getRealPath("/") + "WEB-INF/", this.config,
this.graphDatabase);
System.out.println("status update templates loaded");
} catch (ParserConfigurationException | SAXException | IOException e) {
System.err.println("failed to load status update templates!");
e.printStackTrace();
}
final File tmpDir = (File) context
.getAttribute("javax.servlet.context.tempdir");
final DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setRepository(tmpDir);
Create.setDiskFileItemFactory(factory);
}
示例12: MultiPartParamSourceHandle
import org.apache.commons.fileupload.disk.DiskFileItemFactory; //导入方法依赖的package包/类
public MultiPartParamSourceHandle(MultiPartOption multiPartOption, boolean dealNormalPut)
{
this.multiPartOption = multiPartOption;
this.dealNormalPut = dealNormalPut;
factory = new DiskFileItemFactory();
if (multiPartOption.tempDir != null)
{
factory.setRepository(new File(multiPartOption.tempDir));
}
factory.setSizeThreshold(multiPartOption.cacheSize);
}
示例13: configFileUpload
import org.apache.commons.fileupload.disk.DiskFileItemFactory; //导入方法依赖的package包/类
@Override
public void configFileUpload( DiskFileItemFactory fileItemFactory,
ServletFileUpload servletFileUpload )
{
fileItemFactory.setSizeThreshold( BYTE_M * 10 );
fileItemFactory.setRepository( new File( "D:\\appUploads" ) );
servletFileUpload.setFileSizeMax( BYTE_M * 100 );
}
示例14: FileHttpFilter
import org.apache.commons.fileupload.disk.DiskFileItemFactory; //导入方法依赖的package包/类
/**
* 初始化缓存文件夹
*/
public FileHttpFilter() {
tempPath = HttpConfig.PROJECT_PATH + "/" + HttpConfig.PROJECT_NAME + "_TEMP";
if (HttpConfig.log != null) {
HttpConfig.log.info("缓存文件路径为:" + tempPath);
}
File file = new File(tempPath);
if (!file.exists()) {
file.mkdirs();
}
diskFileItemFactory = new DiskFileItemFactory();
diskFileItemFactory.setSizeThreshold(1024);
diskFileItemFactory.setRepository(file);
}
示例15: receiveFile
import org.apache.commons.fileupload.disk.DiskFileItemFactory; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked" })
private void receiveFile(HttpServletRequest request, OnFileReceiveListener listener) throws Exception{
DiskFileItemFactory factory = new DiskFileItemFactory();
// 临时文件夹路径
String repositoryPath = ConfigManager.getManager().FILE_TEMP_PATH;
// 设定临时文件夹为repositoryPath
File fileTempFolder = new File(repositoryPath);
if(!fileTempFolder.exists())fileTempFolder.mkdirs();
factory.setRepository(fileTempFolder);
// 设定上传文件的阈值,如果上传文件大于1M,就可能在repository
// 所代 表的文件夹中产生临时文件,否则直接在内存中进行处理
factory.setSizeThreshold(1024 * 1024);
// 创建一个ServletFileUpload对象
ServletFileUpload uploader = new ServletFileUpload(factory);
// 调用uploader中的parseRequest方法,可以获得请求中的相关内容,
// 即一个FileItem类型的ArrayList。FileItem是在
// org.apache.commons.fileupload中定义的,它可以代表一个文件,
// 也可以代表一个普通的form field
ArrayList<FileItem> list = (ArrayList<FileItem>) uploader.parseRequest(request);
for (FileItem fileItem : list){
if (!fileItem.isFormField()){ // 如果是文件
String fileName = fileItem.getName() + UUID.randomUUID();
// 将其中包含的内容写到指定目录下名为fileName的文件中
File file = new File(ConfigManager.getManager().FILE_SAVE_PATH + File.separator + fileName);
file.createNewFile();
// System.out.println(file.getPath());
fileItem.write(file);
listener.onFinished(MD5.getMD5CodeByFile(file),fileName,file.length());
break;//一次请求只接受一个文件
}
}
}