@Test public void testInstantiateClassWithParameters() throws Exception { StringBuilder builder = OAuthUtils.instantiateClassWithParameters(StringBuilder.class, new Class[]{String.class}, new Object[]{"something"}); assertNotNull(builder); assertEquals("something", builder.toString()); }
public static <T> T instantiateClassWithParameters(Class<T> clazz, Class<?>[] paramsTypes, Object[] paramValues) throws OAuthSystemException { try { if (paramsTypes != null && paramValues != null) { if (!(paramsTypes.length == paramValues.length)) { throw new IllegalArgumentException("Number of types and values must be equal"); } if (paramsTypes.length == 0 && paramValues.length == 0) { return clazz.newInstance(); } Constructor<T> clazzConstructor = clazz.getConstructor(paramsTypes); return clazzConstructor.newInstance(paramValues); } return clazz.newInstance(); } catch (NoSuchMethodException e) { throw new OAuthSystemException(e); } catch (InstantiationException e) { throw new OAuthSystemException(e); } catch (IllegalAccessException e) { throw new OAuthSystemException(e); } catch (InvocationTargetException e) { throw new OAuthSystemException(e); } }
OAuthUtils { public static <T> T instantiateClassWithParameters(Class<T> clazz, Class<?>[] paramsTypes, Object[] paramValues) throws OAuthSystemException { try { if (paramsTypes != null && paramValues != null) { if (!(paramsTypes.length == paramValues.length)) { throw new IllegalArgumentException("Number of types and values must be equal"); } if (paramsTypes.length == 0 && paramValues.length == 0) { return clazz.newInstance(); } Constructor<T> clazzConstructor = clazz.getConstructor(paramsTypes); return clazzConstructor.newInstance(paramValues); } return clazz.newInstance(); } catch (NoSuchMethodException e) { throw new OAuthSystemException(e); } catch (InstantiationException e) { throw new OAuthSystemException(e); } catch (IllegalAccessException e) { throw new OAuthSystemException(e); } catch (InvocationTargetException e) { throw new OAuthSystemException(e); } } }
OAuthUtils { public static <T> T instantiateClassWithParameters(Class<T> clazz, Class<?>[] paramsTypes, Object[] paramValues) throws OAuthSystemException { try { if (paramsTypes != null && paramValues != null) { if (!(paramsTypes.length == paramValues.length)) { throw new IllegalArgumentException("Number of types and values must be equal"); } if (paramsTypes.length == 0 && paramValues.length == 0) { return clazz.newInstance(); } Constructor<T> clazzConstructor = clazz.getConstructor(paramsTypes); return clazzConstructor.newInstance(paramValues); } return clazz.newInstance(); } catch (NoSuchMethodException e) { throw new OAuthSystemException(e); } catch (InstantiationException e) { throw new OAuthSystemException(e); } catch (IllegalAccessException e) { throw new OAuthSystemException(e); } catch (InvocationTargetException e) { throw new OAuthSystemException(e); } }  }
OAuthUtils { public static <T> T instantiateClassWithParameters(Class<T> clazz, Class<?>[] paramsTypes, Object[] paramValues) throws OAuthSystemException { try { if (paramsTypes != null && paramValues != null) { if (!(paramsTypes.length == paramValues.length)) { throw new IllegalArgumentException("Number of types and values must be equal"); } if (paramsTypes.length == 0 && paramValues.length == 0) { return clazz.newInstance(); } Constructor<T> clazzConstructor = clazz.getConstructor(paramsTypes); return clazzConstructor.newInstance(paramValues); } return clazz.newInstance(); } catch (NoSuchMethodException e) { throw new OAuthSystemException(e); } catch (InstantiationException e) { throw new OAuthSystemException(e); } catch (IllegalAccessException e) { throw new OAuthSystemException(e); } catch (InvocationTargetException e) { throw new OAuthSystemException(e); } }  static String format(
        final Collection<? extends Map.Entry<String, Object>> parameters,
        final String encoding); static String saveStreamAsString(InputStream is); static String toString(
        final InputStream is, final String defaultCharset); static OAuthProblemException handleOAuthProblemException(String message); static OAuthProblemException handleMissingParameters(Set<String> missingParams); static OAuthProblemException handleBadContentTypeException(String expectedContentType); static OAuthProblemException handleNotAllowedParametersOAuthException(
        List<String> notAllowedParams); static Map<String, Object> decodeForm(String form); static boolean isFormEncoded(String contentType); static String decodePercent(String s); static String percentEncode(String s); static T instantiateClass(Class<T> clazz); static T instantiateClassWithParameters(Class<T> clazz, Class<?>[] paramsTypes,
                                                       Object[] paramValues); static String getAuthHeaderField(String authHeader); static Map<String, String> decodeOAuthHeader(String header); static String[] decodeClientAuthenticationHeader(String authenticationHeader); static String encodeOAuthHeader(Map<String, Object> entries); static String encodeAuthorizationBearerHeader(Map<String, Object> entries); static boolean isEmpty(String value); static boolean hasEmptyValues(String[] array); static String getAuthzMethod(String header); static Set<String> decodeScopes(String s); static String encodeScopes(Set<String> s); static boolean isMultipart(HttpServletRequest request); static boolean hasContentType(String requestContentType, String requiredContentType); }
OAuthUtils { public static <T> T instantiateClassWithParameters(Class<T> clazz, Class<?>[] paramsTypes, Object[] paramValues) throws OAuthSystemException { try { if (paramsTypes != null && paramValues != null) { if (!(paramsTypes.length == paramValues.length)) { throw new IllegalArgumentException("Number of types and values must be equal"); } if (paramsTypes.length == 0 && paramValues.length == 0) { return clazz.newInstance(); } Constructor<T> clazzConstructor = clazz.getConstructor(paramsTypes); return clazzConstructor.newInstance(paramValues); } return clazz.newInstance(); } catch (NoSuchMethodException e) { throw new OAuthSystemException(e); } catch (InstantiationException e) { throw new OAuthSystemException(e); } catch (IllegalAccessException e) { throw new OAuthSystemException(e); } catch (InvocationTargetException e) { throw new OAuthSystemException(e); } }  static String format(
        final Collection<? extends Map.Entry<String, Object>> parameters,
        final String encoding); static String saveStreamAsString(InputStream is); static String toString(
        final InputStream is, final String defaultCharset); static OAuthProblemException handleOAuthProblemException(String message); static OAuthProblemException handleMissingParameters(Set<String> missingParams); static OAuthProblemException handleBadContentTypeException(String expectedContentType); static OAuthProblemException handleNotAllowedParametersOAuthException(
        List<String> notAllowedParams); static Map<String, Object> decodeForm(String form); static boolean isFormEncoded(String contentType); static String decodePercent(String s); static String percentEncode(String s); static T instantiateClass(Class<T> clazz); static T instantiateClassWithParameters(Class<T> clazz, Class<?>[] paramsTypes,
                                                       Object[] paramValues); static String getAuthHeaderField(String authHeader); static Map<String, String> decodeOAuthHeader(String header); static String[] decodeClientAuthenticationHeader(String authenticationHeader); static String encodeOAuthHeader(Map<String, Object> entries); static String encodeAuthorizationBearerHeader(Map<String, Object> entries); static boolean isEmpty(String value); static boolean hasEmptyValues(String[] array); static String getAuthzMethod(String header); static Set<String> decodeScopes(String s); static String encodeScopes(Set<String> s); static boolean isMultipart(HttpServletRequest request); static boolean hasContentType(String requestContentType, String requiredContentType); static final String AUTH_SCHEME; static final String MULTIPART; }