Search in sources :

Example 91 with Enumeration

use of java.util.Enumeration in project carat by amplab.

the class NanoHTTPD method serve.

// ==================================================
// API parts
// ==================================================
/**
	 * Override this to customize the server.<p>
	 *
	 * (By default, this delegates to serveFile() and allows directory listing.)
	 *
	 * @param uri	Percent-decoded URI without parameters, for example "/index.cgi"
	 * @param method	"GET", "POST" etc.
	 * @param parms	Parsed, percent decoded parameters from URI and, in case of POST, data.
	 * @param header	Header entries, percent decoded
	 * @return HTTP response, see class Response for details
	 */
public Response serve(String uri, String method, Properties header, Properties parms, Properties files) {
    myOut.println(method + " '" + uri + "' ");
    Enumeration e = header.propertyNames();
    while (e.hasMoreElements()) {
        String value = (String) e.nextElement();
        myOut.println("  HDR: '" + value + "' = '" + header.getProperty(value) + "'");
    }
    e = parms.propertyNames();
    while (e.hasMoreElements()) {
        String value = (String) e.nextElement();
        myOut.println("  PRM: '" + value + "' = '" + parms.getProperty(value) + "'");
    }
    e = files.propertyNames();
    while (e.hasMoreElements()) {
        String value = (String) e.nextElement();
        myOut.println("  UPLOADED: '" + value + "' = '" + files.getProperty(value) + "'");
    }
    return serveFile(uri, header, myRootDir, true);
}
Also used : Enumeration(java.util.Enumeration)

Example 92 with Enumeration

use of java.util.Enumeration in project otter by alibaba.

the class ArchiveBean method unpack.

