List of usage examples for java.util Enumeration Enumeration
Enumeration
From source file:net.lightbody.bmp.proxy.jetty.http.HttpFields.java
/** Get multi field values with separator. * The multiple values can be represented as separate headers of * the same name, or by a single header using the separator(s), or * a combination of both. Separators may be quoted. * @param name the case-insensitive field name * @param separators String of separators. * @return Enumeration of the values, or null if no such header. *///from w ww.j a v a 2 s . c o m public Enumeration getValues(String name, final String separators) { final Enumeration e = getValues(name); if (e == null) return null; return new Enumeration() { QuotedStringTokenizer tok = null; public boolean hasMoreElements() { if (tok != null && tok.hasMoreElements()) return true; while (e.hasMoreElements()) { String value = (String) e.nextElement(); tok = new QuotedStringTokenizer(value, separators, false, false); if (tok.hasMoreElements()) return true; } tok = null; return false; } public Object nextElement() throws NoSuchElementException { if (!hasMoreElements()) throw new NoSuchElementException(); String next = (String) tok.nextElement(); if (next != null) next = next.trim(); return next; } }; }
From source file:net.wastl.webmail.misc.Helper.java
public static Enumeration breakLine(String line, int linesize, int quotelevel) { if (line.length() <= linesize) { final String s = line; return new Enumeration() { int count = 0; public boolean hasMoreElements() { return count == 0; }/* w ww .j a va 2s . c o m*/ public Object nextElement() { count++; if (count == 1) return s; else return null; } }; } else { int breakpos = findFittingBreakPos(line, linesize); final String first = line.substring(0, breakpos); String rest = ""; for (int i = 0; i < quotelevel; i++) rest += ">"; rest += line.substring(breakpos); final Enumeration enumVar = breakLine(rest, linesize, quotelevel); return new Enumeration() { int count = 0; public boolean hasMoreElements() { return count < 1 || enumVar.hasMoreElements(); } public Object nextElement() { count++; if (count == 1) { return first; } else { return enumVar.nextElement(); } } }; } }
From source file:org.jahia.data.templates.JahiaTemplatesPackage.java
/** * Returns a class loader which is a chain of class loaders, starting from the Web application one, then this modules class loader and * at the end the list of class loaders of modules this module depends on. * * @return a class loader which is a chain of class loaders, starting from the Web application one, then this modules class loader and * at the end the list of class loaders of modules this module depends on *//*from w ww. j a va 2 s . c o m*/ public ClassLoader getChainedClassLoader() { if (chainedClassLoader != null) { return chainedClassLoader; } final List<ClassLoader> classLoaders = new ArrayList<ClassLoader>(); classLoaders.add(Jahia.class.getClassLoader()); final ClassLoader classLoader = getClassLoader(); if (classLoader != null) { classLoaders.add(classLoader); } for (JahiaTemplatesPackage dependentPack : getDependencies()) { if (dependentPack != null && dependentPack.getClassLoader() != null) { classLoaders.add(dependentPack.getClassLoader()); } } chainedClassLoader = new ClassLoader() { @Override public URL getResource(String name) { URL url = null; for (ClassLoader loader : classLoaders) { url = loader.getResource(name); if (url != null) return url; } return url; } @Override public Enumeration<URL> getResources(String name) throws IOException { final List<Enumeration<URL>> urlsEnums = new ArrayList<Enumeration<URL>>(); for (ClassLoader loader : classLoaders) { Enumeration<URL> urls = loader.getResources(name); if (urls != null && urls.hasMoreElements()) { // we only add enumerations that have elements, make things simpler urlsEnums.add(urls); } } if (urlsEnums.size() == 0) { return java.util.Collections.emptyEnumeration(); } return new Enumeration<URL>() { int i = 0; Enumeration<URL> currentEnum = urlsEnums.get(i); @Override public boolean hasMoreElements() { if (currentEnum.hasMoreElements()) { return true; } int j = i; do { j++; } while (j < (urlsEnums.size() - 1) && !urlsEnums.get(j).hasMoreElements()); if (j <= (urlsEnums.size() - 1)) { return urlsEnums.get(j).hasMoreElements(); } else { return false; } } @Override public URL nextElement() { if (currentEnum.hasMoreElements()) { return currentEnum.nextElement(); } do { i++; currentEnum = urlsEnums.get(i); } while (!currentEnum.hasMoreElements() && i < (urlsEnums.size() - 1)); if (currentEnum.hasMoreElements()) { return currentEnum.nextElement(); } else { throw new NoSuchElementException(); } } }; } @Override protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { for (ClassLoader classLoader : classLoaders) { try { Class<?> clazz = classLoader.loadClass(name); if (resolve) { resolveClass(clazz); } return clazz; } catch (ClassNotFoundException e) { // keep moving through the classloaders } } throw new ClassNotFoundException(name); } }; return chainedClassLoader; }
From source file:com.android.tools.idea.sdk.remote.internal.archives.ArchiveInstaller.java
/** * Generates a source.properties in the destination folder that contains all the infos * relevant to this archive, this package and the source so that we can reload them * locally later.//from w ww . j a v a 2 s . c o m */ @VisibleForTesting(visibility = Visibility.PRIVATE) protected boolean generateSourceProperties(Archive archive, File unzipDestFolder) { // Create a version of Properties that returns a sorted key set. // This is used by Properties#saveProperties and should ensure the // properties are in a stable order. Unit tests rely on this fact. @SuppressWarnings("serial") Properties props = new Properties() { @Override public synchronized Enumeration<Object> keys() { Set<Object> sortedSet = new TreeSet<Object>(keySet()); final Iterator<Object> it = sortedSet.iterator(); return new Enumeration<Object>() { @Override public boolean hasMoreElements() { return it.hasNext(); } @Override public Object nextElement() { return it.next(); } }; } }; archive.saveProperties(props); RemotePkgInfo pkg = archive.getParentPackage(); if (pkg != null) { pkg.saveProperties(props); } try { mFileOp.saveProperties(new File(unzipDestFolder, SdkConstants.FN_SOURCE_PROP), props, "## Android Tool: Source of this archive."); //$NON-NLS-1$ return true; } catch (IOException ignore) { return false; } }
From source file:com.android.sdklib.internal.repository.archives.ArchiveInstaller.java
/** * Generates a source.properties in the destination folder that contains all the infos * relevant to this archive, this package and the source so that we can reload them * locally later./*from w w w. j a va2s.c o m*/ */ @VisibleForTesting(visibility = Visibility.PRIVATE) protected boolean generateSourceProperties(Archive archive, File unzipDestFolder) { // Create a version of Properties that returns a sorted key set. // This is used by Properties#saveProperties and should ensure the // properties are in a stable order. Unit tests rely on this fact. @SuppressWarnings("serial") Properties props = new Properties() { @Override public synchronized Enumeration<Object> keys() { Set<Object> sortedSet = new TreeSet<Object>(keySet()); final Iterator<Object> it = sortedSet.iterator(); return new Enumeration<Object>() { @Override public boolean hasMoreElements() { return it.hasNext(); } @Override public Object nextElement() { return it.next(); } }; } }; archive.saveProperties(props); Package pkg = archive.getParentPackage(); if (pkg != null) { pkg.saveProperties(props); } try { mFileOp.saveProperties(new File(unzipDestFolder, SdkConstants.FN_SOURCE_PROP), props, "## Android Tool: Source of this archive."); //$NON-NLS-1$ return true; } catch (IOException ignore) { return false; } }
From source file:org.allcolor.yahp.converter.CClassLoader.java
public final Enumeration findResources(final String name) throws IOException { final CClassLoader loader = CClassLoader.getRootLoader(); final List URLList = new ArrayList(); try {/*from w ww. ja v a 2 s. c o m*/ CClassLoader.loadResources(loader, URLList, name); } finally { try { } catch (final Exception ignore) { } } try { final Enumeration eu = CClassLoader.getRootLoader().getParent().getResources(name); while (eu.hasMoreElements()) { URLList.add(eu.nextElement()); } } catch (final Throwable ignore) { } final Iterator it = URLList.iterator(); return new Enumeration() { Iterator internalIt = it; public boolean hasMoreElements() { return this.internalIt.hasNext(); } // end hasMoreElements() public Object nextElement() { return this.internalIt.next(); } // end nextElement() } // end new ; }