Java Code Examples for org.apache.commons.fileupload.util.Streams

The following examples show how to use org.apache.commons.fileupload.util.Streams. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: httplite   Source File: MiscHandle.java    License: Apache License 2.0 5 votes vote down vote up
private String handleMultipart(RecordedRequest request) {
    RecordedUpload upload = new RecordedUpload(request);
    Exception exception;
    try {
        Map<String,String> params = new HashMap<>();
        FileItemIterator iter = upload.getItemIterator();
        while (iter.hasNext()) {
            FileItemStream item = iter.next();
            String name = item.getFieldName();
            InputStream stream = item.openStream();
            if (item.isFormField()) {
                String value = Streams.asString(stream);
                System.out.println("Form field " + name + " with value "
                        + value + " detected.");
                params.put(name,value);
            } else {
                System.out.println("File field " + name + " with file name "
                        + item.getName() + " detected.");
                params.put(name, "file->"+item.getName());
            }
        }
        return "Multipart:"+JSON.toJSONString(params);
    } catch (Exception e) {
        exception = e;
    }
    return "Multipart:error->"+exception;
}
 
Example 2
Source Project: kurento-java   Source File: RepositoryHttpServlet.java    License: Apache License 2.0 5 votes vote down vote up
private void uploadMultipart(HttpServletRequest req, HttpServletResponse resp,
    OutputStream repoItemOutputStrem) throws IOException {

  log.debug("Multipart detected");

  ServletFileUpload upload = new ServletFileUpload();

  try {

    // Parse the request
    FileItemIterator iter = upload.getItemIterator(req);
    while (iter.hasNext()) {
      FileItemStream item = iter.next();
      String name = item.getFieldName();
      try (InputStream stream = item.openStream()) {
        if (item.isFormField()) {
          // TODO What to do with this?
          log.debug("Form field {} with value {} detected.", name, Streams.asString(stream));
        } else {

          // TODO Must we support multiple files uploading?
          log.debug("File field {} with file name detected.", name, item.getName());

          log.debug("Start to receive bytes (estimated bytes)",
              Integer.toString(req.getContentLength()));
          int bytes = IOUtils.copy(stream, repoItemOutputStrem);
          resp.setStatus(SC_OK);
          log.debug("Bytes received: {}", Integer.toString(bytes));
        }
      }
    }

  } catch (FileUploadException e) {
    throw new IOException(e);
  }
}
 
Example 3
Source Project: SI   Source File: HeritFormBasedFileUtil.java    License: BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
    * 파일을 Upload 처리한다.
    *
    * @param request
    * @param where
    * @param maxFileSize
    * @return
    * @throws Exception
    */
   public static List<HeritFormBasedFileVO> uploadFiles(HttpServletRequest request, String where, long maxFileSize) throws Exception {
List<HeritFormBasedFileVO> list = new ArrayList<HeritFormBasedFileVO>();

// Check that we have a file upload request
boolean isMultipart = ServletFileUpload.isMultipartContent(request);

if (isMultipart) {
    // Create a new file upload handler
    ServletFileUpload upload = new ServletFileUpload();
    upload.setFileSizeMax(maxFileSize);	// SizeLimitExceededException

    // Parse the request
    FileItemIterator iter = upload.getItemIterator(request);
    while (iter.hasNext()) {
        FileItemStream item = iter.next();
        String name = item.getFieldName();
        InputStream stream = item.openStream();
        if (item.isFormField()) {
            ////System.out.println("Form field '" + name + "' with value '" + Streams.asString(stream) + "' detected.");
            Logger.getLogger(HeritFormBasedFileUtil.class).info("Form field '" + name + "' with value '" + Streams.asString(stream) + "' detected.");
        } else {
            ////System.out.println("File field '" + name + "' with file name '" + item.getName() + "' detected.");
            Logger.getLogger(HeritFormBasedFileUtil.class).info("File field '" + name + "' with file name '" + item.getName() + "' detected.");

            if ("".equals(item.getName())) {
        	continue;
            }

            // Process the input stream
            HeritFormBasedFileVO vo = new HeritFormBasedFileVO();

            String tmp = item.getName();

            if (tmp.lastIndexOf("\\") >= 0) {
        	tmp = tmp.substring(tmp.lastIndexOf("\\") + 1);
            }

            vo.setFileName(tmp);
            vo.setContentType(item.getContentType());
            vo.setServerSubPath(getTodayString());
            vo.setPhysicalName(getPhysicalFileName());

            if (tmp.lastIndexOf(".") >= 0) {
        	 vo.setPhysicalName(vo.getPhysicalName() + tmp.substring(tmp.lastIndexOf(".")));
            }

            long size = saveFile(stream, new File(HeritWebUtil.filePathBlackList(where) + SEPERATOR + vo.getServerSubPath() + SEPERATOR + vo.getPhysicalName()));

            vo.setSize(size);

            list.add(vo);
        }
    }
} else {
    throw new IOException("form's 'enctype' attribute have to be 'multipart/form-data'");
}

return list;
   }
 