public List<File> unpack(File archiveFile, File targetDir) throws ArchiveException {
    // 首先判断下对应的目标文件是否存在,如存在则执行删除
    if (false == archiveFile.exists()) {
        throw new ArchiveException(String.format("[%s] not exist", archiveFile.getAbsolutePath()));
    }
    if (false == targetDir.exists() && false == NioUtils.create(targetDir, false, 3)) {
        throw new ArchiveException(String.format("[%s] not exist and create failed", targetDir.getAbsolutePath()));
    }
    List<File> result = new ArrayList<File>();
    ZipFile zipFile = null;
    try {
        zipFile = new ZipFile(archiveFile);
        Enumeration entries = zipFile.entries();
        while (entries.hasMoreElements()) {
            // entry
            ZipEntry entry = (ZipEntry) entries.nextElement();
            String entryName = entry.getName();
            // target
            File targetFile = new File(targetDir, entryName);
            // 尝试创建父路径
            NioUtils.create(targetFile.getParentFile(), false, 3);
            InputStream input = null;
            OutputStream output = null;
            try {
                output = new FileOutputStream(targetFile);
                input = zipFile.getInputStream(entry);
                NioUtils.copy(input, output);
            } finally {
                IOUtils.closeQuietly(input);
                IOUtils.closeQuietly(output);
            }
            result.add(targetFile);
        }
    } catch (Exception e) {
        throw new ArchiveException(e);
    } finally {
        if (zipFile != null) {
            try {
                zipFile.close();
            } catch (IOException ex) {
            }
        }
    }
    return result;
}
Also used : Enumeration(java.util.Enumeration) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ZipEntry(de.schlichtherle.util.zip.ZipEntry) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) ZipOutputStream(de.schlichtherle.util.zip.ZipOutputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ExecutionException(java.util.concurrent.ExecutionException) ZipFile(de.schlichtherle.util.zip.ZipFile) FileOutputStream(java.io.FileOutputStream) ZipFile(de.schlichtherle.util.zip.ZipFile) File(java.io.File)

Example 93 with Enumeration

use of java.util.Enumeration in project groovy by apache.

the class SecurityTestSupport method executeTest.

protected void executeTest(Class test, Permission missingPermission) {
    TestSuite suite = new TestSuite();
    suite.addTestSuite(test);
    TestResult result = new TestResult();
    suite.run(result);
    if (result.wasSuccessful()) {
        if (missingPermission == null) {
            return;
        } else {
            fail("Security test expected an AccessControlException on " + missingPermission + ", but did not receive one");
        }
    } else {
        if (missingPermission == null) {
            new SecurityTestResultPrinter(System.out).print(result);
            fail("Security test was expected to run successfully, but failed (results on System.out)");
        } else {
            //There may be more than 1 failure:  iterate to ensure that they all match the missingPermission.
            boolean otherFailure = false;
            for (Enumeration e = result.errors(); e.hasMoreElements(); ) {
                TestFailure failure = (TestFailure) e.nextElement();
                if (failure.thrownException() instanceof AccessControlException) {
                    AccessControlException ace = (AccessControlException) failure.thrownException();
                    if (missingPermission.implies(ace.getPermission())) {
                        continue;
                    }
                }
                otherFailure = true;
                break;
            }
            if (otherFailure) {
                new SecurityTestResultPrinter(System.out).print(result);
                fail("Security test expected an AccessControlException on " + missingPermission + ", but failed for other reasons (results on System.out)");
            }
        }
    }
}
Also used : Enumeration(java.util.Enumeration) TestSuite(junit.framework.TestSuite) TestFailure(junit.framework.TestFailure) TestResult(junit.framework.TestResult)

Example 94 with Enumeration

use of java.util.Enumeration in project groovy by apache.

the class Groovyc method extractJointOptions.

private List<String> extractJointOptions(Path classpath) {
    List<String> jointOptions = new ArrayList<String>();
    if (!jointCompilation)
        return jointOptions;
    // extract joint options, some get pushed up...
    RuntimeConfigurable rc = javac.getRuntimeConfigurableWrapper();
    for (Object o1 : rc.getAttributeMap().entrySet()) {
        final Map.Entry e = (Map.Entry) o1;
        final String key = e.getKey().toString();
        final String value = getProject().replaceProperties(e.getValue().toString());
        if (key.contains("debug")) {
            String level = "";
            if (javac.getDebugLevel() != null) {
                level = ":" + javac.getDebugLevel();
            }
            jointOptions.add("-Fg" + level);
        } else if (key.contains("debugLevel")) {
        // ignore, taken care of in debug
        } else if ((key.contains("nowarn")) || (key.contains("verbose")) || (key.contains("deprecation"))) {
            // false is default, so something to do only in true case
            if ("on".equalsIgnoreCase(value) || "true".equalsIgnoreCase(value) || "yes".equalsIgnoreCase(value))
                jointOptions.add("-F" + key);
        } else if (key.contains("classpath")) {
            classpath.add(javac.getClasspath());
        } else if ((key.contains("depend")) || (key.contains("extdirs")) || (key.contains("encoding")) || (key.contains("source")) || (key.contains("target")) || (key.contains("verbose"))) {
            // already handling verbose but pass on too
            jointOptions.add("-J" + key + "=" + value);
        } else {
            log.warn("The option " + key + " cannot be set on the contained <javac> element. The option will be ignored");
        }
    // TODO includes? excludes?
    }
    // ant's <javac> supports nested <compilerarg value=""> elements (there can be multiple of them)
    // for additional options to be passed to javac.
    Enumeration children = rc.getChildren();
    while (children.hasMoreElements()) {
        RuntimeConfigurable childrc = (RuntimeConfigurable) children.nextElement();
        if (childrc.getElementTag().equals("compilerarg")) {
            for (Object o : childrc.getAttributeMap().entrySet()) {
                final Map.Entry e = (Map.Entry) o;
                final String key = e.getKey().toString();
                if (key.equals("value")) {
                    final String value = getProject().replaceProperties(e.getValue().toString());
                    StringTokenizer st = new StringTokenizer(value, " ");
                    while (st.hasMoreTokens()) {
                        String optionStr = st.nextToken();
                        String replaced = optionStr.replace("-X", "-FX");
                        if (optionStr.equals(replaced)) {
                            // GROOVY-5063
                            replaced = optionStr.replace("-W", "-FW");
                        }
                        jointOptions.add(replaced);
                    }
                }
            }
        }
    }
    return jointOptions;
}
Also used : StringTokenizer(java.util.StringTokenizer) Enumeration(java.util.Enumeration) RuntimeConfigurable(org.apache.tools.ant.RuntimeConfigurable) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 95 with Enumeration

use of java.util.Enumeration in project robovm by robovm.

the class LogFactory method releaseAll.

/**
     * Release any internal references to previously created {@link LogFactory}
     * instances, after calling the instance method <code>release()</code> on
     * each of them.  This is useful in environments like servlet containers,
     * which implement application reloading by throwing away a ClassLoader.
     * Dangling references to objects in that class loader would prevent
     * garbage collection.
     */
public static void releaseAll() {
    if (isDiagnosticsEnabled()) {
        logDiagnostic("Releasing factory for all classloaders.");
    }
    synchronized (factories) {
        Enumeration elements = factories.elements();
        while (elements.hasMoreElements()) {
            LogFactory element = (LogFactory) elements.nextElement();
            element.release();
        }
        factories.clear();
        if (nullClassLoaderFactory != null) {
            nullClassLoaderFactory.release();
            nullClassLoaderFactory = null;
        }
    }
}
Also used : Enumeration(java.util.Enumeration)

Aggregations

Enumeration (java.util.Enumeration)1418 IOException (java.io.IOException)247 ArrayList (java.util.ArrayList)183 File (java.io.File)122 Vector (java.util.Vector)98 Properties (java.util.Properties)97 HashMap (java.util.HashMap)96 List (java.util.List)89 URL (java.net.URL)74 HashSet (java.util.HashSet)71 Map (java.util.Map)71 Hashtable (java.util.Hashtable)70 Iterator (java.util.Iterator)70 Set (java.util.Set)67 InputStream (java.io.InputStream)62 ZipEntry (java.util.zip.ZipEntry)62 ServletContext (javax.servlet.ServletContext)55 ZipFile (java.util.zip.ZipFile)51 FileInputStream (java.io.FileInputStream)48 ServletException (javax.servlet.ServletException)46