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

io.debezium.text.MultipleParsingExceptions Maven / Gradle / Ivy

/*
 * Copyright Debezium Authors.
 *
 * Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
 */
package io.debezium.text;

import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.Collections;
import java.util.function.Consumer;

/**
 * Representation of multiple {@link ParsingException}s.
 * @author Randall Hauch
 */
public class MultipleParsingExceptions extends RuntimeException {

    private static final long serialVersionUID = 1L;
    private final Collection errors;

    public MultipleParsingExceptions(Collection errors) {
        this("Multiple parsing errors", errors);
    }

    public MultipleParsingExceptions(String message, Collection errors) {
        super(message);
        this.errors = Collections.unmodifiableCollection(errors);
    }

    /**
     * Get the set of parsing exceptions.
     * @return the parsing exceptions
     */
    public Collection getErrors() {
        return errors;
    }

    public void forEachError(Consumer action) {
        errors.forEach(action);
    }

    @Override
    public void printStackTrace() {
        forEachError(ParsingException::printStackTrace);
    }

    @Override
    public void printStackTrace(PrintStream s) {
        forEachError(e -> e.printStackTrace(s));
    }

    @Override
    public void printStackTrace(PrintWriter s) {
        forEachError(e -> e.printStackTrace(s));
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder(getMessage());
        forEachError(e -> {
            sb.append(System.lineSeparator()).append(e.toString());
        });
        return sb.toString();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy