title: Java : InputStream to Multi-part file conversion, result file is empty
body: <p>I am working on a Java application in which I am trying to create a Multipart file out of downloaded InputStream. Unfortunately, it is not working and the Multipart file is empty. I checked the size of savedFile on disk before copying it to Multipart, and it has correct size, attributes, content. </p>
  
  <p>What am I doing wrong in the conversion, there is no stacktrace, as I am catching it. </p>
  
  <p>Code :</p>
  
  <pre><code>// InputStream contains file data.
  byte[] bytes = IOUtils.toByteArray(inputStream);
  
  File file = new File(msg + "temp");
  if (file.exists() &amp;&amp; file.isDirectory()) {
    OutputStream outputStream = new FileOutputStream(new File(msg + "temp" + "/" +
      groupAttachments.getFileName()));
    outputStream.write(bytes);
    outputStream.close();
  }
  java.io.File savedFile = new java.io.File(msg + "temp" + "/" + 
    groupAttachments.getFileName());
  DiskFileItem fileItem = new DiskFileItem("file", "text/plain", false,
                                              savedFile.getName(), (int) savedFile.length(), savedFile.getParentFile());
  fileItem.getOutputStream();
  MultipartFile multipartFile = new CommonsMultipartFile(fileItem);
  
  System.out.println("Saved file size is "+savedFile.length());
  if (multipartFile.isEmpty()) {
    System.out.println("Dropbox uploaded multipart file is empty");
  } else {
    System.out.println("Multipart file is not empty.");
  }
  this.dropboxTask.insertFile(multipartFile, "",
    savedPersonalNoteObject.getNoteid(), (long) 0, true);
  Path path = Paths.get(msg + "temp" + "/" + groupAttachments.getFileName());
  </code></pre>
  
  <p>Console output :</p>
  
  <pre><code>Multipart file is not empty
  Bytes are not null
  File path is /My Group
  Input stream is not null
  Saved file size is 4765
  Dropbox uploaded multipart file is empty
  Multipart file is empty
  Bytes are not null
  </code></pre>
  
  <p>What am I doing wrong in the conversion? Any help would be nice. Thanks a lot. </p>