Esempio n. 1
0
  /**
   * Create a revision as a child of another revision.
   *
   * @param parent Parent revision, or null if this is the root revision.
   */
  public Revision(GVCLib gvclib, Revision parent, Map<String, Set<File>> fileSet, String comment)
      throws GVCException {
    this.parent = parent;
    this.date = new Date();
    this.comment = comment;

    if (parent == null) {
      // This is the initial revision.
      this.filesAdded = fileSet;
    } else {
      // Diff the given file set with parent's file set to get added and removed.
      List<Map<String, Set<File>>> diffList = filesetGetDiff(parent.getFileset(gvclib), fileSet);
      this.filesAdded = diffList.get(0);
      this.filesRemoved = diffList.get(1);
    }

    if (this.filesAdded == null && this.filesRemoved == null) {
      throw new GVCException("Will not create a revision with no changes.");
    }

    this.serialize();

    // Generate hash.
    MD5 md5 = new MD5();
    try {
      md5.Update(this.serialized, null);
    } catch (UnsupportedEncodingException e) {
      throw new GVCException(e);
    }
    this.hash = md5.asHex();
  }
Esempio n. 2
0
  /**
   * Returns array of bytes (16 bytes) representing hash as of the current state of this object.
   * Note: getting a hash does not invalidate the hash object, it only creates a copy of the real
   * state which is finalized.
   *
   * @return Array of 16 bytes, the hash of all updated bytes
   */
  public synchronized byte[] Final() {
    byte bits[];
    int index, padlen;
    MD5State fin;

    if (finals == null) {
      fin = new MD5State(state);

      int[] count_ints = {(int) (fin.count << 3), (int) (fin.count >> 29)};
      bits = Encode(count_ints, 8);

      index = (int) (fin.count & 0x3f);
      padlen = (index < 56) ? (56 - index) : (120 - index);

      Update(fin, padding, 0, padlen);
      Update(fin, bits, 0, 8);

      /* Update() sets finals to null */
      finals = fin;
    }

    return Encode(finals.state, 16);
  }
Esempio n. 3
0
 /**
  * Update buffer with given string using the given encoding. If the given encoding is null, the
  * encoding "ISO8859_1" is used.
  *
  * @param s String to be update to hash (is used as s.getBytes(charset_name))
  * @param charset_name The character set to use to convert s to a byte array, or null if the
  *     "ISO8859_1" character set is desired.
  * @exception java.io.UnsupportedEncodingException If the named charset is not supported.
  */
 public void Update(String s, String charset_name) throws UnsupportedEncodingException {
   if (charset_name == null) charset_name = "ISO8859_1";
   byte chars[] = s.getBytes(charset_name);
   Update(chars, chars.length);
 }
Esempio n. 4
0
 /**
  * Update buffer with a single integer (only & 0xff part is used, as a byte)
  *
  * @param i Integer value, which is then converted to byte as i & 0xff
  */
 public void Update(int i) {
   Update((byte) (i & 0xff));
 }
Esempio n. 5
0
 /**
  * Update buffer with given string. Note that because the version of the s.getBytes() method
  * without parameters is used to convert the string to a byte array, the results of this method
  * may be different on different platforms. The s.getBytes() method converts the string into a
  * byte array using the current platform's default character set and may therefore have different
  * results on platforms with different default character sets. If a version that works
  * consistently across platforms with different default character sets is desired, use the
  * overloaded version of the Update() method which takes a string and a character encoding.
  *
  * @param s String to be update to hash (is used as s.getBytes())
  */
 public void Update(String s) {
   byte chars[] = s.getBytes();
   Update(chars, chars.length);
 }
Esempio n. 6
0
  /**
   * Updates hash with a single byte
   *
   * @param b Single byte to update the hash
   */
  public void Update(byte b) {
    byte buffer[] = new byte[1];
    buffer[0] = b;

    Update(buffer, 1);
  }
Esempio n. 7
0
 /**
  * Updates hash with given array of bytes
  *
  * @param buffer Array of bytes to use for updating the hash
  */
 public void Update(byte buffer[]) {
   Update(buffer, 0, buffer.length);
 }
Esempio n. 8
0
 public void Update(byte buffer[], int length) {
   Update(this.state, buffer, 0, length);
 }
Esempio n. 9
0
 /**
  * Initialize class, and update hash with ob.toString()
  *
  * @param ob Object, ob.toString() is used to update hash after initialization
  */
 public MD5(Context context, Object ob) {
   this(context);
   Update(ob.toString());
 }