Example 4
Source Project: SI   Source File: HeritFormBasedFileUtil.java    License: BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
    * 파일을 Upload 처리한다.
    *
    * @param request
    * @param where
    * @param maxFileSize
    * @return
    * @throws Exception
    */
   public static List<HeritFormBasedFileVO> uploadFiles(HttpServletRequest request, String where, long maxFileSize) throws Exception {
List<HeritFormBasedFileVO> list = new ArrayList<HeritFormBasedFileVO>();

// Check that we have a file upload request
boolean isMultipart = ServletFileUpload.isMultipartContent(request);

if (isMultipart) {
    // Create a new file upload handler
    ServletFileUpload upload = new ServletFileUpload();
    upload.setFileSizeMax(maxFileSize);	// SizeLimitExceededException

    // Parse the request
    FileItemIterator iter = upload.getItemIterator(request);
    while (iter.hasNext()) {
        FileItemStream item = iter.next();
        String name = item.getFieldName();
        InputStream stream = item.openStream();
        if (item.isFormField()) {
            ////System.out.println("Form field '" + name + "' with value '" + Streams.asString(stream) + "' detected.");
            Logger.getLogger(HeritFormBasedFileUtil.class).info("Form field '" + name + "' with value '" + Streams.asString(stream) + "' detected.");
        } else {
            ////System.out.println("File field '" + name + "' with file name '" + item.getName() + "' detected.");
            Logger.getLogger(HeritFormBasedFileUtil.class).info("File field '" + name + "' with file name '" + item.getName() + "' detected.");

            if ("".equals(item.getName())) {
        	continue;
            }

            // Process the input stream
            HeritFormBasedFileVO vo = new HeritFormBasedFileVO();

            String tmp = item.getName();

            if (tmp.lastIndexOf("\\") >= 0) {
        	tmp = tmp.substring(tmp.lastIndexOf("\\") + 1);
            }

            vo.setFileName(tmp);
            vo.setContentType(item.getContentType());
            vo.setServerSubPath(getTodayString());
            vo.setPhysicalName(getPhysicalFileName());

            if (tmp.lastIndexOf(".") >= 0) {
        	 vo.setPhysicalName(vo.getPhysicalName() + tmp.substring(tmp.lastIndexOf(".")));
            }

            long size = saveFile(stream, new File(HeritWebUtil.filePathBlackList(where) + SEPERATOR + vo.getServerSubPath() + SEPERATOR + vo.getPhysicalName()));

            vo.setSize(size);

            list.add(vo);
        }
    }
} else {
    throw new IOException("form's 'enctype' attribute have to be 'multipart/form-data'");
}

return list;
   }
 
