Package org.apache.commons.fileupload

Examples of org.apache.commons.fileupload.FileItemStream


      // Multipart form encoding?
      if (ServletFileUpload.isMultipartContent(request)) {
        try {
          ServletFileUpload payload = new ServletFileUpload();
          for (FileItemIterator iter = payload.getItemIterator(request); iter.hasNext();) {
            FileItemStream item = iter.next();
            String fieldName = item.getFieldName();
            if (item.isFormField()) {
              String fieldValue = Streams.asString(item.openStream());
              if (StringUtils.isBlank(fieldValue))
                continue;
              if (OPT_PATH.equals(fieldName)) {
                path = fieldValue;
              } else if (OPT_LANGUAGE.equals(fieldName)) {
                try {
                  language = LanguageUtils.getLanguage(fieldValue);
                } catch (UnknownLanguageException e) {
                  throw new WebApplicationException(Status.BAD_REQUEST);
                }
              } else if (OPT_MIMETYPE.equals(fieldName)) {
                mimeType = fieldValue;
              }
            } else {
              // once the body gets read iter.hasNext must not be invoked
              // or the stream can not be read
              fileName = StringUtils.trim(item.getName());
              mimeType = StringUtils.trim(item.getContentType());
              uploadedFile = File.createTempFile("upload-", null);
              FileOutputStream fos = new FileOutputStream(uploadedFile);
              try {
                IOUtils.copy(item.openStream(), fos);
              } catch (IOException e) {
                throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
              } finally {
                IOUtils.closeQuietly(fos);
              }
View Full Code Here


      List<T> rows = new ArrayList<T>();
        ServletFileUpload upload = new ServletFileUpload();
        FileItemIterator iter = upload.getItemIterator(request);
       
        while (iter.hasNext()) {
            FileItemStream item = iter.next();
           
            if (!item.isFormField()) {
              InputStream stream = item.openStream();
             
              switch (type) {
        case TEXT:
                  rows.addAll((List<T>) readTextRows(stream));
          break;
        case CSV:
                  rows.addAll((List<T>) readCSVRows(stream));
          break;
        case BINARY:
          rows.add((T)readBinaryFile(stream, item.getName()));
          break;
        default:
          break;
        }
            }
View Full Code Here

TOP

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

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.