Examples of FileItemStream


Examples of org.apache.commons.fileupload.FileItemStream

        try {
            iterator = upload.getItemIterator(request);

            while (iterator.hasNext()) {
                final FileItemStream item = iterator.next();
                final InputStream stream = item.openStream();

                final JSONObject preference = preferenceUtils.getPreference();
                if (null == preference) {
                    response.sendError(HttpServletResponse.SC_NOT_FOUND);
                    return;
                }

                final String localeString = preference.getString(
                        Preference.LOCALE_STRING);
                final Locale locale = new Locale(
                        Locales.getLanguage(localeString),
                        Locales.getCountry(localeString));
                if (!item.isFormField()) {
                    final ResourceBundle lang =
                            ResourceBundle.getBundle(Keys.LANGUAGE, locale);
                    // XXX: check size before streaming
                    final byte[] contentBytes = IOUtils.toByteArray(stream);
                    if (contentBytes.length > MAX_SIZE) {
                        final String fail = lang.getString("uploadFailLabel");
                        final String cause =
                                lang.getString("exceedMaxUploadSizeLabel");
                        sendError(request, response,
                                  HttpServletResponse.SC_BAD_REQUEST,
                                  fail, cause);
                        return;
                    }

                    if (0 == contentBytes.length) {
                        final String fail = lang.getString("uploadFailLabel");
                        final String cause = lang.getString("fileEmptyLabel");
                        sendError(request, response,
                                  HttpServletResponse.SC_BAD_REQUEST,
                                  fail, cause);
                        return;
                    }

                    final Blob blob = new Blob(contentBytes);
                    final JSONObject file = new JSONObject();
                    final String id = Ids.genTimeMillisId();
                    file.put(Keys.OBJECT_ID, id);

                    file.put(File.FILE_CONTENT_TYPE, item.getContentType());
                    file.put(File.FILE_CONTENT, blob);

                    file.put(File.FILE_DOWNLOAD_COUNT, 0);
                    final String timeZoneId =
                            preference.getString(Preference.TIME_ZONE_ID);
                    final Date createDate = timeZoneUtils.getTime(timeZoneId);
                    file.put(File.FILE_UPLOAD_DATE, createDate);
                    final String fileName = item.getName();
                    file.put(File.FILE_NAME, fileName);
                    final long fileSize = contentBytes.length;
                    file.put(File.FILE_SIZE, fileSize);
                    final String downloadURL = "/datastore-file-access.do?oId="
                                               + id;
View Full Code Here

Examples of org.apache.commons.fileupload.FileItemStream

         if (fac == null) {
             throw new NullPointerException(
                 "No FileItemFactory has been set.");
         }
         while (iter.hasNext()) {
             FileItemStream item = iter.next();
             HttpFileItem fileItem = new HttpFileItem(fac.createItem(item.getFieldName(),
                     item.getContentType(), item.isFormField(),
                     item.getName())
             );
             try {
               MessageDigestInputStream in = new MessageDigestInputStream(
                   item.openStream(), algorithm);
                 Streams.copy(in, fileItem.getOutputStream(), true);
                
                 fileItem.setDigest(in.getDigest());
             } catch (FileUploadIOException e) {
                 throw (FileUploadException) e.getCause();
View Full Code Here

Examples of org.apache.commons.fileupload.FileItemStream

        if (isMultipart) {
            ServletFileUpload upload = new ServletFileUpload();
            FileItemIterator iter = upload.getItemIterator(request);

            while (iter.hasNext()) {
                FileItemStream item = iter.next();
                String name = item.getFieldName();
                InputStream itemStream = new BufferedInputStream(item.openStream());

                if (item.isFormField()) {
                    InputStreamReader reader = new InputStreamReader(itemStream, "UTF-8");

                    try {
                        StringBuilder sb = new StringBuilder();

                        char[] buffer = new char[64 * 1024];
                        int b = 0;
                        while ((b = reader.read(buffer)) > -1) {
                            sb.append(buffer, 0, b);
                        }

                        addParameter(name, sb.toString());
                    } finally {
                        try {
                            reader.close();
                        } catch (Exception e) {
                            // ignore
                        }
                    }
                } else {
                    filename = item.getName();
                    contentType = (item.getContentType() == null ? Constants.MEDIATYPE_OCTETSTREAM : item
                            .getContentType());

                    ThresholdOutputStream os = new ThresholdOutputStream(tempDir, memoryThreshold);

                    try {
View Full Code Here

Examples of org.apache.commons.fileupload.FileItemStream

        ServletFileUpload upload = new ServletFileUpload();
        upload.setFileSizeMax(maxFileSize);
        try {
            FileItemIterator it = upload.getItemIterator(target);
            while (it.hasNext()) {
                FileItemStream item = it.next();
                if (item.isFormField()) {
                    InputStream input = null;
                    try {
                        input = item.openStream();
                        String fieldName = item.getFieldName();
                        String encode = request.getCharacterEncoding();
                        String fieldValue = encode==null ? Streams.asString(input) : Streams.asString(input, encode);
                        addFormItem(fieldName, fieldValue);
                    }
                    finally {
View Full Code Here

Examples of org.apache.commons.fileupload.FileItemStream

    // Get the image representation
    try{
        ServletFileUpload upload = new ServletFileUpload();
        FileItemIterator iter = upload.getItemIterator(req);
        while(iter.hasNext()){
          FileItemStream imageItem = iter.next();
          InputStream imgStream = imageItem.openStream();
          byte[] data = IOUtils.toByteArray(imgStream);
          imgStream.close();
          if(!imageItem.isFormField() && data.length>0){
            log.info("Is a file: "+imageItem.getName());
            Blob imageBlob = new Blob(resizeImage(data));
            images.put(imageItem.getName(), imageBlob);
          }
        }
        ArticlesOAM oam = provider.get();
        UserService userService = UserServiceFactory.getUserService();
          User user = userService.getCurrentUser();
View Full Code Here

Examples of org.apache.commons.fileupload.FileItemStream

                fileUpload.setFileSizeMax(cfg.getFileUploadFileSizeMax());
            }
            try {
                FileItemIterator it = fileUpload.getItemIterator(request);
                while (it.hasNext()) {
                    FileItemStream fis = it.next();
                    if (fis.isFormField()) {
                        String s = Streams.asString(fis.openStream(), cfg.getCharset());
                        Object o = params.get(fis.getFieldName());
                        if (o == null) {
                            params.put(fis.getFieldName(), new String[]{s});
                        } else if (o instanceof String[]) {
                            String[] ss = (String[]) o;
                            String[] nss = new String[ss.length + 1];
                            System.arraycopy(ss, 0, nss, 0, ss.length);
                            nss[ss.length] = s;
                            params.put(fis.getFieldName(), nss);
                        }
                    } else if (!fis.getName().isEmpty()) {
                        FileExImpl fileEx = new FileExImpl(File.createTempFile("wfu", null));
                        Object o = params.get(fis.getFieldName());
                        if (o == null) {
                            params.put(fis.getFieldName(), new FileEx[]{fileEx});
                        } else if (o instanceof FileEx[]) {
                            FileEx[] ss = (FileEx[]) o;
                            FileEx[] nss = new FileEx[ss.length + 1];
                            System.arraycopy(ss, 0, nss, 0, ss.length);
                            nss[ss.length] = fileEx;
                            params.put(fis.getFieldName(), nss);
                        }
                        Streams.copy(fis.openStream(), new FileOutputStream(fileEx.getFile()), true);
                        fileEx.fileName = fis.getName();
                        fileEx.contentType = fis.getContentType();
                    }
                }
            } catch (FileUploadException e) {
                if (action instanceof FileUploadExceptionAware) {
                    ((FileUploadExceptionAware) action).setFileUploadException(e);
View Full Code Here

Examples of org.apache.commons.fileupload.FileItemStream

        int tripleCount = 0 ;

        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(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.parse(contentTypeHeader) ;

                    lang = WebContent.contentTypeToLang(ct.getContentType()) ;
                    if ( lang == null )
                        lang = RDFLanguages.filenameToLang(name) ;
View Full Code Here

Examples of org.apache.commons.fileupload.FileItemStream

   
    try {
      FileItemIterator i = new ServletFileUpload().getItemIterator(req);

      while (i.hasNext()) {
        FileItemStream item = i.next();
        InputStream stream = item.openStream();
        try {
          String randomId = UUID.randomUUID().toString()// cache ID
          byte[] rawData = FileUtil.toByteArray(stream)// cache data

          memcache.put(randomId, rawData);
          logger.info("Cached uploaded file id : " + randomId + " with size = " + rawData.length);
         
          CacheUploadResult result = AutoBeanUtil.newCacheUploadResult(Status.SUCCESS, randomId, item.getName(), rawData.length);
          resultStr = AutoBeanUtil.encode(CacheUploadResult.class, result);
        } finally {
          stream.close();
        }
      }
View Full Code Here

Examples of org.apache.commons.fileupload.FileItemStream

      // step1 : extract data from the request
      String fileName = null;
      byte[] rawData = null;
     
      while (i.hasNext()) {
        FileItemStream item = i.next();
        
        InputStream stream = item.openStream();
       
        byte [] content = FileUtil.toByteArray(stream);
       
        try {
          if (item.isFormField()) {  // filename         
            fileName = new String(content);
          } else // rawdata
            rawData = content;   
         
        } finally {
View Full Code Here

Examples of org.apache.commons.fileupload.FileItemStream

        // Parse the request
        try {
            FileItemIterator iter = upload.getItemIterator(request);
            while (iter.hasNext() == true) {
                FileItemStream item = iter.next();
                String name = item.getName();
                InputStream stream = item.openStream();
                if (item.isFormField() == false) {
                    ContentResource child = (ContentResource)
                            dir.createChild(name, ContentNode.Type.RESOURCE);

                    File tmp = File.createTempFile("contentupload", "tmp");
                    RunUtil.writeToFile(stream, tmp);
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.