Example 5
Source Project: studio   Source File: WebdavController.java    License: GNU General Public License v3.0 4 votes vote down vote up
/**
 * Uploads a file to a WebDAV server
 * @param request the request
 * @return the uploaded item
 * @throws IOException if there is any error reading the content of the file
 * @throws WebDavException if there is any error uploading the file to the WebDAV server
 * @throws InvalidParametersException if there is any error parsing the request
 */
@PostMapping("/upload")
public ResultOne<WebDavItem> uploadItem(HttpServletRequest request) throws IOException, WebDavException,
    InvalidParametersException {
    if (ServletFileUpload.isMultipartContent(request)) {
        ResultOne<WebDavItem> result = new ResultOne<>();
        try {
            ServletFileUpload upload = new ServletFileUpload();
            FileItemIterator iterator = upload.getItemIterator(request);
            String siteId = null;
            String profileId = null;
            String path = null;
            if (!iterator.hasNext()) {
                throw new InvalidParametersException("Request body is empty");
            }
            while (iterator.hasNext()) {
                FileItemStream item = iterator.next();
                String name = item.getFieldName();
                try(InputStream stream = item.openStream()) {
                    if (item.isFormField()) {
                        switch (name) {
                            case REQUEST_PARAM_SITEID:
                                siteId = Streams.asString(stream);
                                break;
                            case REQUEST_PARAM_PROFILE_ID:
                                profileId = Streams.asString(stream);
                                break;
                            case REQUEST_PARAM_PATH:
                                path = Streams.asString(stream);
                            default:
                                // Unknown parameter, just skip it...
                        }
                    } else {
                        String filename = item.getName();
                        if (StringUtils.isNotEmpty(filename)) {
                            filename = FilenameUtils.getName(filename);
                        }
                        result.setEntity(RESULT_KEY_ITEM,
                            webDavService.upload(siteId, profileId, path, filename, stream));
                        result.setResponse(ApiResponse.OK);
                    }
                }
            }
            return result;
        } catch (FileUploadException e) {
            throw new InvalidParametersException("The request body is invalid");
        }
    } else {
        throw new InvalidParametersException("The request is not multipart");
    }
}
 
Example 6
/**
 * Uploads a file to S3 and triggers a MediaConvert job
 *
 * @param request the request
 * @return the result of triggering the job
 * @throws IOException if there is any error reading the content of the file
 * @throws AwsException if there is any error uploading the file or triggering the job
 * @throws InvalidParametersException if there is any error parsing the request
 */
@PostMapping("/upload")
public ResultOne<MediaConvertResult> uploadVideo(HttpServletRequest request)
    throws IOException, AwsException, InvalidParametersException {
    if (ServletFileUpload.isMultipartContent(request)) {
        ResultOne<MediaConvertResult> result = new ResultOne<>();
        try {
            ServletFileUpload upload = new ServletFileUpload();
            FileItemIterator iterator = upload.getItemIterator(request);
            String siteId = null;
            String inputProfileId = null;
            String outputProfileId = null;
            while (iterator.hasNext()) {
                FileItemStream item = iterator.next();
                String name = item.getFieldName();
                try (InputStream stream = item.openStream()) {
                    if (item.isFormField()) {
                        switch (name) {
                            case REQUEST_PARAM_SITEID:
                                siteId = Streams.asString(stream);
                                break;
                            case INPUT_PROFILE_PARAM:
                                inputProfileId = Streams.asString(stream);
                                break;
                            case OUTPUT_PROFILE_PARAM:
                                outputProfileId = Streams.asString(stream);
                                break;
                            default:
                                // Unknown parameter, just skip it...
                        }
                    } else {
                        if (StringUtils.isAnyEmpty(siteId, inputProfileId, outputProfileId)) {
                            throw new InvalidParametersException("Missing one or more required parameters: "
                                + "siteId, inputProfileId or outputProfileId");
                        }
                        String filename = item.getName();
                        if (StringUtils.isNotEmpty(filename)) {
                            filename = FilenameUtils.getName(filename);
                        }
                        result.setEntity(RESULT_KEY_ITEM,
                            mediaConvertService
                                .uploadVideo(siteId, inputProfileId, outputProfileId, filename, stream));
                        result.setResponse(ApiResponse.OK);
                    }
                }
            }
            return result;
        } catch (FileUploadException e) {
            throw new InvalidParametersException("The request body is invalid");
        }
    } else {
        throw new InvalidParametersException("The request is not multipart");
    }
}
 
