<commit_before>package com.ardverk.utils;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;

public class ExceptionUtils {
    
    private ExceptionUtils() {}
    
    /**
     * Takes the given Exception, wraps it in an {@link IOException}
     * and returns it.
     */
    public static IOException toIOException(Throwable cause) {
        if (cause == null) {
            throw new NullPointerException("cause");
        }
        
        if (cause instanceof IOException) {
            return (IOException)cause;
        }
        
        return new IOException(cause);
    }
    
    /**
     * Returns true if the message of the given {@link Throwable}
     * contains any of the other messages.
     */
    public static boolean isIgnorable(Throwable t, String... messages) {
        String msg = t.getMessage();
        if (msg != null) {
            for (int i = messages.length-1; i >= 0; --i) {
                if (msg.startsWith(messages[i])) {
                    return true;
                }
            }
        }
        return false;
    }
    
    /**
     * Returns true if Throwable <tt>t</tt> was caused by an another
     * Exception that is of type <tt>clazz</tt>
     */
    public static boolean isCausedBy(Throwable t, Class<? extends Throwable> clazz) {
        return getCause(t, clazz) != null;
    }
    
    /**
     * Returns the first Exception from the exception cause 
     * chain that is of type <tt>clazz</tt> or null if the
     * given Throwable was not caused a such Exception.
     */
    @SuppressWarnings("unchecked")
    public static <T extends Throwable> T getCause(Throwable t, Class<T> clazz) {
        while(t != null) {
            if (clazz.isInstance(t)) {
                return (T)t;
            }
            t = t.getCause();
        }
        return null;
    }
    
    
    
    /**
     * Returns the stack trace of the given {@link Throwable}
     * as a String.
     */
    public static String toString(Throwable t) {
        if (t == null) {
            return null;
        }
        StringWriter out = new StringWriter();
        PrintWriter pw = new PrintWriter(out);
        t.printStackTrace(pw);
        IoUtils.close(out);
        return out.toString();
    }
}<commit_msg>Comments, cleaning it up a bit<commit_after>package com.ardverk.utils;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * An utility class to make working with {@link Exception}s easier.
 */
public class ExceptionUtils {
    
    private ExceptionUtils() {}
    
    /**
     * An utility method to wrap {@link Throwable}s in {@link IOException}s
     * unless they are already an {@link IOException} in which case it will
     * simply cast and return it.
     */
    public static IOException toIOException(Throwable cause) {
        if (cause == null) {
            throw new NullPointerException("cause");
        }
        
        if (cause instanceof IOException) {
            return (IOException)cause;
        }
        
        return new IOException(cause);
    }
    
    /**
     * Returns true if the given {@link Throwable} is or rather was caused
     * by an instance of the given {@link Class}.
     */
    public static boolean isCausedBy(Throwable t, Class<? extends Throwable> clazz) {
        return getCause(t, clazz) != null;
    }
    
    /**
     * Returns the first {@link Exception} from the cause chain that is an
     * instance of the given {@link Class}.
     */
    @SuppressWarnings("unchecked")
    public static <T extends Throwable> T getCause(Throwable t, Class<T> clazz) {
        while(t != null) {
            if (clazz.isInstance(t)) {
                return (T)t;
            }
            t = t.getCause();
        }
        return null;
    }
    
    
    
    /**
     * Turns the given {@link Throwable} in a nicely formatted {@link String}.
     */
    public static String toString(Throwable t) {
        if (t == null) {
            return null;
        }
        StringWriter out = new StringWriter();
        PrintWriter pw = new PrintWriter(out);
        t.printStackTrace(pw);
        IoUtils.close(out);
        return out.toString();
    }
}
{'fraction_non_alphanumeric': 0.10210352162609312, 'fraction_numerical': 0.0004727014890096904, 'mean_word_length': 1.8710990502035278, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6647199', 'n_tokens_mistral': 1183, 'n_tokens_neox': 1163, 'n_words': 378}