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

ConcatFileInputStream

public class ConcatFileInputStream extends InputStream
Special InputStream that will concatenate the contents of an array of files.

Fields Summary
private static final int
EOF
private int
currentIndex
private boolean
eof
private File[]
file
private InputStream
currentStream
private org.apache.tools.ant.ProjectComponent
managingPc
Constructors Summary
public ConcatFileInputStream(File[] file)
Construct a new ConcatFileInputStream with the specified File[].

param
file File[].
throws
IOException if I/O errors occur.


                        
         
        this.file = file;
    
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 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 {
            if (loglevel > Project.MSG_WARN) {
                System.out.println(message);
            } else {
                System.err.println(message);
            }
        }
    
private voidopenFile(int index)

        closeCurrent();
        if (file != null && index < file.length) {
            log("Opening " + file[index], Project.MSG_VERBOSE);
            try {
                currentStream = new BufferedInputStream(
                    new FileInputStream(file[index]));
            } catch (IOException eyeOhEx) {
                log("Failed to open " + file[index], Project.MSG_ERR);
                throw eyeOhEx;
            }
        } else {
            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.

        int result = readCurrent();
        if (result == EOF && !eof) {
            openFile(++currentIndex);
            result = readCurrent();
        }
        return result;
    
private intreadCurrent()

        return (eof || currentStream == null) ? EOF : currentStream.read();
    
public voidsetManagingComponent(org.apache.tools.ant.ProjectComponent pc)
Set a managing Task for this ConcatFileInputStream.

param
pc the managing Task.

        this.managingPc = pc;
    
public voidsetManagingTask(org.apache.tools.ant.Task task)
Set a managing Task for this ConcatFileInputStream.

param
task the managing Task.

        setManagingComponent(task);