Package org.apache.commons.fileupload

Examples of org.apache.commons.fileupload.FileUpload


        if (!MemoryControl.request(request.getContentLength() * 3, false)) {
          throw new IOException("not enough memory available for request. request.getContentLength() = " + request.getContentLength() + ", MemoryControl.available() = " + MemoryControl.available());
        }

        // parse data in memory
        final FileUpload upload = new FileUpload(DISK_FILE_ITEM_FACTORY);
        final List<FileItem> items;

        try {
            items = upload.parseRequest(request);
        } catch (FileUploadException e) {
            throw new IOException("FileUploadException " + e.getMessage());
        }

        // format information for further usage
View Full Code Here


               ? 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)
      {
View Full Code Here

  public MultipartFormData readFrom(Class<MultipartFormData> type, Type genericType, Annotation[] annotations, MediaType mediaType,
      MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {

    final MultipartFormData multipartFormData = createMultipartFormDataInstance();
    final FileUpload fileUpload = createFileUploadInstance();

    String contentType = httpHeaders.getFirst("content-type");
    RestMultipartRequestContext requestContext = createRequestContext(entityStream, contentType);

    // parse the request (populates the multipartFormData)
View Full Code Here

    return multipartFormData;

  }

  protected FileUpload createFileUploadInstance() {
    return new FileUpload();
  }
View Full Code Here

      try
      {
         if (FileUpload.isMultipartContent(requestContext))
         {
            // content is multipart, we need to parse it (that includes form parameters)
            FileUpload upload = new FileUpload();
            FileItemIterator iter = upload.getItemIterator(requestContext);
            List<UploadContext> uploadContexts = new ArrayList<UploadContext>(7);
            List<NamedString> formParameters = new ArrayList<NamedString>(7);
            while (iter.hasNext())
            {
               FileItemStream item = iter.next();
View Full Code Here

   * @return the parsing result
   * @throws MultipartException if multipart resolution failed.
   */
  protected MultipartParsingResult parseRequest(HttpServletRequest request) throws MultipartException {
    String encoding = determineEncoding(request);
    FileUpload fileUpload = prepareFileUpload(encoding);
    try {
      List fileItems = ((ServletFileUpload) fileUpload).parseRequest(request);
      return parseFileItems(fileItems, encoding);
    }
    catch (FileUploadBase.SizeLimitExceededException ex) {
      throw new MaxUploadSizeExceededException(fileUpload.getSizeMax(), ex);
    }
    catch (FileUploadException ex) {
      throw new MultipartException("Could not parse multipart servlet request", ex);
    }
  }
View Full Code Here

   * with the same configuration other than the desired encoding.
   * @param encoding the character encoding to use
   * @return an appropriate FileUpload instance.
   */
  protected FileUpload prepareFileUpload(String encoding) {
    FileUpload fileUpload = getFileUpload();
    FileUpload actualFileUpload = fileUpload;

    // Use new temporary FileUpload instance if the request specifies
    // its own encoding that does not match the default encoding.
    if (encoding != null && !encoding.equals(fileUpload.getHeaderEncoding())) {
      actualFileUpload = newFileUpload(getFileItemFactory());
      actualFileUpload.setSizeMax(fileUpload.getSizeMax());
      actualFileUpload.setHeaderEncoding(encoding);
    }

    return actualFileUpload;
  }
View Full Code Here

    @SuppressWarnings("unchecked")
    public List<FileItem> readFrom(Class<List<FileItem>> type,
            Type genericType, Annotation[] annotations, MediaType mediaType,
            final MultivaluedMap<String, String> respHeaders,
            final InputStream entityStream) throws IOException {
        final FileUpload rfu = new FileUpload();
        final RequestContext requCtx = new RequestContext(entityStream,
                respHeaders);
        try {
            return rfu.parseRequest(requCtx);
        } catch (FileUploadException e) {
            if (e.getCause() instanceof IOException) {
                throw (IOException) e.getCause();
            }
            final IOException ioExc = new IOException(
View Full Code Here

        if (ServletFileUpload.isMultipartContent(new ServletRequestContext(request))) {
            //Used to communicate to clients of multipart data if the request processing worked correctly
            UploadStatus uploadStatus;
           
            final String encoding = this.determineEncoding(request);
            final FileUpload fileUpload = this.prepareFileUpload(encoding);
            try {
                final List<FileItem> fileItems = ((ServletFileUpload) fileUpload).parseRequest(request);
                final MultipartParsingResult parsingResult = parseFileItems(fileItems, encoding);
               
                final Map<String, MultipartDataSource[]> multipartDataSources = this.getMultipartDataSources(parsingResult);
View Full Code Here

   *
   * @param encoding the character encoding to use
   * @return an appropriate FileUpload instance.
   */
  protected FileUpload prepareFileUpload(String encoding) {
    FileUpload fileUpload = getFileUpload();
    FileUpload actualFileUpload = fileUpload;

    // Use new temporary FileUpload instance if the request specifies
    // its own encoding that does not match the default encoding.
    if (encoding != null && !encoding.equals(fileUpload.getHeaderEncoding())) {
      actualFileUpload = newFileUpload(getFileItemFactory());
      actualFileUpload.setSizeMax(fileUpload.getSizeMax());
      actualFileUpload.setHeaderEncoding(encoding);
    }

    return actualFileUpload;
  }
View Full Code Here

TOP

Related Classes of org.apache.commons.fileupload.FileUpload

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.