Search in sources :

Example 1 with ConcatResourceInputStream

use of org.apache.tools.ant.util.ConcatResourceInputStream in project ant by apache.

the class Tokens method getCollection.

/**
 * Sort the contained elements.
 * @return a Collection of Resources.
 */
protected synchronized Collection<Resource> getCollection() {
    ResourceCollection rc = getResourceCollection();
    if (rc.isEmpty()) {
        return Collections.emptySet();
    }
    if (tokenizer == null) {
        tokenizer = new LineTokenizer();
    }
    try (ConcatResourceInputStream cat = new ConcatResourceInputStream(rc);
        InputStreamReader rdr = new InputStreamReader(cat, encoding == null ? Charset.defaultCharset() : Charset.forName(encoding))) {
        cat.setManagingComponent(this);
        List<Resource> result = new ArrayList<>();
        for (String s = tokenizer.getToken(rdr); s != null; s = tokenizer.getToken(rdr)) {
            // do not send the Project to the constructor of StringResource, since
            // the semantics of that constructor clearly state that property value
            // replacement takes place on the passed string value. We don't want
            // that to happen.
            final StringResource resource = new StringResource(s);
            resource.setProject(getProject());
            result.add(resource);
        }
        return result;
    } catch (IOException e) {
        throw new BuildException("Error reading tokens", e);
    }
}
Also used : ConcatResourceInputStream(org.apache.tools.ant.util.ConcatResourceInputStream) InputStreamReader(java.io.InputStreamReader) LineTokenizer(org.apache.tools.ant.util.LineTokenizer) Resource(org.apache.tools.ant.types.Resource) ArrayList(java.util.ArrayList) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) ResourceCollection(org.apache.tools.ant.types.ResourceCollection)

Aggregations

IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 BuildException (org.apache.tools.ant.BuildException)1 Resource (org.apache.tools.ant.types.Resource)1 ResourceCollection (org.apache.tools.ant.types.ResourceCollection)1 ConcatResourceInputStream (org.apache.tools.ant.util.ConcatResourceInputStream)1 LineTokenizer (org.apache.tools.ant.util.LineTokenizer)1