title: Downloaded File Size 0
body: <p>I'm trying here to add a specific dialog bean for action on Alfresco Explorer that supposed to download a specific docx file. The code is working fine when I hit the download action, it downloads the file but as mentioned in my question title, the file size is 0 bytes.</p>
  
  <p>I'm using this to do that:</p>
  
  <pre><code>public class NewFormDialog extends BaseDialogBean {
  
  protected String aspect;
  
  protected String finishImpl(FacesContext context, String outcome)
          throws Exception {
  
      download(aspect);
  
      // // get the space the action will apply to
      // NodeRef nodeRef = this.browseBean.getActionSpace().getNodeRef();
      //
      // // resolve the fully qualified aspect name
      // QName aspectToAdd = Repository.resolveToQName(this.aspect);
      //
      // // add the aspect to the space
      // getNodeService().addAspect(nodeRef, aspectToAdd, null);
      //
      // // return the default outcome
      return outcome;
  }
  
  public boolean getFinishButtonDisabled() {
      return false;
  }
  
  public String getFinishButtonLabel() {
      return "Download";
  }
  
  public void download(String pAspect) throws ServletException, IOException {
  
      String filename = pAspect;
      String filepath = "\\";
      BufferedInputStream buf = null;
      ServletOutputStream myOut = null;
  
      try {
          FacesContext fc = FacesContext.getCurrentInstance();
          HttpServletResponse response = (HttpServletResponse) fc
                  .getExternalContext().getResponse();
  
          myOut = response.getOutputStream();
          File myfile = new File(filepath + filename);
  
          // set response headers
          response.setContentType("application/octet-stream");
  
          response.addHeader("Content-Disposition", "attachment; filename="
                  + filename);
  
          response.setContentLength((int) myfile.length());
  
          FileInputStream input = new FileInputStream(myfile);
          buf = new BufferedInputStream(input);
          int readBytes = 0;
  
          // read from the file; write to the ServletOutputStream
          while ((readBytes = buf.read()) != -1)
              myOut.write(readBytes);
          myOut.flush();
          response.flushBuffer();
  
      } catch (IOException ioe) {
  
          throw new ServletException(ioe.getMessage());
  
      } finally {
          // close the input/output streams
          if (myOut != null)
              myOut.close();
          if (buf != null)
              buf.close();
          FacesContext.getCurrentInstance().responseComplete();
      }
  }
  
  public String getAspect() {
      return aspect;
  }
  
  public void setAspect(String aspect) {
      this.aspect = aspect;
  }
  }
  </code></pre>
  
  <p>I tried every solution that I found by none works.</p>
  
  <p>Thank you in advance.</p>