List of usage examples for org.apache.commons.fileupload DefaultFileItemFactory DefaultFileItemFactory
public DefaultFileItemFactory(int sizeThreshold, File repository)
From source file:org.etk.core.rest.impl.provider.MultipartFormDataEntityProvider.java
/** * {@inheritDoc}/*from w ww . ja v a 2s . c o m*/ */ @SuppressWarnings("unchecked") public Iterator<FileItem> readFrom(Class<Iterator<FileItem>> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException { try { ApplicationContext context = ApplicationContextImpl.getCurrent(); int bufferSize = (Integer) context.getAttributes().get(RequestHandler.WS_RS_BUFFER_SIZE); File repo = (File) context.getAttributes().get(RequestHandler.WS_RS_TMP_DIR); DefaultFileItemFactory factory = new DefaultFileItemFactory(bufferSize, repo); FileUpload upload = new FileUpload(factory); return upload.parseRequest(httpRequest).iterator(); } catch (FileUploadException e) { throw new IOException("Can't process multipart data item " + e); } }
From source file:org.everrest.core.impl.provider.MultipartFormDataEntityProvider.java
@Override @SuppressWarnings("unchecked") public Iterator<FileItem> readFrom(Class<Iterator<FileItem>> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException { try {// www. j a v a 2s. co m ApplicationContext context = ApplicationContextImpl.getCurrent(); int bufferSize = context.getEverrestConfiguration().getMaxBufferSize(); DefaultFileItemFactory factory = new DefaultFileItemFactory(bufferSize, FileCollector.getInstance().getStore()); FileUpload upload = new FileUpload(factory); return upload.parseRequest(httpRequest).iterator(); } catch (FileUploadException e) { throw new IOException("Can't process multipart data item " + e); } }
From source file:org.exoplatform.services.rest.impl.provider.MultipartFormDataEntityProvider.java
/** * {@inheritDoc}/* w w w. j av a2s .c o m*/ */ @SuppressWarnings("unchecked") public Iterator<FileItem> readFrom(Class<Iterator<FileItem>> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException { try { ApplicationContext context = ApplicationContextImpl.getCurrent(); int bufferSize = context.getProperties().get(RequestHandler.WS_RS_BUFFER_SIZE) == null ? RequestHandler.WS_RS_BUFFER_SIZE_VALUE : Integer.parseInt(context.getProperties().get(RequestHandler.WS_RS_BUFFER_SIZE)); File repo = new File(context.getProperties().get(RequestHandler.WS_RS_TMP_DIR)); DefaultFileItemFactory factory = new DefaultFileItemFactory(bufferSize, repo); final FileUpload upload = new FileUpload(factory); return SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<Iterator<FileItem>>() { public Iterator<FileItem> run() throws Exception { return upload.parseRequest(httpRequest).iterator(); } }); } catch (PrivilegedActionException pae) { Throwable cause = pae.getCause(); if (cause instanceof FileUploadException) { throw new IOException("Can't process multipart data item " + cause, cause); } else if (cause instanceof RuntimeException) { throw (RuntimeException) cause; } else { throw new RuntimeException(cause); } } }