code: public static void downloadDataToSink( CResponse response, ByteSink byteSink )
      {
          InputStream is = null;
          ByteSinkStream bss = null;
          boolean success = false;
          try {
  
              long contentLength = response.getContentLength();
              if ( contentLength >= 0 ) {
                  // content length is known: inform any listener
                  byteSink.setExpectedLength( contentLength );
              }
  
              long current = 0;
              is = response.openStream();
              bss = byteSink.openStream();
  
              byte[] buffer = new byte[ 8 * 1024 ];
              int len;
              while ( ( len = is.read( buffer ) ) != -1 ) {
                  current += len;
                  bss.write( buffer, 0, len );
              }
  
              if ( contentLength < 0 ) {
                  // content length was unknown; inform listener operation is terminated
                  byteSink.setExpectedLength( current );
              }
  
              bss.flush();
              bss.close();
              bss = null;
  
              success = true;
  
          } catch ( IOException ex ) {
              throw new CStorageException( ex.getMessage(), ex );
          } finally {
              if ( bss != null && !success ) {
                  bss.abort();
              }
  
              PcsUtils.closeQuietly( is );
              PcsUtils.closeQuietly( bss );
          }
      }
docs: Server has answered OK with a file to download as stream.
  
  Open byte sink stream, and copy data from server stream to sink stream
  
  @param response server response to read from
  @param byteSink destination