public static int copy(InputStream in,OutputStream out) throws IOException {
  Assert.notNull(in,"No InputStream specified");
  Assert.notNull(out,"No OutputStream specified");
  int byteCount=0;
  byte[] buffer=new byte[BUFFER_SIZE];
  int bytesRead=-1;
  while ((bytesRead=in.read(buffer)) != -1) {
    out.write(buffer,0,bytesRead);
    byteCount+=bytesRead;
  }
  out.flush();
  return byteCount;
}

public static int copy ( InputStream in , OutputStream out ) throws IOException { Assert . notNull ( in , "No InputStream specified" ) ; Assert . notNull ( out , "No OutputStream specified" ) ; int byteCount = 0 ; byte [ ] buffer = new byte [ BUFFER_SIZE ] ; int bytesRead = - 1 ; while ( ( bytesRead = in . read ( buffer ) ) != - 1 ) { out . write ( buffer , 0 , bytesRead ) ; byteCount += bytesRead ; } out . flush ( ) ; return byteCount ; }
copy the contents of the given inputstream to the given outputstream . leaves both streams open when done .
