code: private void copy( final InputStream is, final OutputStream os ) throws IOException
     {
        final byte[] buffer = new byte[ 512 ];
        int countOfBytes = -1;
  
        while ( !this.terminated )
        {
           while ( is.available() <= 0 )
           {
              synchronized( this )
              {
                 try
                 {
                    this.wait( 50 ); // guard
                    if ( this.terminated ) return;
                 }
                 catch ( InterruptedException ie )
                 {
                    log.error(ie);
                 }
              }
           }
  
           countOfBytes = is.read( buffer, 0, buffer.length );
           os.write( buffer, 0, countOfBytes );
        }
     }
docs: Copies all data from <b>is</b> to <b>os</b> until job is killed
  @param is input stream to read data from
  @param os output stream to write data to
  @throws IOException if I/O error occurs