Search in sources :

Example 6 with ChainReaderHelper

use of org.apache.tools.ant.filters.util.ChainReaderHelper in project ant by apache.

the class FilterMapper method mapFileName.

/**
 * Return the result of the filters on the sourcefilename.
 * @param sourceFileName the filename to map
 * @return  a one-element array of converted filenames, or null if
 *          the filterchain returns an empty string.
 */
@Override
public String[] mapFileName(String sourceFileName) {
    if (sourceFileName == null) {
        return null;
    }
    try {
        Reader stringReader = new StringReader(sourceFileName);
        ChainReaderHelper helper = new ChainReaderHelper();
        helper.setBufferSize(BUFFER_SIZE);
        helper.setPrimaryReader(stringReader);
        helper.setProject(getProject());
        Vector<FilterChain> filterChains = new Vector<>();
        filterChains.add(this);
        helper.setFilterChains(filterChains);
        String result = FileUtils.safeReadFully(helper.getAssembledReader());
        if (result.isEmpty()) {
            return null;
        }
        return new String[] { result };
    } catch (BuildException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new BuildException(ex);
    }
}
Also used : FilterChain(org.apache.tools.ant.types.FilterChain) StringReader(java.io.StringReader) StringReader(java.io.StringReader) Reader(java.io.Reader) ChainReaderHelper(org.apache.tools.ant.filters.util.ChainReaderHelper) BuildException(org.apache.tools.ant.BuildException) Vector(java.util.Vector) UnsupportedAttributeException(org.apache.tools.ant.UnsupportedAttributeException) BuildException(org.apache.tools.ant.BuildException)

Example 7 with ChainReaderHelper

use of org.apache.tools.ant.filters.util.ChainReaderHelper in project ant by apache.

the class ResourceList method open.

private Reader open(Resource r) throws IOException {
    ChainReaderHelper crh = new ChainReaderHelper();
    crh.setPrimaryReader(new InputStreamReader(new BufferedInputStream(r.getInputStream()), encoding == null ? Charset.defaultCharset() : Charset.forName(encoding)));
    crh.setFilterChains(filterChains);
    crh.setProject(getProject());
    return crh.getAssembledReader();
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedInputStream(java.io.BufferedInputStream) ChainReaderHelper(org.apache.tools.ant.filters.util.ChainReaderHelper)

Aggregations

ChainReaderHelper (org.apache.tools.ant.filters.util.ChainReaderHelper)7 InputStreamReader (java.io.InputStreamReader)5 BuildException (org.apache.tools.ant.BuildException)4 BufferedInputStream (java.io.BufferedInputStream)3 IOException (java.io.IOException)3 Reader (java.io.Reader)3 BufferedReader (java.io.BufferedReader)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 StringReader (java.io.StringReader)2 Charset (java.nio.charset.Charset)2 Vector (java.util.Vector)2 ChainReader (org.apache.tools.ant.filters.util.ChainReaderHelper.ChainReader)2 FilterChain (org.apache.tools.ant.types.FilterChain)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 PipedOutputStream (java.io.PipedOutputStream)1 List (java.util.List)1 Properties (java.util.Properties)1 Project (org.apache.tools.ant.Project)1