Пример #1
0
 /**
  * Compare the content of two Resources. A nonexistent Resource's content is "less than" that of
  * an existing Resource; a directory-type Resource's content is "less than" that of a file-type
  * Resource.
  *
  * @param r1 the Resource whose content is to be compared.
  * @param r2 the other Resource whose content is to be compared.
  * @param text true if the content is to be treated as text and differences in kind of line break
  *     are to be ignored.
  * @return a negative integer, zero, or a positive integer as the first argument is less than,
  *     equal to, or greater than the second.
  * @throws IOException if the Resources cannot be read.
  * @since Ant 1.7
  */
 public static int compareContent(Resource r1, Resource r2, boolean text) throws IOException {
   if (r1.equals(r2)) {
     return 0;
   }
   boolean e1 = r1.isExists();
   boolean e2 = r2.isExists();
   if (!(e1 || e2)) {
     return 0;
   }
   if (e1 != e2) {
     return e1 ? 1 : -1;
   }
   boolean d1 = r1.isDirectory();
   boolean d2 = r2.isDirectory();
   if (d1 && d2) {
     return 0;
   }
   if (d1 || d2) {
     return d1 ? -1 : 1;
   }
   return text ? textCompare(r1, r2) : binaryCompare(r1, r2);
 }
Пример #2
0
 /**
  * Compares the contents of two Resources.
  *
  * @param r1 the Resource whose content is to be compared.
  * @param r2 the other Resource whose content is to be compared.
  * @param text true if the content is to be treated as text and differences in kind of line break
  *     are to be ignored.
  * @return true if the content of the Resources is the same.
  * @throws IOException if the Resources cannot be read.
  * @since Ant 1.7
  */
 public static boolean contentEquals(Resource r1, Resource r2, boolean text) throws IOException {
   if (r1.isExists() != r2.isExists()) {
     return false;
   }
   if (!r1.isExists()) {
     // two not existing files are equal
     return true;
   }
   // should the following two be switched?  If r1 and r2 refer to the same file,
   // isn't their content equal regardless of whether that file is a directory?
   if (r1.isDirectory() || r2.isDirectory()) {
     // don't want to compare directory contents for now
     return false;
   }
   if (r1.equals(r2)) {
     return true;
   }
   if (!text && r1.getSize() != r2.getSize()) {
     return false;
   }
   return compareContent(r1, r2, text) == 0;
 }