code
stringlengths
73
34.1k
label
stringclasses
1 value
public static Dictionary<String, String> convertInitParams( final WebAppInitParam[] initParams) { if (initParams == null || initParams.length == 0) { return null; } Hashtable<String, String> dictionary = new Hashtable<>(); for (WebAppInitParam initParam : initParams) { dictionary.put(initParam.g...
java
private void createManagedService(final BundleContext context) { ManagedService service = this::scheduleUpdateConfig; final Dictionary<String, String> props = new Hashtable<>(); props.put(Constants.SERVICE_PID, org.ops4j.pax.web.service.WebContainerConstants.PID); context.registerService(ManagedService.class, s...
java
private static String validateAlias(final String alias) { NullArgumentException.validateNotNull(alias, "Alias"); if (!alias.startsWith("/")) { throw new IllegalArgumentException( "Alias does not start with slash (/)"); } // "/" must be allowed if (alias.length() > 1 && alias.endsWith("/")) { throw ...
java
private static String aliasAsUrlPattern(final String alias) { String urlPattern = alias; if (urlPattern != null && !urlPattern.equals("/") && !urlPattern.contains("*")) { if (urlPattern.endsWith("/")) { urlPattern = urlPattern + "*"; } else { urlPattern = urlPattern + "/*"; } } return urlPa...
java
@Override public void registerServlet(Class<? extends Servlet> servletClass, String[] urlPatterns, Dictionary<String, ?> initParams, HttpContext httpContext) throws ServletException { LOG.warn("Http service has already been stopped"); }
java
private String createResourceIdentifier(final String localePrefix, final String resourceName, final String resourceVersion, final String libraryName, final String libraryVersion) { final StringBuilder sb = new StringBuilder(); if (StringUtils.isNotBlank(localePrefix)) { sb.append(localePrefix).append(PATH_SEPAR...
java
public static String[] extractNameVersionType(String url) { Matcher m = ARTIFACT_MATCHER.matcher(url); if (!m.matches()) { return new String[]{url.split("\\.")[0], DEFAULT_VERSION}; } else { //CHECKSTYLE:OFF StringBuilder v = new StringBuilder(); String d1 = m.group(1); String d2 = m.group(2); S...
java
public void visit(final WebAppServlet webAppServlet) { //CHECKSTYLE:OFF NullArgumentException.validateNotNull(webAppServlet, "Web app servlet"); final String[] aliases = webAppServlet.getAliases(); if (aliases != null && aliases.length > 0) { for (String alias : aliases) { try { httpService.u...
java
public void addServletMapping(final WebAppServletMapping servletMapping) { NullArgumentException .validateNotNull(servletMapping, "Servlet mapping"); NullArgumentException.validateNotNull(servletMapping.getServletName(), "Servlet name"); NullArgumentException.validateNotNull(servletMapping.getUrlPattern()...
java
public List<WebAppServletMapping> getServletMappings( final String servletName) { final Set<WebAppServletMapping> webAppServletMappings = servletMappings .get(servletName); if (webAppServletMappings == null) { return new ArrayList<>(); } return new ArrayList<>(webAppServletMappings); }
java
public void addFilter(final WebAppFilter filter) { NullArgumentException.validateNotNull(filter, "Filter"); NullArgumentException.validateNotNull(filter.getFilterName(), "Filter name"); NullArgumentException.validateNotNull(filter.getFilterClass(), "Filter class"); filters.put(filter.getFilterName(), fi...
java
public void addFilterMapping(final WebAppFilterMapping filterMapping) { NullArgumentException.validateNotNull(filterMapping, "Filter mapping"); NullArgumentException.validateNotNull(filterMapping.getFilterName(), "Filter name"); final String filterName = filterMapping.getFilterName(); if (!orderedFilters.c...
java
public List<WebAppFilterMapping> getFilterMappings(final String filterName) { final Set<WebAppFilterMapping> webAppFilterMappings = filterMappings .get(filterName); if (webAppFilterMappings == null) { return new ArrayList<>(); } return new ArrayList<>(webAppFilterMappings); }
java
public void addErrorPage(final WebAppErrorPage errorPage) { NullArgumentException.validateNotNull(errorPage, "Error page"); if (errorPage.getErrorCode() == null && errorPage.getExceptionType() == null) { throw new NullPointerException( "At least one of error type or exception code must be set"); } e...
java
public void addContextParam(final WebAppInitParam contextParam) { NullArgumentException.validateNotNull(contextParam, "Context param"); NullArgumentException.validateNotNull(contextParam.getParamName(), "Context param name"); NullArgumentException.validateNotNull(contextParam.getParamValue(), "Context par...
java
public void addMimeMapping(final WebAppMimeMapping mimeMapping) { NullArgumentException.validateNotNull(mimeMapping, "Mime mapping"); NullArgumentException.validateNotNull(mimeMapping.getExtension(), "Mime mapping extension"); NullArgumentException.validateNotNull(mimeMapping.getMimeType(), "Mime mapping ...
java
public void addLoginConfig(final WebAppLoginConfig webApploginConfig) { NullArgumentException .validateNotNull(webApploginConfig, "Login Config"); NullArgumentException.validateNotNull( webApploginConfig.getAuthMethod(), "Login Config Authorization Method"); // NullArgumentException.validateNotNull(lo...
java
public void accept(final WebAppVisitor visitor) { visitor.visit(this); // First do everything else for (WebAppListener listener : listeners) { visitor.visit(listener); } if (!filters.isEmpty()) { // first visit the filters with a filter mapping in mapping order final List<WebAppFilter> remainingFilter...
java
private void configureSecurity(ServletContextHandler context, String realmName, String authMethod, String formLoginPage, String formErrorPage) { final SecurityHandler securityHandler = context.getSecurityHandler(); Authenticator authenticator = null; if (authMethod == null) { LOG.warn("UNKNOWN AUTH...
java
public void validate( KeyStore keyStore ) throws CertificateException { try { Enumeration<String> aliases = keyStore.aliases(); for ( ; aliases.hasMoreElements(); ) { String alias = aliases.nextElement(); validate(keyStore,alias); } ...
java
public void visit(final WebAppServlet webAppServlet) { NullArgumentException.validateNotNull(webAppServlet, "Web app servlet"); Class<? extends Servlet> servletClass = webAppServlet .getServletClass(); if (servletClass == null && webAppServlet.getServletClassName() != null) { try { servletClass =...
java
public void visit(final WebAppFilter webAppFilter) { NullArgumentException.validateNotNull(webAppFilter, "Web app filter"); String filterName = webAppFilter.getFilterName(); if (filterName != null) { //CHECKSTYLE:OFF try { webContainer.unregisterFilter(filterName); } catch (Exception ignore)...
java
public void visit(final WebAppListener webAppListener) { NullArgumentException.validateNotNull(webAppListener, "Web app listener"); final EventListener listener = webAppListener.getListener(); if (listener != null) { //CHECKSTYLE:OFF try { webContainer.unregisterEventListener(listener); }...
java
public void visit(final WebAppErrorPage webAppErrorPage) { NullArgumentException.validateNotNull(webAppErrorPage, "Web app error page"); //CHECKSTYLE:OFF try { webContainer.unregisterErrorPage(webAppErrorPage.getError(), httpContext); } catch (Exception ignore) { LOG.warn("Unregistration ...
java
@Override public void addEventListener(final EventListener listener) { super.addEventListener(listener); if ((listener instanceof HttpSessionActivationListener) || (listener instanceof HttpSessionAttributeListener) || (listener instanceof HttpSessionBindingListener) || (listener instanceof HttpSessionL...
java
public URL getResource(final String name) { final String normalizedName = Path.normalizeResourcePath(rootPath + (name.startsWith("/") ? "" : "/") + name).trim(); log.debug("Searching bundle " + bundle + " for resource [{}], normalized to [{}]", name, normalizedName); URL url = resourceCach...
java
public String getMimeType(final String name) { String mimeType = null; if (name != null && name.length() > 0 && name.contains(".")) { final String[] segments = name.split("\\."); mimeType = mimeMappings.get(segments[segments.length - 1]); } if (mimeType == null) { mimeType = httpContext.getMimeT...
java
public void publish(final WebApp webApp) { NullArgumentException.validateNotNull(webApp, "Web app"); LOG.debug("Publishing web application [{}]", webApp); final BundleContext webAppBundleContext = BundleUtils .getBundleContext(webApp.getBundle()); if (webAppBundleContext != null) { try { Filte...
java
public void unpublish(final WebApp webApp) { NullArgumentException.validateNotNull(webApp, "Web app"); LOG.debug("Unpublishing web application [{}]", webApp); final ServiceTracker<WebAppDependencyHolder, WebAppDependencyHolder> tracker = webApps .remove(webApp); if (tracker != null) { tracker.close...
java
@Override public void registerServlet(final String alias, final Servlet servlet, @SuppressWarnings("rawtypes") final Dictionary initParams, final HttpContext httpContext) throws ServletException, NamespaceException { synchronized (lock) { this.registerServlet(alias, servlet, initParams, null, n...
java
private <T> T withWhiteboardDtoService(Function<WhiteboardDtoService, T> function) { final BundleContext bundleContext = serviceBundle.getBundleContext(); ServiceReference<WhiteboardDtoService> ref = bundleContext.getServiceReference(WhiteboardDtoService.class); if (ref != null) { WhiteboardDtoService service ...
java
protected void preDestroy(Object instance, final Class<?> clazz) throws IllegalAccessException, InvocationTargetException { Class<?> superClass = clazz.getSuperclass(); if (superClass != Object.class) { preDestroy(instance, superClass); } // At the end the postconstruct annotated // method is invoked ...
java
protected void populateAnnotationsCache(Class<?> clazz, Map<String, String> injections) throws IllegalAccessException, InvocationTargetException { while (clazz != null) { List<AnnotationCacheEntry> annotations = null; synchronized (annotationCache) { annotations = annotationCache.get(clazz); ...
java
public static int pipeBytes(InputStream in, OutputStream out, byte[] buffer) throws IOException { int count = 0; int length; while ((length = (in.read(buffer))) >= 0) { out.write(buffer, 0, length); count += length; } return count; }
java
private List<Deployment> managedDeployments(List<Deployment> deployments) { List<Deployment> managed = new ArrayList<Deployment>(); for (Deployment deployment : deployments) { if (deployment.getDescription().managed()) { managed.add(deployment); } } ...
java
private List<Deployment> defaultDeployments(List<Deployment> deployments) { List<Deployment> defaults = new ArrayList<Deployment>(); for (Deployment deployment : deployments) { if (deployment.getDescription().getName().equals(DeploymentTargetDescription.DEFAULT.getName())) { ...
java
private List<Deployment> archiveDeployments(List<Deployment> deployments) { List<Deployment> archives = new ArrayList<Deployment>(); for (Deployment deployment : deployments) { if (deployment.getDescription().isArchiveDeployment()) { archives.add(deployment); } ...
java
private Deployment findMatchingDeployment(DeploymentTargetDescription target) { List<Deployment> matching = findMatchingDeployments(target); if (matching.size() == 0) { return null; } if (matching.size() == 1) { return matching.get(0); } // if mul...
java
private void validateNotSameNameAndTypeOfDeployment(DeploymentDescription deployment) { for (Deployment existing : deployments) { if (existing.getDescription().getName().equals(deployment.getName())) { if ( (existing.getDescription().isArchiveDeployment() && deplo...
java
private void validateNotSameArchiveAndSameTarget(DeploymentDescription deployment) { if (!deployment.isArchiveDeployment()) { return; } for (Deployment existing : archiveDeployments(deployments)) { if (existing.getDescription().getArchive().getName().equals(deployment.get...
java
private List<Object> getRuleInstances(Object testInstance) throws Exception { List<Object> ruleInstances = new ArrayList<Object>(); List<Field> fieldsWithRuleAnnotation = SecurityActions.getFieldsWithAnnotation(testInstance.getClass(), Rule.class); if (fieldsWithRuleAnnotation.isEmp...
java
public static void notNull(final Object obj, final String message) throws IllegalArgumentException { if (obj == null) { throw new IllegalArgumentException(message); } }
java
public static void notNullOrEmpty(final String string, final String message) throws IllegalArgumentException { if (string == null || string.length() == 0) { throw new IllegalArgumentException(message); } }
java
public static void stateNotNull(final Object obj, final String message) throws IllegalStateException { if (obj == null) { throw new IllegalStateException(message); } }
java
public static void configurationDirectoryExists(final String string, final String message) throws ConfigurationException { if (string == null || string.length() == 0 || new File(string).isDirectory() == false) { throw new ConfigurationException(message); } }
java
private static Object convert(Class<?> clazz, String value) { /* TODO create a new Converter class and move this method there for reuse */ if (Integer.class.equals(clazz) || int.class.equals(clazz)) { return Integer.valueOf(value); } else if (Double.class.equals(clazz) || double.class...
java
private Object[] resolveArguments(Manager manager, Object event) { final Class<?>[] argumentTypes = getMethod().getParameterTypes(); int numberOfArguments = argumentTypes.length; // we know that the first Argument is always the Event, and it will be there else this wouldn't be a Observer method...
java
private boolean containsNull(Object[] arguments) { for (Object argument : arguments) { if (argument == null) { return true; } } return false; }
java
private void validateConfiguration(ArquillianDescriptor desc) { Object defaultConfig = null; // verify only one container is marked as default for (ContainerDef container : desc.getContainers()) { if (container.isDefault()) { if (defaultConfig != null) { ...
java
public static String fileAsString(String filename) { File classpathFile = getClasspathFile(filename); return fileAsString(classpathFile); }
java
public static InputStream fileAsStream(String filename) { File classpathFile = getClasspathFile(filename); return fileAsStream(classpathFile); }
java
public static InputStream fileAsStream(File file) { try { return new BufferedInputStream(new FileInputStream(file)); } catch(FileNotFoundException e) { throw LOG.fileNotFoundException(file.getAbsolutePath(), e); } }
java
public static String join(String delimiter, String... parts) { if (parts == null) { return null; } if (delimiter == null) { delimiter = ""; } StringBuilder stringBuilder = new StringBuilder(); for (int i=0; i < parts.length; i++) { if (i > 0) { stringBuilder.append(de...
java
protected void logDebug(String id, String messageTemplate, Object... parameters) { if(delegateLogger.isDebugEnabled()) { String msg = formatMessageTemplate(id, messageTemplate); delegateLogger.debug(msg, parameters); } }
java
protected void logInfo(String id, String messageTemplate, Object... parameters) { if(delegateLogger.isInfoEnabled()) { String msg = formatMessageTemplate(id, messageTemplate); delegateLogger.info(msg, parameters); } }
java
protected void logWarn(String id, String messageTemplate, Object... parameters) { if(delegateLogger.isWarnEnabled()) { String msg = formatMessageTemplate(id, messageTemplate); delegateLogger.warn(msg, parameters); } }
java
protected void logError(String id, String messageTemplate, Object... parameters) { if(delegateLogger.isErrorEnabled()) { String msg = formatMessageTemplate(id, messageTemplate); delegateLogger.error(msg, parameters); } }
java
protected String formatMessageTemplate(String id, String messageTemplate) { return projectCode + "-" + componentId + id + " " + messageTemplate; }
java
protected String exceptionMessage(String id, String messageTemplate, Object... parameters) { String formattedTemplate = formatMessageTemplate(id, messageTemplate); if(parameters == null || parameters.length == 0) { return formattedTemplate; } else { return MessageFormatter.arrayFormat(formatted...
java
public static void ensureNotNull(String parameterName, Object value) { if(value == null) { throw LOG.parameterIsNullException(parameterName); } }
java
@SuppressWarnings("unchecked") public static <T> T ensureParamInstanceOf(String objectName, Object object, Class<T> type) { if(type.isAssignableFrom(object.getClass())) { return (T) object; } else { throw LOG.unsupportedParameterType(objectName, object, type); } }
java
private static int[] getFactors(int _value, int _max) { final int factors[] = new int[MAX_GROUP_SIZE]; int factorIdx = 0; for (int possibleFactor = 1; possibleFactor <= _max; possibleFactor++) { if ((_value % possibleFactor) == 0) { factors[factorIdx++] = possibleFactor; ...
java
public int getNumGroups(int _dim) { return (_dim == 0 ? (globalSize_0 / localSize_0) : (_dim == 1 ? (globalSize_1 / localSize_1) : (globalSize_2 / localSize_2))); }
java
public double getElapsedTimeCurrentThread(int stage) { if (stage == ProfilingEvent.START.ordinal()) { return 0; } Accumulator acc = getAccForThread(); return acc == null ? Double.NaN : (acc.currentTimes[stage] - acc.currentTimes[stage - 1]) / MILLION; }
java
public double getCumulativeElapsedTimeCurrrentThread(ProfilingEvent stage) { Accumulator acc = getAccForThread(); return acc == null ? Double.NaN : acc.accumulatedTimes[stage.ordinal()] / MILLION; }
java
public double getCumulativeElapsedTimeAllCurrentThread() { double sum = 0; Accumulator acc = getAccForThread(); if (acc == null) { return sum; } for (int i = 1; i <= ProfilingEvent.EXECUTED.ordinal(); ++i) { sum += acc.accumulatedTimes[i]; } return sum; }
java
public double getElapsedTimeLastThread(int stage) { if (stage == ProfilingEvent.START.ordinal()) { return 0; } Accumulator acc = lastAccumulator.get(); return acc == null ? Double.NaN : (acc.currentTimes[stage] - acc.currentTimes[stage - 1]) / MILLION; }
java
public double getCumulativeElapsedTimeGlobal(ProfilingEvent stage) { final long[] accumulatedTimesHolder = new long[NUM_EVENTS]; globalAcc.consultAccumulatedTimes(accumulatedTimesHolder); return accumulatedTimesHolder[stage.ordinal()] / MILLION; }
java
public double getCumulativeElapsedTimeAllGlobal() { final long[] accumulatedTimesHolder = new long[NUM_EVENTS]; globalAcc.consultAccumulatedTimes(accumulatedTimesHolder); double sum = 0; for (int i = 1; i <= ProfilingEvent.EXECUTED.ordinal(); ++i) { sum += accumulatedTimesHolder[i]; } ...
java
public boolean isSuperClass(String otherClassName) { if (getClassWeAreModelling().getName().equals(otherClassName)) { return true; } else if (superClazz != null) { return superClazz.isSuperClass(otherClassName); } else { return false; } }
java
public boolean isSuperClass(Class<?> other) { Class<?> s = other.getSuperclass(); while (s != null) { if ((getClassWeAreModelling() == s) || (getClassWeAreModelling().getName().equals(s.getName()))) { return true; } s = s.getSuperclass(); } return false; ...
java
public Integer getPrivateMemorySize(String fieldName) throws ClassParseException { if (CacheEnabler.areCachesEnabled()) return privateMemorySizes.computeIfAbsent(fieldName); return computePrivateMemorySize(fieldName); }
java
public ClassModelMethod getMethod(MethodEntry _methodEntry, boolean _isSpecial) { final String entryClassNameInDotForm = _methodEntry.getClassEntry().getNameUTF8Entry().getUTF8().replace('/', '.'); // Shortcut direct calls to supers to allow "foo() { super.foo() }" type stuff to work if (_isSpecial &...
java
public MethodModel getMethodModel(String _name, String _signature) throws AparapiException { if (CacheEnabler.areCachesEnabled()) return methodModelCache.computeIfAbsent(MethodKey.of(_name, _signature)); else { final ClassModelMethod method = getMethod(_name, _signature); return n...
java
public void setProfileReport(final long reportId, final long[] _currentTimes) { id = reportId; System.arraycopy(_currentTimes, 0, currentTimes, 0, NUM_EVENTS); }
java
public double getElapsedTime(int stage) { if (stage == ProfilingEvent.START.ordinal()) { return 0; } return (currentTimes[stage] - currentTimes[stage - 1]) / MILLION; }
java
public void configure() { if (configurator != null && !underConfiguration.get() && underConfiguration.compareAndSet(false, true)) { try { configurator.configure(this); } finally { underConfiguration.set(false); } } }
java
public static List<OpenCLDevice> listDevices(TYPE type) { final OpenCLPlatform platform = new OpenCLPlatform(0, null, null, null); final ArrayList<OpenCLDevice> results = new ArrayList<>(); for (final OpenCLPlatform p : platform.getOpenCLPlatforms()) { for (final OpenCLDevice device : p.getO...
java
void onStart(Device device) { KernelDeviceProfile currentDeviceProfile = deviceProfiles.get(device); if (currentDeviceProfile == null) { currentDeviceProfile = new KernelDeviceProfile(this, kernelClass, device); KernelDeviceProfile existingProfile = deviceProfiles.putIfAbsent(device, cu...
java
void onEvent(Device device, ProfilingEvent event) { if (event == null) { logger.log(Level.WARNING, "Discarding profiling event " + event + " for null device, for Kernel class: " + kernelClass.getName()); return; } final KernelDeviceProfile deviceProfile = deviceProfiles.get(device); switch (event...
java
@Override public String convertType(String _typeDesc, boolean useClassModel, boolean isLocal) { if (_typeDesc.equals("Z") || _typeDesc.equals("boolean")) { return (cvtBooleanToChar); } else if (_typeDesc.equals("[Z") || _typeDesc.equals("boolean[]")) { return isLocal ? (cvtBooleanArrayToCh...
java
private ClassModel getClassModelFromArg(KernelArg arg, final Class<?> arrayClass) { ClassModel c = null; if (arg.getObjArrayElementModel() == null) { final String tmp = arrayClass.getName().substring(2).replace('/', '.'); final String arrayClassInDotForm = tmp.substring(0, tmp.length() - 1)...
java
public boolean allocateArrayBufferIfFirstTimeOrArrayChanged(KernelArg arg, Object newRef, final int objArraySize, final int totalStructSize, final int totalBufferSize) { boolean didReallocate = false; if ((arg.getObjArrayBuffer() == null) || (newRef != arg.getArray())) { final ByteBuffer st...
java
public boolean isDeviceAmongPreferredDevices(Device device) { maybeSetUpDefaultPreferredDevices(); boolean result = false; synchronized (this) { result = preferredDevices.get().contains(device); } return result; }
java
public static OpenCLKernel createKernel(OpenCLProgram _program, String _kernelName, List<OpenCLArgDescriptor> _args) { final OpenCLArgDescriptor[] argArray = _args.toArray(new OpenCLArgDescriptor[0]); final OpenCLKernel oclk = new OpenCLKernel().createKernelJNI(_program, _kernelName, argArray); for (f...
java
public boolean doesNotContainContinueOrBreak(Instruction _start, Instruction _extent) { boolean ok = true; boolean breakOrContinue = false; for (Instruction i = _start; i != null; i = i.getNextExpr()) { if (i.isBranch()) { if (i.asBranch().isForwardUnconditional() && i.asBranch()....
java
public Instruction add(Instruction _instruction) { if (head == null) { head = _instruction; } else { _instruction.setPrevExpr(tail); tail.setNextExpr(_instruction); } tail = _instruction; logger.log(Level.FINE, "After PUSH of " + _instruction + " tail=" + tail...
java
public void replaceInclusive(Instruction _head, Instruction _tail, Instruction _newOne) { _newOne.setNextExpr(null); _newOne.setPrevExpr(null); final Instruction prevHead = _head.getPrevExpr(); if (_tail == null) { // this is the new tail _newOne.setPrevExpr(prevHead); ...
java
public static <T extends Kernel> T sharedKernelInstance(Class<T> kernelClass) { return instance().getSharedKernelInstance(kernelClass); }
java
public void deoptimizeReverseBranches() { for (Instruction instruction = pcHead; instruction != null; instruction = instruction.getNextPC()) { if (instruction.isBranch()) { final Branch branch = instruction.asBranch(); if (branch.isReverse()) { final Instruction ta...
java
void checkForSetter(Map<Integer, Instruction> pcMap) throws ClassParseException { final String methodName = getMethod().getName(); if (methodName.startsWith("set")) { final String rawVarNameCandidate = methodName.substring(3); final String firstLetter = rawVarNameCandidate.substring(0, 1)....
java
public static String getSimpleName(Class<?> klass) { String simpleName = klass.getSimpleName(); if (simpleName.isEmpty()) { String fullName = klass.getName(); int index = fullName.lastIndexOf('.'); simpleName = (index < 0) ? fullName : fullName.substring(index + 1); } ...
java
public void loadFromResource(String resource, Candidate.CandidateType type) throws IOException { InputStream candidatesConfig = classloader.getResourceAsStream(resource); if(candidatesConfig == null) { throw new IOException("Resource '" + resource + "' not found"); } try { load...
java
public static void main(String[] args) { TextReporter reporter = new TextReporter(System.out, System.err); run(reporter); if(reporter.hasErrors()) { System.exit(1); } }
java
public static void run(Reporter reporter) { TCK tck = new TCK(new ObjenesisStd(), new ObjenesisSerializer(), reporter); tck.runTests(); }
java
public static SortedSet<String> getClassesForPackage(Package pkg, ClassLoader classLoader) { SortedSet<String> classes = new TreeSet<>(new Comparator<String>() { public int compare(String o1, String o2) { String simpleName1 = getSimpleName(o1); String simpleName2 = getSimp...
java
public static byte[] readClass(String className) throws IOException { // convert to a resource className = ClassUtils.classNameToResource(className); byte[] b = new byte[2500]; // I'm assuming that I'm reading class that are not too big int length; try (InputStream in = ClassDefinitionU...
java
public static void writeClass(String fileName, byte[] bytes) throws IOException { try (BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(fileName))) { out.write(bytes); } }
java
@SuppressWarnings("unchecked") public static <T> Class<T> getExistingClass(ClassLoader classLoader, String className) { try { return (Class<T>) Class.forName(className, true, classLoader); } catch (ClassNotFoundException e) { return null; } }
java
public void registerCandidate(Class<?> candidateClass, String description, Candidate.CandidateType type) { Candidate candidate = new Candidate(candidateClass, description, type); int index = candidates.indexOf(candidate); if(index >= 0) { Candidate existingCandidate = candidates.get(index); ...
java