Exemple #1
0
 @Override
 public void setContent(InputStream inputStream) throws IOException {
   if (fileUpload instanceof MemoryFileUpload) {
     // change to Disk
     fileUpload =
         new DiskFileUpload(
             fileUpload.getName(),
             fileUpload.getFilename(),
             fileUpload.getContentType(),
             fileUpload.getContentTransferEncoding(),
             fileUpload.getCharset(),
             definedSize);
   }
   fileUpload.setContent(inputStream);
 }
Exemple #2
0
 @Override
 public void setContent(ChannelBuffer buffer) throws IOException {
   if (buffer.readableBytes() > limitSize) {
     if (fileUpload instanceof MemoryFileUpload) {
       // change to Disk
       fileUpload =
           new DiskFileUpload(
               fileUpload.getName(),
               fileUpload.getFilename(),
               fileUpload.getContentType(),
               fileUpload.getContentTransferEncoding(),
               fileUpload.getCharset(),
               definedSize);
     }
   }
   fileUpload.setContent(buffer);
 }
Exemple #3
0
 @Override
 public void setContent(File file) throws IOException {
   if (file.length() > limitSize) {
     if (fileUpload instanceof MemoryFileUpload) {
       // change to Disk
       fileUpload =
           new DiskFileUpload(
               fileUpload.getName(),
               fileUpload.getFilename(),
               fileUpload.getContentType(),
               fileUpload.getContentTransferEncoding(),
               fileUpload.getCharset(),
               definedSize);
     }
   }
   fileUpload.setContent(file);
 }
 /**
  * Add a file as a FileUpload
  *
  * @param name the name of the parameter
  * @param file the file to be uploaded (if not Multipart mode, only the filename will be included)
  * @param contentType the associated contentType for the File
  * @param isText True if this file should be transmitted in Text format (else binary)
  * @throws NullPointerException for name and file
  * @throws ErrorDataEncoderException if the encoding is in error or if the finalize were already
  *     done
  */
 public void addBodyFileUpload(String name, File file, String contentType, boolean isText)
     throws ErrorDataEncoderException {
   if (name == null) {
     throw new NullPointerException("name");
   }
   if (file == null) {
     throw new NullPointerException("file");
   }
   String scontentType = contentType;
   String contentTransferEncoding = null;
   if (contentType == null) {
     if (isText) {
       scontentType = HttpPostBodyUtil.DEFAULT_TEXT_CONTENT_TYPE;
     } else {
       scontentType = HttpPostBodyUtil.DEFAULT_BINARY_CONTENT_TYPE;
     }
   }
   if (!isText) {
     contentTransferEncoding = HttpPostBodyUtil.TransferEncodingMechanism.BINARY.value;
   }
   FileUpload fileUpload =
       factory.createFileUpload(
           request,
           name,
           file.getName(),
           scontentType,
           contentTransferEncoding,
           null,
           file.length());
   try {
     fileUpload.setContent(file);
   } catch (IOException e) {
     throw new ErrorDataEncoderException(e);
   }
   addBodyHttpData(fileUpload);
 }