Example 7
Source Project: studio   Source File: AwsS3Controller.java    License: GNU General Public License v3.0 4 votes vote down vote up
/**
 * Upload a file to an S3 bucket.
 * @param request the request
 * @return the item uploaded
 * @throws IOException if there is any error reading the content of the file
 * @throws InvalidParametersException if there is any error parsing the request
 * @throws AwsException if there is any error connecting to S3
 */
@PostMapping("/upload")
public ResultOne<S3Item> uploadItem(HttpServletRequest request) throws IOException, InvalidParametersException,
    AwsException {
    if(ServletFileUpload.isMultipartContent(request)) {
        ResultOne<S3Item> result = new ResultOne<>();
        try {
            ServletFileUpload upload = new ServletFileUpload();
            FileItemIterator iterator = upload.getItemIterator(request);
            String siteId = null;
            String profileId = null;
            String path = null;
            while (iterator.hasNext()) {
                FileItemStream item = iterator.next();
                String name = item.getFieldName();
                try(InputStream stream = item.openStream()) {
                    if (item.isFormField()) {
                        switch (name) {
                            case REQUEST_PARAM_SITEID:
                                siteId = Streams.asString(stream);
                                break;
                            case REQUEST_PARAM_PROFILE_ID:
                                profileId = Streams.asString(stream);
                                break;
                            case REQUEST_PARAM_PATH:
                                path = Streams.asString(stream);
                            default:
                                // Unknown parameter, just skip it...
                        }
                    } else {
                        String filename = item.getName();
                        if (StringUtils.isNotEmpty(filename)) {
                            filename = FilenameUtils.getName(filename);
                        }
                        result.setEntity(RESULT_KEY_ITEM,
                            s3Service.uploadItem(siteId, profileId, path, filename, stream));
                        result.setResponse(ApiResponse.OK);
                    }
                }
            }
            return result;
        } catch (FileUploadException e) {
            throw new InvalidParametersException("The request body is invalid");
        }
    } else {
        throw new InvalidParametersException("The request is not multipart");
    }
}
 
Example 8
Source Project: studio   Source File: CmisController.java    License: GNU General Public License v3.0 4 votes vote down vote up
@PostMapping(value = "/api/2/cmis/upload")
public ResponseBody uploadContent(HttpServletRequest httpServletRequest)
        throws IOException, CmisUnavailableException, CmisPathNotFoundException, CmisTimeoutException,
        CmisRepositoryNotFoundException, FileUploadException, InvalidParametersException {

    ServletFileUpload servletFileUpload = new ServletFileUpload();
    FileItemIterator itemIterator = servletFileUpload.getItemIterator(httpServletRequest);
    String filename = StringUtils.EMPTY;
    String siteId = StringUtils.EMPTY;
    String cmisRepoId = StringUtils.EMPTY;
    String cmisPath = StringUtils.EMPTY;
    CmisUploadItem cmisUploadItem = new CmisUploadItem();
    while (itemIterator.hasNext()) {
        FileItemStream item = itemIterator.next();
        String name = item.getFieldName();
        try (InputStream stream = item.openStream()) {
            if (item.isFormField()) {
                switch (name) {
                    case REQUEST_PARAM_SITEID:
                        siteId = Streams.asString(stream);
                        break;
                    case REQUEST_PARAM_CMIS_REPO_ID:
                        cmisRepoId = Streams.asString(stream);
                        break;
                    case REQUEST_PARAM_CMIS_PATH:
                        cmisPath = Streams.asString(stream);
                        break;
                    default:
                        // Unknown parameter, just skip it...
                        break;
                }
            } else {
                filename = item.getName();
                if (StringUtils.isEmpty(siteId)) {
                    throw new InvalidParametersException("Invalid siteId");
                }
                if (StringUtils.isEmpty(cmisRepoId)) {
                    throw new InvalidParametersException("Invalid cmisRepoId");
                }
                if (StringUtils.isEmpty(cmisPath)) {
                    throw new InvalidParametersException("Invalid cmisPath");
                }
                cmisUploadItem = cmisService.uploadContent(siteId, cmisRepoId, cmisPath, filename, stream);
            }
        }
    }
    ResponseBody responseBody = new ResponseBody();
    ResultOne<CmisUploadItem> result = new ResultOne<CmisUploadItem>();
    result.setResponse(OK);
    result.setEntity(RESULT_KEY_ITEM, cmisUploadItem);
    responseBody.setResult(result);
    return responseBody;
}
 
