コード例 #1
0
ファイル: AppLoaderBase.java プロジェクト: hoenninger/openxma
  /**
   * creates the has value for the application. This is done by concatenating the content of the two
   * given input streams and calculating the MD5-hash over this combined content.
   *
   * @param isApp first description file (xma-app.xml)
   * @param isPi second description file (plugin.xml)
   * @return the calculated hash value
   * @throws IOException in case of errors reading the streams
   */
  protected byte[] createApplicationHash(InputStream isApp, InputStream isPi) throws IOException {
    MessageDigest md;
    try {
      md = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
      log_.log(LogLevel.SEVERE, "error preventing hash calculations: ", e);
      throw new RuntimeException(e);
    }
    int b = -1;
    ByteArrayOutputStream os = new ByteArrayOutputStream();

    while ((b = isApp.read()) != -1) {
      os.write(b);
    }

    while ((b = isPi.read()) != -1) {
      os.write(b);
    }

    md.update(os.toByteArray());
    byte[] digest = md.digest();

    return digest;
  }