public static int patchFast(File oldFile,File newFile,File diffFile,int extLen) throws IOException {
  if (oldFile == null || oldFile.length() <= 0) {
    return RETURN_OLD_FILE_ERR;
  }
  if (newFile == null) {
    return RETURN_NEW_FILE_ERR;
  }
  if (diffFile == null || diffFile.length() <= 0) {
    return RETURN_DIFF_FILE_ERR;
  }
  InputStream oldInputStream=new BufferedInputStream(new FileInputStream(oldFile));
  byte[] diffBytes=new byte[(int)diffFile.length()];
  InputStream diffInputStream=new FileInputStream(diffFile);
  try {
    BSUtil.readFromStream(diffInputStream,diffBytes,0,diffBytes.length);
  }
  finally {
    diffInputStream.close();
  }
  byte[] newBytes=patchFast(oldInputStream,(int)oldFile.length(),diffBytes,extLen);
  OutputStream newOutputStream=new FileOutputStream(newFile);
  try {
    newOutputStream.write(newBytes);
  }
  finally {
    newOutputStream.close();
  }
  return RETURN_SUCCESS;
}

public static int patchFast ( File oldFile , File newFile , File diffFile , int extLen ) throws IOException { if ( oldFile == null || oldFile . length ( ) <= 0 ) { return RETURN_OLD_FILE_ERR ; } if ( newFile == null ) { return RETURN_NEW_FILE_ERR ; } if ( diffFile == null || diffFile . length ( ) <= 0 ) { return RETURN_DIFF_FILE_ERR ; } InputStream oldInputStream = new BufferedInputStream ( new FileInputStream ( oldFile ) ) ; byte [ ] diffBytes = new byte [ ( int ) diffFile . length ( ) ] ; InputStream diffInputStream = new FileInputStream ( diffFile ) ; try { BSUtil . readFromStream ( diffInputStream , diffBytes , 0 , diffBytes . length ) ; } finally { diffInputStream . close ( ) ; } byte [ ] newBytes = patchFast ( oldInputStream , ( int ) oldFile . length ( ) , diffBytes , extLen ) ; OutputStream newOutputStream = new FileOutputStream ( newFile ) ; try { newOutputStream . write ( newBytes ) ; } finally { newOutputStream . close ( ) ; } return RETURN_SUCCESS ; }
this patch method is fast , but using more memory . memory size = oldbuf + diffbuf + newbuf