Example 9
Source Project: cms   Source File: FileController.java    License: Apache License 2.0 4 votes vote down vote up
public void uploadFolder(HttpServletRequest request, HttpServletResponse response, String requestUri) throws WPBException
  {
org.json.JSONObject returnJson = new org.json.JSONObject();
WPBAuthenticationResult authenticationResult = this.handleAuthentication(request);
if (! isRequestAuthenticated(authenticationResult))
{
	httpServletToolbox.writeBodyResponseAsJson(response, returnJson, null, authenticationResult);
	return ;
}

      try
      {
            ServletFileUpload upload = new ServletFileUpload();
            upload.setHeaderEncoding("UTF-8");
            FileItemIterator iterator = upload.getItemIterator(request);
            WPBFile ownerFile = null;
            Map<String, WPBFile> subfolderFiles = new HashMap<String, WPBFile>();
            
            while (iterator.hasNext()) {
              FileItemStream item = iterator.next();
             
              if (item.isFormField() && item.getFieldName().equals("ownerExtKey"))
              {
                  String ownerExtKey = Streams.asString(item.openStream());
                  ownerFile = getDirectory(ownerExtKey, adminStorage);	            
              } else
              if (!item.isFormField() && item.getFieldName().equals("file")) {
                
                String fullName = item.getName();
                String directoryPath = getDirectoryFromLongName(fullName);
                String fileName = getFileNameFromLongName(fullName);
                
                Map<String, WPBFile> tempSubFolders = checkAndCreateSubDirectory(directoryPath, ownerFile);
                subfolderFiles.putAll(tempSubFolders);
                
                // delete the existing file
                WPBFile existingFile = getFileFromDirectory(subfolderFiles.get(directoryPath) , fileName);
                if (existingFile != null)
                {
                    deleteFile(existingFile, 0);
                }
                
                // create the file
                WPBFile file = new WPBFile();
                file.setExternalKey(adminStorage.getUniqueId());
                file.setFileName(fileName);
                file.setLastModified(Calendar.getInstance(TimeZone.getTimeZone("GMT")).getTime());
                file.setDirectoryFlag(0);
                
                addFileToDirectory(subfolderFiles.get(directoryPath), file, item.openStream());
                
              }
            } 
            
            returnJson.put(DATA, jsonObjectConverter.JSONFromObject(null));           
               httpServletToolbox.writeBodyResponseAsJson(response, returnJson, null, authenticationResult);
      } catch (Exception e)
      {
          Map<String, String> errors = new HashMap<String, String>();     
          errors.put("", WPBErrors.WB_CANT_UPDATE_RECORD);
          httpServletToolbox.writeBodyResponseAsJson(response, jsonObjectConverter.JSONObjectFromMap(null), errors);          
      }
  }
 
