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

org.hibernate.validator.internal.util.privilegedactions.GetResources Maven / Gradle / Ivy

There is a newer version: 8.0.1.Final
Show newest version
/*
 * Hibernate Validator, declare and validate application constraints
 *
 * License: Apache License, Version 2.0
 * See the license.txt file in the root directory or .
 */


package org.hibernate.validator.internal.util.privilegedactions;

import java.io.IOException;
import java.net.URL;
import java.security.PrivilegedAction;
import java.util.Collections;
import java.util.Enumeration;

/**
 * A {@code PrivilegedAction} wrapping around {@code ClassLoader.getResources(String)}.
 *
 * @author Hardy Ferentschik
 */
public final class GetResources implements PrivilegedAction> {

	private final String resourceName;
	private final ClassLoader classLoader;

	public static GetResources action(ClassLoader classLoader, String resourceName) {
		return new GetResources( classLoader, resourceName );
	}

	private GetResources(ClassLoader classLoader, String resourceName) {
		this.classLoader = classLoader;
		this.resourceName = resourceName;
	}

	@Override
	public Enumeration run() {
		try {
			return classLoader.getResources( resourceName );
		}
		catch (IOException e) {
			// Collections.emptyEnumeration() would be 1.7
			return Collections.enumeration( Collections.emptyList() );
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy