本文整理匯總了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;//一次請求隻接受一個文件
}
}
}