Example 10
Source Project: Mars-Java   Source File: MultipartStream.java    License: MIT License 2 votes vote down vote up
/**
 * <p>Reads <code>body-data</code> from the current
 * <code>encapsulation</code> and writes its contents into the
 * output <code>Stream</code>.
 *
 * <p>Arbitrary large amounts of data can be processed by this
 * method using a constant size buffer. (see {@link
 * #MultipartStream(InputStream,byte[],int,
 *   MultipartStream.ProgressNotifier) constructor}).
 *
 * @param output The <code>Stream</code> to write data into. May
 *               be null, in which case this method is equivalent
 *               to {@link #discardBodyData()}.
 *
 * @return the amount of data written.
 *
 * @throws MalformedStreamException if the stream ends unexpectedly.
 * @throws IOException              if an i/o error occurs.
 */
public int readBodyData(OutputStream output)
        throws MalformedStreamException, IOException {
    return (int) Streams.copy(newInputStream(), output, false); // N.B. Streams.copy closes the input stream
}
 
Example 11
Source Project: Mars-Java   Source File: DiskFileItem.java    License: MIT License 2 votes vote down vote up
/**
 * Returns the original filename in the client's filesystem.
 *
 * @return The original filename in the client's filesystem.
 * @throws org.apache.commons.fileupload.InvalidFileNameException The file name contains a NUL character,
 *   which might be an indicator of a security attack. If you intend to
 *   use the file name anyways, catch the exception and use
 *   {@link org.apache.commons.fileupload.InvalidFileNameException#getName()}.
 */
@Override
public String getName() {
    return Streams.checkFileName(fileName);
}
 
Example 12
Source Project: Mars-Java   Source File: FileUploadBase.java    License: MIT License 2 votes vote down vote up
/**
 * Returns the items file name.
 *
 * @return File name, if known, or null.
 * @throws InvalidFileNameException The file name contains a NUL character,
 *   which might be an indicator of a security attack. If you intend to
 *   use the file name anyways, catch the exception and use
 *   InvalidFileNameException#getName().
 */
public String getName() {
    return Streams.checkFileName(name);
}
 
Example 13
Source Project: onedev   Source File: DiskFileItem.java    License: MIT License 2 votes vote down vote up
/**
 * Returns the original filename in the client's filesystem.
 *
 * @return The original filename in the client's filesystem.
 * @throws org.apache.commons.fileupload.InvalidFileNameException The file name contains a NUL character,
 *   which might be an indicator of a security attack. If you intend to
 *   use the file name anyways, catch the exception and use
 *   {@link org.apache.commons.fileupload.InvalidFileNameException#getName()}.
 */
public String getName() {
    return Streams.checkFileName(fileName);
}
 
