Examples of FileItemStream


Examples of org.apache.commons.fileupload.FileItemStream

        Lang lang = null ;

        try {
            FileItemIterator iter = upload.getItemIterator(action.request);
            while (iter.hasNext()) {
                FileItemStream item = iter.next();
                String fieldName = item.getFieldName();
                InputStream stream = item.openStream();
                if (item.isFormField())
                {
                    // Graph name.
                    String value = Streams.asString(stream, "UTF-8") ;
                    if ( fieldName.equals(HttpNames.paramGraph) )
                    {
                        graphName = value ;
                        if ( graphName != null && ! graphName.equals("") && ! graphName.equals(HttpNames.valueDefault) )
                        {
                            IRI iri = IRIResolver.parseIRI(value) ;
                            if ( iri.hasViolation(false) )
                                errorBadRequest("Bad IRI: "+graphName) ;
                            if ( iri.getScheme() == null )
                                errorBadRequest("Bad IRI: no IRI scheme name: "+graphName) ;
                            if ( iri.getScheme().equalsIgnoreCase("http") || iri.getScheme().equalsIgnoreCase("https"))
                            {
                                // Redundant??
                                if ( iri.getRawHost() == null )
                                    errorBadRequest("Bad IRI: no host name: "+graphName) ;
                                if ( iri.getRawPath() == null || iri.getRawPath().length() == 0 )
                                    errorBadRequest("Bad IRI: no path: "+graphName) ;
                                if ( iri.getRawPath().charAt(0) != '/' )
                                    errorBadRequest("Bad IRI: Path does not start '/': "+graphName) ;
                            }
                        }
                    }
                    else if ( fieldName.equals(HttpNames.paramDefaultGraphURI) )
                        graphName = null ;
                    else
                        // Add file type?
                        log.info(format("[%d] Upload: Field=%s ignored", action.id, fieldName)) ;
                } else {
                    // Process the input stream
                    name = item.getName() ;
                    if ( name == null || name.equals("") || name.equals("UNSET FILE NAME") )
                        errorBadRequest("No name for content - can't determine RDF syntax") ;

                    String contentTypeHeader = item.getContentType() ;
                    ct = ContentType.create(contentTypeHeader) ;

                    lang = RDFLanguages.contentTypeToLang(ct.getContentType()) ;

                    if ( lang == null ) {
View Full Code Here

Examples of org.apache.commons.fileupload.FileItemStream

          ServletFileUpload upload = new ServletFileUpload();
      FileItemIterator iterator = upload.getItemIterator(request);
            byte[] image = null;
            String contentType = null;
      while (iterator.hasNext()) {
              FileItemStream fileItem = iterator.next();
              InputStream stream = fileItem.openStream();

                if (fileItem.isFormField()) {
                  switch (fileItem.getFieldName()) {
            case "thought":
              userThought = Streams.asString(stream);
              break;
            case "name":
              name = Streams.asString(stream);
              break;
            default: break;
          }
                } else {
                    if ("image".equals(fileItem.getFieldName())) {
                      contentType = fileItem.getContentType();
                      ByteArrayOutputStream out = new ByteArrayOutputStream();
                        IOUtils.copy(stream, out);
                        IOUtils.closeQuietly(stream);
                        IOUtils.closeQuietly(out);
                        image = out.toByteArray();
View Full Code Here

Examples of org.apache.commons.fileupload.FileItemStream

          ServletFileUpload upload = new ServletFileUpload();
      FileItemIterator iterator = upload.getItemIterator(request);
            byte[] image = null;
            String contentType = null;
      while (iterator.hasNext()) {
              FileItemStream fileItem = iterator.next();
              InputStream stream = fileItem.openStream();

                if (fileItem.isFormField()) {
                  switch (fileItem.getFieldName()) {
            case "thought":
              userThought = Streams.asString(stream);
              break;
            case "name":
              name = Streams.asString(stream);
              break;
            case "id":
              id = NumberUtils.toLong(Streams.asString(stream), 0L);
              break;
            default: break;
          }
                } else {
                    if ("image".equals(fileItem.getFieldName())) {
                      contentType = fileItem.getContentType();
                      ByteArrayOutputStream out = new ByteArrayOutputStream();
                        IOUtils.copy(stream, out);
                        IOUtils.closeQuietly(stream);
                        IOUtils.closeQuietly(out);
                        image = out.toByteArray();
View Full Code Here

Examples of org.apache.commons.fileupload.FileItemStream

     * @return parameters and files
     */
    private MultipartParameters parseFileItems(FileItemIterator iterator) throws FileUploadException, IOException {
        MultipartParameters multipartParameters = new MultipartParameters();
        while (iterator.hasNext()) {
            FileItemStream fileItemStream = iterator.next();
            String fieldName = fileItemStream.getFieldName();
            if (fileItemStream.getContentType() == null) {
                // The FileItemStream represents a simple String parameter when there is no content type
                String fieldValue = FileCopyUtils.copyToString(new InputStreamReader(fileItemStream.openStream()));
                multipartParameters.addStringParameter(fieldName, fieldValue);
            } else {
                // The FileItemStream represents an actual file
                MultipartFile multipartFile = new CommonsStreamMultipartFile(fileItemStream);
                multipartParameters.addMultipartFileParameter(fieldName, multipartFile);
View Full Code Here

Examples of org.apache.commons.fileupload.FileItemStream

            FileItemIterator iter = upload.getItemIterator(requestContextWrapper);
            List<UploadContext> uploadContexts = new ArrayList<UploadContext>(7);
            List<NamedString> formParameters = new ArrayList<NamedString>(7);
            while (iter.hasNext())
            {
               FileItemStream item = iter.next();
               InputStream stream = item.openStream();
               if (!item.isFormField())
               {
                  String contentType = item.getContentType();
                  if (log.isDebugEnabled())
                  {
                     log.debug("File field " + item.getFieldName() + " with file name " + item.getName()
                        + " and content type " + contentType + " detected.");
                  }

                  BufferedInputStream bufIn = new BufferedInputStream(stream);
                  ByteArrayOutputStream baos = new ByteArrayOutputStream();
                  BufferedOutputStream bos = new BufferedOutputStream(baos);

                  int c = bufIn.read();
                  while (c != -1)
                  {
                     bos.write(c);
                     c = bufIn.read();
                  }

                  bos.flush();
                  baos.flush();
                  bufIn.close();
                  bos.close();

                  final byte[] uploadData = baos.toByteArray();
                  if (uploadData.length != 0)
                  {
                     UploadContext uploadContext = WSRPTypeFactory.createUploadContext(contentType, uploadData);

                     List<NamedString> mimeAttributes = new ArrayList<NamedString>(2);

                     String value = FileUpload.FORM_DATA + ";" + " name=\"" + item.getFieldName() + "\";" + " filename=\"" + item.getName() + "\"";
                     NamedString mimeAttribute = WSRPTypeFactory.createNamedString(FileUpload.CONTENT_DISPOSITION, value);
                     mimeAttributes.add(mimeAttribute);

                     mimeAttribute = WSRPTypeFactory.createNamedString(FileUpload.CONTENT_TYPE, item.getContentType());
                     mimeAttributes.add(mimeAttribute);

                     uploadContext.getMimeAttributes().addAll(mimeAttributes);

                     uploadContexts.add(uploadContext);
                  }
                  else
                  {
                     log.debug("Ignoring empty file " + item.getName());
                  }
               }
               else
               {
                  NamedString formParameter = WSRPTypeFactory.createNamedString(item.getFieldName(), Streams.asString(stream));
                  formParameters.add(formParameter);
               }
            }

            result.getUploadContexts().addAll(uploadContexts);
View Full Code Here

Examples of org.apache.commons.fileupload.FileItemStream

      // multipart request
      try {
        ServletFileUpload upload = new ServletFileUpload();
        FileItemIterator iter = upload.getItemIterator(request);
        while (iter.hasNext()) {
          FileItemStream item = iter.next();
          String name = item.getFieldName();
          InputStream stream = item.openStream();
          if (item.isFormField()) {
            requestParams.put(name, Streams.asString(stream));
          } else {
            String fileName = item.getName();
            if (fileName != null && !"".equals(fileName.trim())) {
              listFiles.add(item);

              ByteArrayOutputStream os = new ByteArrayOutputStream();
              IOUtils.copy(stream, os);
View Full Code Here

Examples of org.apache.commons.fileupload.FileItemStream

      upload.setSizeMax(MAX_FILE_SIZE);

      try {
        FileItemIterator iterator = upload.getItemIterator(request);
        while (iterator.hasNext()) {
          FileItemStream item = iterator.next();
          InputStream in = item.openStream();
          if ((!item.isFormField()) && (item.getFieldName().equals("file1"))) {
           
            String fileName = item.getName();
            if (fileName.length()>0){
              try {
                LineIterator it =  IOUtils.lineIterator(in, "UTF-8");
                while (it.hasNext()) {
                  String line = it.nextLine();
View Full Code Here

Examples of org.apache.commons.fileupload.FileItemStream

      upload.setSizeMax(maxUploadSize);
      upload.setProgressListener(listener);
     
      FileItemIterator iter = upload.getItemIterator(request);
      while (iter.hasNext()) {
          FileItemStream item = iter.next();
          String name = item.getFieldName();
          InputStream stream = item.openStream();
          if (item.isFormField()) {
            String value = Streams.asString(stream);

            logger.info("Upload "+name+":"+value);
           
            if( "progressId".equals(name) ) {
              progressId = value;
              listener.setProgressId(value);
            } else {
              // Add parameter to map
              List<String> paramList = parameterMap.get(name);
              if( null == paramList ) {
                paramList = new Vector<String>();
                parameterMap.put(name,paramList);
              }
              paramList.add(value);
            }
           
          } else {
           
            LoadedFileImpl loadedFile = new LoadedFileImpl();
            loadedFile.setParameterName(name);

            // Get original filename
            String fileName = item.getName();
              if (fileName != null) {
                fileName = fileName.trim();
                if( 0 == fileName.length() ) {
                  fileName = null;
                } else {
View Full Code Here

Examples of org.apache.commons.fileupload.FileItemStream

        FileItemIterator iter = upload.getItemIterator(context);
          //byte[] value;
          InputStream is;
          ArrayList<URLItem> list=new ArrayList<URLItem>();
      while (iter.hasNext()) {
          FileItemStream item = iter.next();

          is=IOUtil.toBufferedInputStream(item.openStream());
          if (item.getContentType()==null || StringUtil.isEmpty(item.getName())) {
            list.add(new URLItem(item.getFieldName(),new String(IOUtil.toBytes(is),encoding),false));      
          }
          else {
            tempFile=tempDir.getRealResource(getFileName());
            fileItems.put(item.getFieldName().toLowerCase(),
                new Item(tempFile,item.getContentType(),item.getName(),item.getFieldName()));
          String value=tempFile.toString();
            IOUtil.copy(is, tempFile,true);
           
            list.add(new URLItem(item.getFieldName(),value,false));      
          }      
      }
     
      raw= list.toArray(new URLItem[list.size()]);
      fillDecoded(raw,encoding,scriptProteced,pc.getApplicationContext().getSameFieldAsArray(SCOPE_FORM));
View Full Code Here

Examples of org.apache.commons.fileupload.FileItemStream

                Map<String, String[]> params = new HashMap<String, String[]>();
                InputStream fileStream = null;
                ServletFileUpload upload = new ServletFileUpload();
                FileItemIterator iter = upload.getItemIterator(request);
                while (iter.hasNext()) {
                    FileItemStream fileItemStream = iter.next();
                    if (fileItemStream.isFormField()) {
                        String fieldName = fileItemStream.getFieldName();
                        if ("content".equals(fieldName)) {
                            utf8 = true;
                            String[] parser = params.get("parser");
                            if (parser != null && parser[0].startsWith("xml")) {
                                contentType = "application/xml";
                            } else {
                                contentType = "text/html";
                            }
                            request.setAttribute("nu.validator.servlet.MultipartFormDataFilter.type", "textarea");
                            fileStream = fileItemStream.openStream();
                            break;
                        } else {
                            putParam(
                                    params,
                                    fieldName,
                                    utf8ByteStreamToString(fileItemStream.openStream()));
                        }
                    } else {
                        String fileName = fileItemStream.getName();
                        if (fileName != null) {
                            putParam(params, fileItemStream.getFieldName(),
                                    fileName);
                            Matcher m = EXTENSION.matcher(fileName);
                            if (m.matches()) {
                                contentType = EXTENSION_TO_TYPE.get(m.group(1));
                            }
                        }
                        if (contentType == null) {
                            contentType = fileItemStream.getContentType();
                        }
                        request.setAttribute("nu.validator.servlet.MultipartFormDataFilter.type", "file");
                        fileStream = fileItemStream.openStream();
                        break;
                    }
                }
                if (fileStream == null) {
                    fileStream = new ByteArrayInputStream(new byte[0]);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.