/*
 * @author Ranides Atterwim <ranides@gmail.com>
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */
package net.ranides.assira.io;

import java.io.IOException;
import net.ranides.assira.trace.*;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

/**
 *
 * @author ranides
 */
public class IOExceptions extends IOException implements Iterable<IOException> {

    private final List<IOException> causeList;
    
    public IOExceptions(Collection<? extends IOException> causeList) {
        super();
        this.causeList = new LinkedList<>(causeList);
    }

    public <T extends Throwable> IOExceptions(String message, Collection<? extends IOException> causeList) {
        super(message);
        this.causeList = new LinkedList<>(causeList);
    }

    public IOExceptions(String message) {
        super(message);
        this.causeList = new LinkedList<>();
    }
    
    @Override
    public Iterator<IOException> iterator() {
		return causeList.iterator();
    }
    
    public List<IOException> getCauseList() {
        return causeList;
    }
    
    public void addCause(IOException cause) {
        causeList.add(cause);
    }

    @Override
    public void printStackTrace(PrintStream stream) {
        super.printStackTrace(stream);
		ExceptionInspector.print(stream, causeList);
    }

    @Override
    public void printStackTrace(PrintWriter writer) {
        super.printStackTrace(writer);
		ExceptionInspector.print(writer, causeList);
    }
    
}
