class ConcatClosingInputStream extends InputStream {

    @Override
    public int read() throws IOException {
        if (closed)
            return -1;

        if (current == null) {
            return safeCloseAndThrow(new IOException("cannot read from null Stream"));
        }

        int read;
        try {
            read = current.read();
        } catch (IOException e) {
            return safeCloseAndThrow(e);
        }

        if (read >= 0)
            return read;

        else {
            try {
                current.close();
            } catch (IOException e) {
                return safeCloseAndThrow(e);
            }
            if (streams.hasNext()) {
                current = streams.next();
                return read();
            } else {
                closed = true;
                return -1;
            }
        }
    }

    public  ConcatClosingInputStream(Iterator<InputStream> streams);

}