Methods Summary |
---|
public void | addConfigured(org.apache.tools.ant.types.ResourceCollection a)Set the source resource.
if (a.size() != 1) {
throw new BuildException("only single argument resource collections"
+ " are supported");
}
src = (Resource) a.iterator().next();
|
public final void | addFilterChain(org.apache.tools.ant.types.FilterChain filter)Add the FilterChain element.
filterChains.addElement(filter);
|
public final void | execute()read in a source file to a property
//validation
if (src == null) {
throw new BuildException("source resource not defined");
}
if (property == null) {
throw new BuildException("output property not defined");
}
if (quiet && failOnError) {
throw new BuildException("quiet and failonerror cannot both be "
+ "set to true");
}
if (!src.isExists()) {
String message = src + " doesn't exist";
if (failOnError) {
throw new BuildException(message);
} else {
log(message, quiet ? Project.MSG_WARN : Project.MSG_ERR);
return;
}
}
InputStream is = null;
BufferedInputStream bis = null;
Reader instream = null;
log("loading " + src + " into property " + property,
Project.MSG_VERBOSE);
try {
final long len = src.getSize();
log("resource size = "
+ (len != Resource.UNKNOWN_SIZE ? String.valueOf(len)
: "unknown"), Project.MSG_DEBUG);
//discard most of really big resources
final int size = (int) len;
//open up the resource
is = src.getInputStream();
bis = new BufferedInputStream(is);
if (encoding == null) {
instream = new InputStreamReader(bis);
} else {
instream = new InputStreamReader(bis, encoding);
}
String text = "";
if (size != 0) {
ChainReaderHelper crh = new ChainReaderHelper();
if (len != Resource.UNKNOWN_SIZE) {
crh.setBufferSize(size);
}
crh.setPrimaryReader(instream);
crh.setFilterChains(filterChains);
crh.setProject(getProject());
instream = crh.getAssembledReader();
text = crh.readFully(instream);
}
if (text != null) {
if (text.length() > 0) {
getProject().setNewProperty(property, text);
log("loaded " + text.length() + " characters",
Project.MSG_VERBOSE);
log(property + " := " + text, Project.MSG_DEBUG);
}
}
} catch (final IOException ioe) {
final String message = "Unable to load resource: "
+ ioe.toString();
if (failOnError) {
throw new BuildException(message, ioe, getLocation());
} else {
log(message, quiet ? Project.MSG_VERBOSE : Project.MSG_ERR);
}
} catch (final BuildException be) {
if (failOnError) {
throw be;
} else {
log(be.getMessage(),
quiet ? Project.MSG_VERBOSE : Project.MSG_ERR);
}
} finally {
FileUtils.close(is);
}
|
public final void | setEncoding(java.lang.String encoding)Encoding to use for input, defaults to the platform's default
encoding.
For a list of possible values see
http://java.sun.com/j2se/1.5.0/docs/guide/intl/encoding.doc.html
.
this.encoding = encoding;
|
public final void | setFailonerror(boolean fail)If true, fail on load error.
failOnError = fail;
|
public final void | setProperty(java.lang.String property)Property name to save to.
this.property = property;
|
public void | setQuiet(boolean quiet)If true, suppress the load error report and set the
the failonerror value to false.
this.quiet = quiet;
if (quiet) {
this.failOnError = false;
}
|