Search in sources :

Example 46 with MalformedURLException

use of java.net.MalformedURLException in project android_frameworks_base by ParanoidAndroid.

the class FileFilter method loadTestExpectations.

public void loadTestExpectations() {
    URL url = null;
    try {
        url = new URL(ForwarderManager.getHostSchemePort(false) + "LayoutTests/" + TEST_EXPECTATIONS_TXT_PATH);
    } catch (MalformedURLException e) {
        assert false;
    }
    try {
        InputStream inputStream = null;
        BufferedReader bufferedReader = null;
        try {
            byte[] httpAnswer = FsUtils.readDataFromUrl(url);
            if (httpAnswer == null) {
                Log.w(LOG_TAG, "loadTestExpectations(): File not found: " + TEST_EXPECTATIONS_TXT_PATH);
                return;
            }
            bufferedReader = new BufferedReader(new StringReader(new String(httpAnswer)));
            String line;
            String entry;
            String[] parts;
            String path;
            Set<String> tokens;
            while (true) {
                line = bufferedReader.readLine();
                if (line == null) {
                    break;
                }
                /** Remove the comment and trim */
                entry = line.split("//", 2)[0].trim();
                /** Omit empty lines, advance to next line */
                if (entry.isEmpty()) {
                    continue;
                }
                /** Split on whitespace into path part and the rest */
                parts = entry.split("\\s", 2);
                /** At this point parts.length >= 1 */
                if (parts.length == 1) {
                    Log.w(LOG_TAG + "::reloadConfiguration", "There are no options specified for the test!");
                    continue;
                }
                path = trimTrailingSlashIfPresent(parts[0]);
                /** Split on whitespace */
                tokens = new HashSet<String>(Arrays.asList(parts[1].split("\\s", 0)));
                /** Chose the right collections to add to */
                if (tokens.contains(TOKEN_CRASH)) {
                    mCrashList.add(path);
                    /** If test is on skip list we ignore any further options */
                    continue;
                }
                if (tokens.contains(TOKEN_FAIL)) {
                    mFailList.add(path);
                }
                if (tokens.contains(TOKEN_SLOW)) {
                    mSlowList.add(path);
                }
            }
        } finally {
            if (inputStream != null) {
                inputStream.close();
            }
            if (bufferedReader != null) {
                bufferedReader.close();
            }
        }
    } catch (IOException e) {
        Log.e(LOG_TAG, "url=" + url, e);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) IOException(java.io.IOException) URL(java.net.URL)

Example 47 with MalformedURLException

use of java.net.MalformedURLException in project android_frameworks_base by ParanoidAndroid.

the class FsUtils method getLayoutTestsDirContents.

public static List<String> getLayoutTestsDirContents(String dirRelativePath, boolean recurse, boolean mode) {
    String modeString = (mode ? "folders" : "files");
    URL url = null;
    try {
        url = new URL(SCRIPT_URL + "?path=" + dirRelativePath + "&recurse=" + recurse + "&mode=" + modeString);
    } catch (MalformedURLException e) {
        Log.e(LOG_TAG, "path=" + dirRelativePath + " recurse=" + recurse + " mode=" + modeString, e);
        return new LinkedList<String>();
    }
    HttpGet httpRequest = new HttpGet(url.toString());
    ResponseHandler<LinkedList<String>> handler = new ResponseHandler<LinkedList<String>>() {

        @Override
        public LinkedList<String> handleResponse(HttpResponse response) throws IOException {
            LinkedList<String> lines = new LinkedList<String>();
            if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
                return lines;
            }
            HttpEntity entity = response.getEntity();
            if (entity == null) {
                return lines;
            }
            BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent()));
            String line;
            try {
                while ((line = reader.readLine()) != null) {
                    lines.add(line);
                }
            } finally {
                if (reader != null) {
                    reader.close();
                }
            }
            return lines;
        }
    };
    try {
        return getHttpClient().execute(httpRequest, handler);
    } catch (IOException e) {
        Log.e(LOG_TAG, "getLayoutTestsDirContents(): HTTP GET failed for URL " + url);
        return null;
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ResponseHandler(org.apache.http.client.ResponseHandler) HttpEntity(org.apache.http.HttpEntity) InputStreamReader(java.io.InputStreamReader) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) URL(java.net.URL) LinkedList(java.util.LinkedList) BufferedReader(java.io.BufferedReader)

Example 48 with MalformedURLException

use of java.net.MalformedURLException in project pinpoint by naver.

the class AgentDirBaseClassPathResolver method resolvePlugins.