Example 14
Source Project: steady   Source File: MultipartStreamDef.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * <p>Reads <code>body-data</code> from the current
 * <code>encapsulation</code> and writes its contents into the
 * output <code>Stream</code>.
 *
 * <p>Arbitrary large amounts of data can be processed by this
 * method using a constant size buffer. (see {@link
 * #MultipartStream(InputStream,byte[],int,
 *   MultipartStream.ProgressNotifier) constructor}).
 *
 * @param output The <code>Stream</code> to write data into. May
 *               be null, in which case this method is equivalent
 *               to {@link #discardBodyData()}.
 *
 * @return the amount of data written.
 *
 * @throws MalformedStreamException if the stream ends unexpectedly.
 * @throws IOException              if an i/o error occurs.
 */
public int readBodyData(OutputStream output)
        throws MalformedStreamException, IOException {
    final InputStream istream = newInputStream();
    return (int) Streams.copy(istream, output, false);
}
 
Example 15
Source Project: steady   Source File: MultipartStreamFix.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * <p>Reads <code>body-data</code> from the current
 * <code>encapsulation</code> and writes its contents into the
 * output <code>Stream</code>.
 *
 * <p>Arbitrary large amounts of data can be processed by this
 * method using a constant size buffer. (see {@link
 * #MultipartStream(InputStream,byte[],int,
 *   MultipartStream.ProgressNotifier) constructor}).
 *
 * @param output The <code>Stream</code> to write data into. May
 *               be null, in which case this method is equivalent
 *               to {@link #discardBodyData()}.
 *
 * @return the amount of data written.
 *
 * @throws MalformedStreamException if the stream ends unexpectedly.
 * @throws IOException              if an i/o error occurs.
 */
public int readBodyData(OutputStream output)
        throws MalformedStreamException, IOException {
    final InputStream istream = newInputStream();
    return (int) Streams.copy(istream, output, false);
}
 
Example 16
Source Project: steady   Source File: FileUploadBase.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Returns the items file name.
 *
 * @return File name, if known, or null.
 * @throws InvalidFileNameException The file name contains a NUL character,
 *   which might be an indicator of a security attack. If you intend to
 *   use the file name anyways, catch the exception and use
 *   InvalidFileNameException#getName().
 */
public String getName() {
    return Streams.checkFileName(name);
}
 
Example 17
Source Project: dcs-sdk-java   Source File: MultipartStreamCopy.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * <p>Reads <code>body-data</code> from the current
 * <code>encapsulation</code> and writes its contents into the
 * output <code>Stream</code>.
 * <p>
 * <p>Arbitrary large amounts of data can be processed by this
 * method using a constant size buffer. (see {@link
 * #MultipartStream(InputStream, byte[], int,
 * MultipartStreamCopy.ProgressNotifier) constructor}).
 *
 * @param output The <code>Stream</code> to write data into. May
 *               be null, in which case this method is equivalent
 *               to {@link #discardBodyData()}.
 * @return the amount of data written.
 * @throws MalformedStreamException if the stream ends unexpectedly.
 * @throws IOException              if an i/o error occurs.
 */
public int readBodyData(OutputStream output)
        throws MalformedStreamException, IOException {
    final InputStream istream = newInputStream();
    return (int) Streams.copy(istream, output, false);
}
 
Example 18
Source Project: lams   Source File: MultipartStream.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * <p>Reads <code>body-data</code> from the current
 * <code>encapsulation</code> and writes its contents into the
 * output <code>Stream</code>.
 *
 * <p>Arbitrary large amounts of data can be processed by this
 * method using a constant size buffer. (see {@link
 * #MultipartStream(InputStream,byte[],int,
 *   MultipartStream.ProgressNotifier) constructor}).
 *
 * @param output The <code>Stream</code> to write data into. May
 *               be null, in which case this method is equivalent
 *               to {@link #discardBodyData()}.
 *
 * @return the amount of data written.
 *
 * @throws MalformedStreamException if the stream ends unexpectedly.
 * @throws IOException              if an i/o error occurs.
 */
public int readBodyData(OutputStream output)
        throws MalformedStreamException, IOException {
    final InputStream istream = newInputStream();
    return (int) Streams.copy(istream, output, false);
}
 
Example 19
Source Project: lams   Source File: DiskFileItem.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the original filename in the client's filesystem.
 *
 * @return The original filename in the client's filesystem.
 * @throws org.apache.commons.fileupload.InvalidFileNameException The file name contains a NUL character,
 *   which might be an indicator of a security attack. If you intend to
 *   use the file name anyways, catch the exception and use
 *   {@link org.apache.commons.fileupload.InvalidFileNameException#getName()}.
 */
public String getName() {
    return Streams.checkFileName(fileName);
}
 
Example 20
Source Project: lams   Source File: FileUploadBase.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the items file name.
 *
 * @return File name, if known, or null.
 * @throws InvalidFileNameException The file name contains a NUL character,
 *   which might be an indicator of a security attack. If you intend to
 *   use the file name anyways, catch the exception and use
 *   InvalidFileNameException#getName().
 */
public String getName() {
    return Streams.checkFileName(name);
}
 
Example 21
Source Project: actframework   Source File: MultipartStream.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * <p>Reads <code>body-data</code> from the current
 * <code>encapsulation</code> and writes its contents into the
 * output <code>Stream</code>.
 *
 * <p>Arbitrary large amounts of data can be processed by this
 * method using a constant size buffer. (see {@link
 * #MultipartStream(InputStream,byte[],int, ProgressNotifier) constructor}).
 *
 * @param output The <code>Stream</code> to write data into. May
 *               be null, in which case this method is equivalent
 *               to {@link #discardBodyData()}.
 *
 * @return the amount of data written.
 *
 * @throws MalformedStreamException if the stream ends unexpectedly.
 * @throws IOException              if an i/o error occurs.
 */
public int readBodyData(OutputStream output)
        throws MalformedStreamException, IOException {
    final InputStream istream = newInputStream();
    return (int) Streams.copy(istream, output, false);
}
 
Example 22
Source Project: restcommander   Source File: MultipartStream.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * <p>Reads <code>body-data</code> from the current
 * <code>encapsulation</code> and writes its contents into the
 * output <code>Stream</code>.
 *
 * <p>Arbitrary large amounts of data can be processed by this
 * method using a constant size buffer. (see {@link
 * #MultipartStream(InputStream,byte[],int, ProgressNotifier) constructor}).
 *
 * @param output The <code>Stream</code> to write data into. May
 *               be null, in which case this method is equivalent
 *               to {@link #discardBodyData()}.
 *
 * @return the amount of data written.
 *
 * @throws MalformedStreamException if the stream ends unexpectedly.
 * @throws IOException              if an i/o error occurs.
 */
public int readBodyData(OutputStream output)
        throws MalformedStreamException, IOException {
    final InputStream istream = newInputStream();
    return (int) Streams.copy(istream, output, false);
}
 
Example 23
Source Project: AndroidWebServ   Source File: MultipartStream.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * <p>Reads <code>body-data</code> from the current
 * <code>encapsulation</code> and writes its contents into the
 * output <code>Stream</code>.
 *
 * <p>Arbitrary large amounts of data can be processed by this
 * method using a constant size buffer. (see {@link
 * #MultipartStream(InputStream,byte[],int,
 *   MultipartStream.ProgressNotifier) constructor}).
 *
 * @param output The <code>Stream</code> to write data into. May
 *               be null, in which case this method is equivalent
 *               to {@link #discardBodyData()}.
 *
 * @return the amount of data written.
 *
 * @throws MalformedStreamException if the stream ends unexpectedly.
 * @throws IOException              if an i/o error occurs.
 */
public int readBodyData(OutputStream output)
        throws MalformedStreamException, IOException {
    final InputStream istream = newInputStream();
    return (int) Streams.copy(istream, output, false);
}
 
Example 24
Source Project: AndroidWebServ   Source File: DiskFileItem.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Returns the original filename in the client's filesystem.
 *
 * @return The original filename in the client's filesystem.
 * @throws org.apache.commons.fileupload.InvalidFileNameException The file name contains a NUL character,
 *   which might be an indicator of a security attack. If you intend to
 *   use the file name anyways, catch the exception and use
 *   {@link org.apache.commons.fileupload.InvalidFileNameException#getName()}.
 */
public String getName() {
    return Streams.checkFileName(fileName);
}
 
Example 25
Source Project: AndroidWebServ   Source File: FileUploadBase.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Returns the items file name.
 *
 * @return File name, if known, or null.
 * @throws InvalidFileNameException The file name contains a NUL character,
 *   which might be an indicator of a security attack. If you intend to
 *   use the file name anyways, catch the exception and use
 *   InvalidFileNameException#getName().
 */
public String getName() {
    return Streams.checkFileName(name);
}