本文整理了Java中java.util.Enumeration
类的一些代码示例,展示了Enumeration
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Enumeration
类的具体详情如下:
包路径:java.util.Enumeration
类名称:Enumeration
[英]A legacy iteration interface.
New code should use Iterator instead. Iterator replaces the enumeration interface and adds a way to remove elements from a collection.
If you have an Enumeration and want a Collection, you can use Collections#list to get a List.
If you need an Enumeration for a legacy API and have a Collection, you can use Collections#enumeration.
[中]遗留迭代接口。
新代码应该使用迭代器。迭代器替换了枚举接口,并添加了从集合中删除元素的方法。
如果您有一个枚举并且想要一个集合,那么可以使用集合列表来获取列表。
如果您需要遗留API的枚举并拥有集合,则可以使用集合#枚举。
代码示例来源:origin: alibaba/druid
private static void loadFilterConfig(Properties filterProperties, ClassLoader classLoader) throws IOException {
if (classLoader == null) {
return;
}
for (Enumeration<URL> e = classLoader.getResources("META-INF/druid-filter.properties"); e.hasMoreElements();) {
URL url = e.nextElement();
Properties property = new Properties();
InputStream is = null;
try {
is = url.openStream();
property.load(is);
} finally {
JdbcUtils.close(is);
}
filterProperties.putAll(property);
}
}
代码示例来源:origin: spring-projects/spring-framework
private static HttpHeaders createDefaultHttpHeaders(HttpServletRequest request) {
HttpHeaders headers = new HttpHeaders();
for (Enumeration<?> names = request.getHeaderNames(); names.hasMoreElements(); ) {
String name = (String) names.nextElement();
for (Enumeration<?> values = request.getHeaders(name); values.hasMoreElements(); ) {
headers.add(name, (String) values.nextElement());
}
}
return headers;
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Copy the configured output {@link Properties}, if any, into the
* {@link Transformer#setOutputProperty output property set} of the supplied
* {@link Transformer}.
* @param transformer the target transformer
*/
protected final void copyOutputProperties(Transformer transformer) {
if (this.outputProperties != null) {
Enumeration<?> en = this.outputProperties.propertyNames();
while (en.hasMoreElements()) {
String name = (String) en.nextElement();
transformer.setOutputProperty(name, this.outputProperties.getProperty(name));
}
}
}
代码示例来源:origin: google/guava
@Override
protected void scanJarFile(ClassLoader classloader, JarFile file) {
Enumeration<JarEntry> entries = file.entries();
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
if (entry.isDirectory() || entry.getName().equals(JarFile.MANIFEST_NAME)) {
continue;
}
resources.get(classloader).add(entry.getName());
}
}
代码示例来源:origin: netty/netty
Properties props = new Properties();
try {
Enumeration<URL> resources = classLoader.getResources("META-INF/io.netty.versions.properties");
while (resources.hasMoreElements()) {
URL url = resources.nextElement();
InputStream in = url.openStream();
try {
props.load(in);
} finally {
try {
in.close();
} catch (Exception ignore) {
for (Object o: props.keySet()) {
String k = (String) o;
代码示例来源:origin: spring-projects/spring-framework
Properties props = new Properties();
while (urls.hasMoreElements()) {
URL url = urls.nextElement();
URLConnection con = url.openConnection();
ResourceUtils.useCachesIfNecessary(con);
InputStream is = con.getInputStream();
try {
if (resourceName.endsWith(XML_FILE_EXTENSION)) {
props.loadFromXML(is);
props.load(is);
is.close();
代码示例来源:origin: eclipse-vertx/vert.x
protected String getCommandFromManifest() {
try {
Enumeration<URL> resources = RunCommand.class.getClassLoader().getResources("META-INF/MANIFEST.MF");
while (resources.hasMoreElements()) {
InputStream stream = resources.nextElement().openStream();
Manifest manifest = new Manifest(stream);
Attributes attributes = manifest.getMainAttributes();
String mainClass = attributes.getValue("Main-Class");
if (main.getClass().getName().equals(mainClass)) {
String command = attributes.getValue("Main-Command");
if (command != null) {
stream.close();
return command;
}
}
stream.close();
}
} catch (IOException e) {
throw new IllegalStateException(e.getMessage());
}
return null;
}
代码示例来源:origin: log4j/log4j
Hashtable filters = new Hashtable();
Enumeration e = props.keys();
String name = "";
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
if (key.startsWith(filterPrefix)) {
int dotIdx = key.indexOf('.', fIdx);
name = key.substring(dotIdx+1);
filterOpts.add(new NameValue(name, value));
while (g.hasMoreElements()) {
String key = (String) g.nextElement();
String clazz = props.getProperty(key);
if (clazz != null) {
LogLog.debug("Filter key: ["+key+"] class: ["+props.getProperty(key) +"] props: "+filters.get(key));
Filter filter = (Filter) OptionConverter.instantiateByClassName(clazz, Filter.class, null);
if (filter != null) {
PropertySetter propSetter = new PropertySetter(filter);
Vector v = (Vector)filters.get(key);
Enumeration filterProps = v.elements();
while (filterProps.hasMoreElements()) {
NameValue kv = (NameValue)filterProps.nextElement();
propSetter.setProperty(kv.key, kv.value);
代码示例来源:origin: apache/flink
jar = new JarFile(new File(jarFile.toURI()));
final List<JarEntry> containedJarFileEntries = new ArrayList<JarEntry>();
Enumeration<JarEntry> entries = jar.entries();
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
String name = entry.getName();
for (int i = 0; i < containedJarFileEntries.size(); i++) {
final JarEntry entry = containedJarFileEntries.get(i);
String name = entry.getName();
throw new ProgramInvocationException(
"An I/O error occurred while creating temporary file to extract nested library '" +
entry.getName() + "'.", e);
in = new BufferedInputStream(jar.getInputStream(entry));
while ((numRead = in.read(buffer)) != -1) {
out.write(buffer, 0, numRead);
in.close();
代码示例来源:origin: git-commit-id/maven-git-commit-id-plugin
@Override
public Enumeration keys() {
Enumeration keysEnum = super.keys();
Vector<String> keyList = new Vector<>();
while (keysEnum.hasMoreElements()) {
keyList.add((String)keysEnum.nextElement());
}
Collections.sort(keyList);
return keyList.elements();
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public Map<String, String[]> getParameterMap() {
Map<String, String[]> result = new LinkedHashMap<>();
Enumeration<String> names = getParameterNames();
while (names.hasMoreElements()) {
String name = names.nextElement();
result.put(name, getParameterValues(name));
}
return result;
}
代码示例来源:origin: alibaba/druid
public void setColumnMargin(int margin) {
this.margin = margin;
Enumeration<Object> enumeration = vector.elements();
while (enumeration.hasMoreElements()) {
Object obj = enumeration.nextElement();
if (obj instanceof ColumnGroup) {
((ColumnGroup) obj).setColumnMargin(margin);
}
}
}
代码示例来源:origin: androidannotations/androidannotations
JarFile jar = null;
try {
jarURL = new URL("file:/" + file.getCanonicalPath());
jarURL = new URL("jar:" + jarURL.toExternalForm() + "!/");
JarURLConnection conn = (JarURLConnection) jarURL.openConnection();
jar = conn.getJarFile();
Enumeration<JarEntry> e = jar.entries();
while (e.hasMoreElements()) {
JarEntry entry = e.nextElement();
if (entry.isDirectory()) {
if (entry.getName().toUpperCase().equals("META-INF/")) {
continue;
map.put(new URL(jarURL.toExternalForm() + entry.getName()), packageNameFor(entry));
} catch (MalformedURLException murl) {
代码示例来源:origin: skylot/jadx
public static String getVersion() {
try {
ClassLoader classLoader = Jadx.class.getClassLoader();
if (classLoader != null) {
Enumeration<URL> resources = classLoader.getResources("META-INF/MANIFEST.MF");
while (resources.hasMoreElements()) {
Manifest manifest = new Manifest(resources.nextElement().openStream());
String ver = manifest.getMainAttributes().getValue("jadx-version");
if (ver != null) {
return ver;
}
}
}
} catch (Exception e) {
LOG.error("Can't get manifest file", e);
}
return "dev";
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Set the mappings of bean keys to a comma-separated list of method names.
* The property key should match the bean key and the property value should match
* the list of method names. When searching for method names for a bean, Spring
* will check these mappings first.
* @param mappings the mappings of bean keys to method names
*/
public void setMethodMappings(Properties mappings) {
this.methodMappings = new HashMap<>();
for (Enumeration<?> en = mappings.keys(); en.hasMoreElements();) {
String beanKey = (String) en.nextElement();
String[] methodNames = StringUtils.commaDelimitedListToStringArray(mappings.getProperty(beanKey));
this.methodMappings.put(beanKey, new HashSet<>(Arrays.asList(methodNames)));
}
}
代码示例来源:origin: apache/incubator-dubbo
@Override
public void handle(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
String uri = request.getRequestURI();
HessianSkeleton skeleton = skeletonMap.get(uri);
if (!request.getMethod().equalsIgnoreCase("POST")) {
response.setStatus(500);
} else {
RpcContext.getContext().setRemoteAddress(request.getRemoteAddr(), request.getRemotePort());
Enumeration<String> enumeration = request.getHeaderNames();
while (enumeration.hasMoreElements()) {
String key = enumeration.nextElement();
if (key.startsWith(Constants.DEFAULT_EXCHANGER)) {
RpcContext.getContext().setAttachment(key.substring(Constants.DEFAULT_EXCHANGER.length()),
request.getHeader(key));
}
}
try {
skeleton.invoke(request.getInputStream(), response.getOutputStream());
} catch (Throwable e) {
throw new ServletException(e);
}
}
}
代码示例来源:origin: lets-blade/blade
List<FileMeta> getResourceListing(URL dirURL, String path) throws IOException {
List<FileMeta> listFiles = new ArrayList<>();
if (null == CACHE_JAR_FILE) {
//strip out only the JAR file
String jarPath = dirURL.getPath().substring(5, dirURL.getPath().indexOf("!"));
CACHE_JAR_FILE = new JarFile(URLDecoder.decode(jarPath, "UTF-8"));
}
Enumeration<JarEntry> entries = CACHE_JAR_FILE.entries();
while (entries.hasMoreElements()) {
JarEntry jarEntry = entries.nextElement();
String name = jarEntry.getName();
if (!name.startsWith(path) || name.equals(path + "/")) {
continue;
}
FileMeta fileMeta = new FileMeta();
fileMeta.name = name.substring(path.length() + 1);
fileMeta.isDirectory = jarEntry.isDirectory();
if (!fileMeta.isDirectory) {
fileMeta.length = jarEntry.getSize();
}
listFiles.add(fileMeta);
}
return listFiles;
}
代码示例来源:origin: spring-projects/spring-framework
throws IOException {
URLConnection con = rootDirURL.openConnection();
JarFile jarFile;
String jarFileUrl;
ResourceUtils.useCachesIfNecessary(jarCon);
jarFile = jarCon.getJarFile();
jarFileUrl = jarCon.getJarFileURL().toExternalForm();
JarEntry jarEntry = jarCon.getJarEntry();
rootEntryPath = (jarEntry != null ? jarEntry.getName() : "");
closeJarFile = !jarCon.getUseCaches();
String urlFile = rootDirURL.getFile();
try {
int separatorIndex = urlFile.indexOf(ResourceUtils.WAR_URL_SEPARATOR);
jarFile = new JarFile(urlFile);
jarFileUrl = urlFile;
rootEntryPath = "";
for (Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements();) {
JarEntry entry = entries.nextElement();
String entryPath = entry.getName();
if (entryPath.startsWith(rootEntryPath)) {
String relativePath = entryPath.substring(rootEntryPath.length());
jarFile.close();
代码示例来源:origin: loklak/loklak_server
private static void extractContents() {
// Check if we're running inside a JAR file
if(!LoklakServer.class.getResource("LoklakServer.class").getPath().startsWith("file:"))
return;
try {
JarFile jar =
new JarFile(LoklakServer.class.getProtectionDomain().getCodeSource().getLocation().getPath());
Enumeration entries = jar.entries();
while (entries.hasMoreElements()) {
JarEntry file = (JarEntry) entries.nextElement();
for (String s : FOLDER_TO_EXTRACT) {
if (file.getName().startsWith(s + File.separator)) {
extract(jar, file);
continue;
}
}
}
} catch (IOException e) {
DAO.severe("An exception has occurred while extracting contents from JAR File", e);
DAO.log("Exiting due to fatal error ...");
System.exit(1);
}
}
代码示例来源:origin: redisson/redisson
/**
* This method is periodically invoked so that memory
* footprint will be minimized.
*/
void compress() {
if (compressCount++ > COMPRESS_THRESHOLD) {
compressCount = 0;
Enumeration e = classes.elements();
while (e.hasMoreElements())
((CtClass)e.nextElement()).compress();
}
}
内容来源于网络,如有侵权,请联系作者删除!