KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > types > resources > comparators > Content


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */

18 package org.apache.tools.ant.types.resources.comparators;
19
20 import java.io.IOException JavaDoc;
21
22 import org.apache.tools.ant.BuildException;
23 import org.apache.tools.ant.types.Resource;
24 import org.apache.tools.ant.util.ResourceUtils;
25
26 /**
27  * Compares Resources by content.
28  * @since Ant 1.7
29  */

30 public class Content extends ResourceComparator {
31
32     private boolean binary = true;
33
34     /**
35      * Set binary mode for this Content ResourceComparator. If this
36      * attribute is set to false, Resource content will be compared
37      * ignoring platform line-ending conventions.
38      * Default is <code>true</code>.
39      * @param b whether to compare content in binary mode.
40      */

41     public void setBinary(boolean b) {
42         binary = b;
43     }
44
45     /**
46      * Learn whether this Content ResourceComparator is operating in binary mode.
47      * @return boolean binary flag.
48      */

49     public boolean isBinary() {
50         return binary;
51     }
52
53     /**
54      * Compare two Resources by content.
55      * @param foo the first Resource.
56      * @param bar the second Resource.
57      * @return a negative integer, zero, or a positive integer as the first
58      * argument is less than, equal to, or greater than the second.
59      * @throws BuildException if I/O errors occur.
60      * @see org.apache.tools.ant.util.ResourceUtils#compareContent(Resource, Resource, boolean).
61      */

62     protected int resourceCompare(Resource foo, Resource bar) {
63         try {
64             return ResourceUtils.compareContent(foo, bar, !binary);
65         } catch (IOException JavaDoc e) {
66             throw new BuildException(e);
67         }
68     }
69
70 }
71
Popular Tags