@Override
public URL[] resolvePlugins() {
    final File file = new File(getAgentPluginPath());
    if (!file.exists()) {
        logger.warn(file + " not found");
        return new URL[0];
    }
    if (!file.isDirectory()) {
        logger.warn(file + " is not a directory");
        return new URL[0];
    }
    final File[] jars = file.listFiles(new FilenameFilter() {

        @Override
        public boolean accept(File dir, String name) {
            return name.endsWith(".jar");
        }
    });
    if (jars == null || jars.length == 0) {
        return new URL[0];
    }
    final URL[] urls = new URL[jars.length];
    for (int i = 0; i < jars.length; i++) {
        try {
            urls[i] = jars[i].toURI().toURL();
        } catch (MalformedURLException e) {
            // TODO have to change to PinpointException AFTER moving the exception to pinpoint-common
            throw new RuntimeException("Fail to load plugin jars", e);
        }
    }
    for (File pluginJar : jars) {
        logger.info("Found plugins: " + pluginJar.getPath());
    }
    return urls;
}
Also used : FilenameFilter(java.io.FilenameFilter) MalformedURLException(java.net.MalformedURLException) JarFile(java.util.jar.JarFile) File(java.io.File) URL(java.net.URL)

Example 49 with MalformedURLException

use of java.net.MalformedURLException in project neo4j by neo4j.

the class HotspotManagementSupport method createServer.

private JMXConnectorServer createServer(int port, boolean useSSL, Log log) {
    MBeanServer server = getMBeanServer();
    final JMXServiceURL url;
    try {
        url = new JMXServiceURL("rmi", null, port);
    } catch (MalformedURLException e) {
        log.warn("Failed to start JMX Server", e);
        return null;
    }
    Map<String, Object> env = new HashMap<>();
    if (useSSL) {
        env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, new SslRMIClientSocketFactory());
        env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, new SslRMIServerSocketFactory());
    }
    try {
        return JMXConnectorServerFactory.newJMXConnectorServer(url, env, server);
    } catch (IOException e) {
        log.warn("Failed to start JMX Server", e);
        return null;
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) SslRMIClientSocketFactory(javax.rmi.ssl.SslRMIClientSocketFactory) MalformedURLException(java.net.MalformedURLException) HashMap(java.util.HashMap) SslRMIServerSocketFactory(javax.rmi.ssl.SslRMIServerSocketFactory) IOException(java.io.IOException) MBeanServer(javax.management.MBeanServer)

Example 50 with MalformedURLException

use of java.net.MalformedURLException in project generator by mybatis.

the class ClassloaderUtility method getCustomClassloader.

public static ClassLoader getCustomClassloader(List<String> entries) {
    List<URL> urls = new ArrayList<URL>();
    File file;
    if (entries != null) {
        for (String classPathEntry : entries) {
            file = new File(classPathEntry);
            if (!file.exists()) {
                throw new RuntimeException(getString("RuntimeError.9", //$NON-NLS-1$
                classPathEntry));
            }
            try {
                urls.add(file.toURI().toURL());
            } catch (MalformedURLException e) {
                // this shouldn't happen, but just in case...
                throw new RuntimeException(getString("RuntimeError.9", //$NON-NLS-1$
                classPathEntry));
            }
        }
    }
    ClassLoader parent = Thread.currentThread().getContextClassLoader();
    URLClassLoader ucl = new URLClassLoader(urls.toArray(new URL[urls.size()]), parent);
    return ucl;
}
Also used : MalformedURLException(java.net.MalformedURLException) URLClassLoader(java.net.URLClassLoader) ArrayList(java.util.ArrayList) URLClassLoader(java.net.URLClassLoader) Messages.getString(org.mybatis.generator.internal.util.messages.Messages.getString) File(java.io.File) URL(java.net.URL)

Aggregations

MalformedURLException (java.net.MalformedURLException)3838 URL (java.net.URL)2885 IOException (java.io.IOException)1194 File (java.io.File)910 ArrayList (java.util.ArrayList)372 InputStream (java.io.InputStream)367 HttpURLConnection (java.net.HttpURLConnection)295 URISyntaxException (java.net.URISyntaxException)270 URI (java.net.URI)239 InputStreamReader (java.io.InputStreamReader)226 BufferedReader (java.io.BufferedReader)208 HashMap (java.util.HashMap)200 URLClassLoader (java.net.URLClassLoader)168 Map (java.util.Map)166 URLConnection (java.net.URLConnection)148 FileNotFoundException (java.io.FileNotFoundException)137 Matcher (java.util.regex.Matcher)132 Test (org.junit.Test)129 UnsupportedEncodingException (java.io.UnsupportedEncodingException)119 Pattern (java.util.regex.Pattern)113