Surprise! We've been running on hardware provided by BuyVM for a few months and wanted to show them a little appreciation.
Running a paste site comes with unique challenges, ones that aren't always obvious and hard to control. As such, BuyVM offered us a home where we could worry less about the hosting side of things and focus on maintaining a clean and useful service! Go check them out and show them some love!
Submitted on November 29, 2014 at 02:59 AM

Section 1 (Java)

public class ReflectionUtil
{
    public static void runMethodsFromObjects(ArrayList<Object> objects, String methodName, Object... args) {
        for (int i = 0; i < objects.size(); i++) {
            runMethodFromObj(objects.get(i), methodName, args );
        }
    }

    public static void runMethodsFromClasses(ArrayList<Class> classes, String methodName, Object... args) {
        for (int i = 0; i < classes.size(); i++) {
            runMethodFromClass(classes.get(i), methodName, args);
        }
    }

    public static void runMethodFromObj(Object obj, String methodName, Object... args) {
        try {
            Class[] params = new Class[args.length];
            for (int i = 0; i < args.length; i++) {
                params[i] = args[i].getClass();
            }
            Method method = obj.getClass().getDeclaredMethod(methodName, params);
            method.setAccessible(true);
            method.invoke(obj, args);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }

    public static void runMethodFromClass(Class aClass, String methodName, Object... args) {
        try {
            Class[] params = new Class[args.length];
            for (int i = 0; i < args.length; i++) {
                params[i] = args[i].getClass();
            }
            Method method = aClass.getDeclaredMethod(methodName, params);
            method.setAccessible(true);
            method.invoke(aClass, args);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }

    public static void changeFieldFromObj(Object obj, String fieldName, Object value) {
        Class aClass = obj.getClass();
        Field field;
        try {
            field = aClass.getDeclaredField(fieldName);
            field.setAccessible(true);
            field.set(obj, value);
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }

    public static Object getFieldValFromObj(Object obj, String fieldName) {
        Class aClass = obj.getClass();
        Field field;
        try {
            field = aClass.getDeclaredField(fieldName);
            field.setAccessible(true);
            return field.get(obj);
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return null;
    }
}