FileDocCategorySizeDatePackage
ConcatResourceInputStream.javaAPI DocApache Ant 1.704514Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.util

ConcatResourceInputStream

public class ConcatResourceInputStream extends InputStream
Special InputStream that will concatenate the contents of Resources from a single ResourceCollection.
since
Ant 1.7

Fields Summary
private static final int
EOF
private boolean
eof
private Iterator
iter
private InputStream
currentStream
private org.apache.tools.ant.ProjectComponent
managingPc
private boolean
ignoreErrors
Constructors Summary
public ConcatResourceInputStream(org.apache.tools.ant.types.ResourceCollection rc)
Construct a new ConcatResourceInputStream for the specified ResourceCollection.

param
rc the ResourceCollection to combine.


                   
       
        iter = rc.iterator();
    
Methods Summary
public voidclose()
Close the stream.

throws
IOException if there is an error.

        closeCurrent();
        eof = true;
    
private voidcloseCurrent()

        FileUtils.close(currentStream);
        currentStream = null;
    
public booleanisIgnoreErrors()
Find out whether this ConcatResourceInputStream ignores errors.

return
boolean ignore-errors flag.

        return ignoreErrors;
    
public voidlog(java.lang.String message, int loglevel)
Log a message with the specified logging level.

param
message the String message.
param
loglevel the int logging level.

        if (managingPc != null) {
            managingPc.log(message, loglevel);
        } else {
            (loglevel > Project.MSG_WARN ? System.out : System.err).println(message);
        }
    
private voidnextResource()

        closeCurrent();
        while (iter.hasNext()) {
            Resource r = (Resource) iter.next();
            if (!r.isExists()) {
                continue;
            }
            log("Concating " + r.toLongString(), Project.MSG_VERBOSE);
            try {
                currentStream = new BufferedInputStream(r.getInputStream());
                return;
            } catch (IOException eyeOhEx) {
                if (!ignoreErrors) {
                    log("Failed to get input stream for " + r, Project.MSG_ERR);
                    throw eyeOhEx;
                }
            }
        }
        eof = true;
    
public intread()
Read a byte.

return
the byte (0 - 255) or -1 if this is the end of the stream.
throws
IOException if there is an error.

        if (eof) {
            return EOF;
        }
        int result = readCurrent();
        if (result == EOF) {
            nextResource();
            result = readCurrent();
        }
        return result;
    
private intreadCurrent()

        return eof || currentStream == null ? EOF : currentStream.read();
    
public voidsetIgnoreErrors(boolean b)
Set whether this ConcatResourceInputStream ignores errors.

param
b whether to ignore errors.

        ignoreErrors = b;
    
public voidsetManagingComponent(org.apache.tools.ant.ProjectComponent pc)
Set a managing ProjectComponent for this ConcatResourceInputStream.

param
pc the managing ProjectComponent.

        this.managingPc = pc;