Search in sources :

Example 1 with Enumeration

use of java.util.Enumeration in project vert.x by eclipse.

the class StarterTest method clearProperties.

private void clearProperties() {
    Set<String> toClear = new HashSet<>();
    Enumeration e = System.getProperties().propertyNames();
    // Uhh, properties suck
    while (e.hasMoreElements()) {
        String propName = (String) e.nextElement();
        if (propName.startsWith("vertx.options")) {
            toClear.add(propName);
        }
    }
    for (String propName : toClear) {
        System.clearProperty(propName);
    }
}
Also used : Enumeration(java.util.Enumeration) HashSet(java.util.HashSet)

Example 2 with Enumeration

use of java.util.Enumeration in project jetty.project by eclipse.

the class AnnotationParser method parse.

protected void parse(Set<? extends Handler> handlers, Bundle bundle) throws Exception {
    URI uri = _bundleToUri.get(bundle);
    if (!_alreadyParsed.add(uri)) {
        return;
    }
    String bundleClasspath = (String) bundle.getHeaders().get(Constants.BUNDLE_CLASSPATH);
    if (bundleClasspath == null) {
        bundleClasspath = ".";
    }
    //order the paths first by the number of tokens in the path second alphabetically.
    TreeSet<String> paths = new TreeSet<String>(new Comparator<String>() {

        public int compare(String o1, String o2) {
            int paths1 = new StringTokenizer(o1, "/", false).countTokens();
            int paths2 = new StringTokenizer(o2, "/", false).countTokens();
            if (paths1 == paths2) {
                return o1.compareTo(o2);
            }
            return paths2 - paths1;
        }
    });
    boolean hasDotPath = false;
    StringTokenizer tokenizer = new StringTokenizer(bundleClasspath, ",;", false);
    while (tokenizer.hasMoreTokens()) {
        String token = tokenizer.nextToken().trim();
        if (!token.startsWith("/")) {
            token = "/" + token;
        }
        if (token.equals("/.")) {
            hasDotPath = true;
        } else if (!token.endsWith(".jar") && !token.endsWith("/")) {
            paths.add(token + "/");
        } else {
            paths.add(token);
        }
    }
    //however it makes our life so much easier during development.
    if (bundle.getEntry("/.classpath") != null) {
        if (bundle.getEntry("/bin/") != null) {
            paths.add("/bin/");
        } else if (bundle.getEntry("/target/classes/") != null) {
            paths.add("/target/classes/");
        }
    }
    Enumeration classes = bundle.findEntries("/", "*.class", true);
    if (classes == null) {
        return;
    }
    while (classes.hasMoreElements()) {
        URL classUrl = (URL) classes.nextElement();
        String path = classUrl.getPath();
        //remove the longest path possible:
        String name = null;
        for (String prefixPath : paths) {
            if (path.startsWith(prefixPath)) {
                name = path.substring(prefixPath.length());
                break;
            }
        }
        if (name == null && hasDotPath) {
            //remove the starting '/'
            name = path.substring(1);
        }
        if (name == null) {
            //or the bundle classpath wasn't simply ".", so skip it
            continue;
        }
        //transform into a classname to pass to the resolver
        String shortName = name.replace('/', '.').substring(0, name.length() - 6);
        if (!isParsed(shortName)) {
            try (InputStream classInputStream = classUrl.openStream()) {
                scanClass(handlers, getResource(bundle), classInputStream);
            }
        }
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) Enumeration(java.util.Enumeration) TreeSet(java.util.TreeSet) InputStream(java.io.InputStream) URI(java.net.URI) URL(java.net.URL)

Example 3 with Enumeration

use of java.util.Enumeration in project jetty.project by eclipse.

the class MailSessionReference method getObjectInstance.

/**
     * Create a javax.mail.Session instance based on the information passed in the Reference
     * @see javax.naming.spi.ObjectFactory#getObjectInstance(java.lang.Object, javax.naming.Name, javax.naming.Context, java.util.Hashtable)
     * @param ref the Reference
     * @param arg1 not used
     * @param arg2 not used
     * @param arg3 not used
     * @return the object found
     * @throws Exception if unable to get object instance
     */
public Object getObjectInstance(Object ref, Name arg1, Context arg2, Hashtable arg3) throws Exception {
    if (ref == null)
        return null;
    Reference reference = (Reference) ref;
    Properties props = new Properties();
    String user = null;
    String password = null;
    Enumeration refs = reference.getAll();
    while (refs.hasMoreElements()) {
        RefAddr refAddr = (RefAddr) refs.nextElement();
        String name = refAddr.getType();
        String value = (String) refAddr.getContent();
        if (name.equalsIgnoreCase("user"))
            user = value;
        else if (name.equalsIgnoreCase("pwd"))
            password = value;
        else
            props.put(name, value);
    }
    if (password == null)
        return Session.getInstance(props);
    else
        return Session.getInstance(props, new PasswordAuthenticator(user, password));
}
Also used : RefAddr(javax.naming.RefAddr) StringRefAddr(javax.naming.StringRefAddr) Enumeration(java.util.Enumeration) Reference(javax.naming.Reference) Properties(java.util.Properties)

Example 4 with Enumeration

use of java.util.Enumeration in project jetty.project by eclipse.

the class HttpMethodsServlet method doTrace.

/**
     * @see HttpServlet#doTrace(HttpServletRequest, HttpServletResponse)
     */
protected void doTrace(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.addHeader("Content-Type", "message/http");
    StringBuffer msg = new StringBuffer();
    msg.append(request.getMethod()).append(' ');
    msg.append(request.getRequestURI()).append(' ');
    msg.append(request.getProtocol()).append("\n");
    // Now the headers
    Enumeration enNames = request.getHeaderNames();
    while (enNames.hasMoreElements()) {
        String name = (String) enNames.nextElement();
        Enumeration enValues = request.getHeaders(name);
        while (enValues.hasMoreElements()) {
            String value = (String) enValues.nextElement();
            msg.append(name).append(": ").append(value).append("\n");
        }
    }
    msg.append("\n");
    response.getWriter().print(msg.toString());
}
Also used : Enumeration(java.util.Enumeration)

Example 5 with Enumeration

use of java.util.Enumeration in project che by eclipse.

the class Util method getJdkLevel.

/**
     * Get the jdk level of this root.
     * The value can be:
     * <ul>
     * <li>major<<16 + minor : see predefined constants on ClassFileConstants </li>
     * <li><code>0</null> if the root is a source package fragment root or if a Java model exception occured</li>
     * </ul>
     * Returns the jdk level
     */
public static long getJdkLevel(Object targetLibrary) {
    try {
        ClassFileReader reader = null;
        if (targetLibrary instanceof IFolder) {
            // only internal classfolders are allowed
            IFile classFile = findFirstClassFile((IFolder) targetLibrary);
            if (classFile != null)
                reader = Util.newClassFileReader(classFile);
        } else {
            // root is a jar file or a zip file
            ZipFile jar = null;
            try {
                IPath path = null;
                if (targetLibrary instanceof IResource) {
                    path = ((IResource) targetLibrary).getFullPath();
                } else if (targetLibrary instanceof File) {
                    File f = (File) targetLibrary;
                    if (!f.isDirectory()) {
                        path = new Path(((File) targetLibrary).getPath());
                    }
                }
                if (path != null) {
                    jar = JavaModelManager.getJavaModelManager().getZipFile(path);
                    for (Enumeration e = jar.entries(); e.hasMoreElements(); ) {
                        ZipEntry member = (ZipEntry) e.nextElement();
                        String entryName = member.getName();
                        if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(entryName)) {
                            reader = ClassFileReader.read(jar, entryName);
                            break;
                        }
                    }
                }
            } catch (CoreException e) {
            // ignore
            } finally {
                JavaModelManager.getJavaModelManager().closeZipFile(jar);
            }
        }
        if (reader != null) {
            return reader.getVersion();
        }
    } catch (CoreException e) {
    // ignore
    } catch (ClassFormatException e) {
    // ignore
    } catch (IOException e) {
    // ignore
    }
    return 0;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) Enumeration(java.util.Enumeration) IPath(org.eclipse.core.runtime.IPath) IClassFileReader(org.eclipse.jdt.core.util.IClassFileReader) ClassFileReader(org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) ClassFormatException(org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException) ZipFile(java.util.zip.ZipFile) CoreException(org.eclipse.core.runtime.CoreException) IClassFile(org.eclipse.jdt.core.IClassFile) ClassFile(org.eclipse.jdt.internal.core.ClassFile) ZipFile(java.util.zip.ZipFile) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

Enumeration (java.util.Enumeration)2605 IOException (java.io.IOException)439 ArrayList (java.util.ArrayList)305 File (java.io.File)231 Properties (java.util.Properties)210 HashMap (java.util.HashMap)195 Vector (java.util.Vector)171 List (java.util.List)159 Map (java.util.Map)146 URL (java.net.URL)144 ZipEntry (java.util.zip.ZipEntry)132 Hashtable (java.util.Hashtable)123 InputStream (java.io.InputStream)120 HashSet (java.util.HashSet)118 Iterator (java.util.Iterator)116 ZipFile (java.util.zip.ZipFile)108 FileInputStream (java.io.FileInputStream)91 Set (java.util.Set)90 Test (org.junit.Test)89 JarFile (java.util.jar.JarFile)72