All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.unlaxer.util.copy.MultipleIOException Maven / Gradle / Ivy

package org.unlaxer.util.copy;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;

public class MultipleIOException extends IOException{

	private static final long serialVersionUID = -5674203269195564149L;
	
	public final List causes;

	public MultipleIOException(List causes) {
		super();
		this.causes = causes;
	}
	
	public MultipleIOException(String message , List causes) {
		super(message);
		this.causes = causes;
	}
	
	public MultipleIOException() {
		super();
		this.causes = new ArrayList<>();
	}
	
	public MultipleIOException(String message) {
		super(message);
		this.causes = new ArrayList<>();
	}
	
	public static  Optional process(
			Collection collection,
			Consumer collectionConsumer) {

		List exceptions = new ArrayList();
		for (T current : collection){
			try{
				collectionConsumer.accept(current);
			}catch(Exception e){
				exceptions.add(e);
			}
		}
		return exceptions.isEmpty() ?
				Optional.empty():
				Optional.of(new MultipleIOException(exceptions));
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy