title: Can a web service return a stream?
body: <p>I've been writing a little application that will let people upload &amp; download files to me.  I've added a web service to this applciation to provide the upload/download functionality that way but I'm not too sure on how well my implementation is going to cope with large files.</p>
  
  <p>At the moment the definitions of the upload &amp; download methods look like this (written using Apache CXF):</p>
  
  <pre><code>boolean uploadFile(@WebParam(name = "username") String username,
      @WebParam(name = "password") String password,
      @WebParam(name = "filename") String filename,
      @WebParam(name = "fileContents") byte[] fileContents)
      throws UploadException, LoginException;
  
  byte[] downloadFile(@WebParam(name = "username") String username,
      @WebParam(name = "password") String password,
      @WebParam(name = "filename") String filename) throws DownloadException,
      LoginException;
  </code></pre>
  
  <p>So the file gets uploaded and downloaded as a byte array.  But if I have a file of some stupid size (e.g. 1GB) surely this will try and put all that information into memory and crash my service.</p>
  
  <p>So my question is - is it possible to return some kind of stream instead?  I would imagine this isn't going to be terribly OS independent though.  Although I know the theory behind web services, the practical side is something that I still need to pick up a bit of information on.</p>
  
  <p>Cheers for any input,
  Lee</p>