Search in sources :

Example 61 with URISyntaxException

use of java.net.URISyntaxException in project blade by biezhi.

the class AbstractClassReader method getClassByAnnotation.

@Override
public Set<ClassInfo> getClassByAnnotation(String packageName, Class<?> parent, Class<? extends Annotation> annotation, boolean recursive) {
    Assert.notBlank(packageName);
    Set<ClassInfo> classes = CollectionKit.newHashSet();
    // 获取包的名字 并进行替换
    String packageDirName = packageName.replace('.', '/');
    // 定义一个枚举的集合 并进行循环来处理这个目录下的URL
    Enumeration<URL> dirs;
    try {
        dirs = this.getClass().getClassLoader().getResources(packageDirName);
        // 循环迭代下去
        while (dirs.hasMoreElements()) {
            // 获取下一个元素
            URL url = dirs.nextElement();
            try {
                // 获取包的物理路径
                String filePath = new URI(url.getFile()).getPath();
                Set<ClassInfo> subClasses = findClassByPackage(packageName, filePath, parent, annotation, recursive, classes);
                if (subClasses.size() > 0) {
                    classes.addAll(subClasses);
                }
            } catch (URISyntaxException e) {
                LOGGER.error(e.getMessage(), e);
            }
        }
    } catch (IOException e) {
        LOGGER.error(e.getMessage(), e);
    } catch (ClassNotFoundException e) {
        LOGGER.error("Add user custom view class error Can't find such Class files.");
        throw new ClassReaderException(e);
    }
    return classes;
}
Also used : URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI) URL(java.net.URL) ClassReaderException(com.blade.kit.exception.ClassReaderException)

Example 62 with URISyntaxException

use of java.net.URISyntaxException in project ADWLauncher2 by boombuler.

the class AppDB method RemoveShortcutsFromWorkspace.

private void RemoveShortcutsFromWorkspace(List<DBInfo> infos) {
    final ContentResolver cr = mContext.getContentResolver();
    Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI, new String[] { LauncherSettings.Favorites._ID, LauncherSettings.Favorites.INTENT }, LauncherSettings.Favorites.INTENT + " is not null", null, null);
    long[] ids = null;
    try {
        if (c != null && c.moveToFirst()) {
            // prepare the dirty work!
            ids = new long[c.getCount()];
            int IDColumnIndex = c.getColumnIndex(LauncherSettings.Favorites._ID);
            int IntentColumnIndex = c.getColumnIndex(LauncherSettings.Favorites.INTENT);
            int idx = 0;
            while (!c.isAfterLast()) {
                String intentStr = c.getString(IntentColumnIndex);
                try {
                    Intent intent = Intent.parseUri(intentStr, 0);
                    if (intent != null) {
                        ComponentName cname = intent.getComponent();
                        if (cname != null) {
                            String cnameStr = cname.flattenToString();
                            if (InfosContains(infos, cnameStr)) {
                                c.getLong(IDColumnIndex);
                                ids[idx++] = c.getLong(IDColumnIndex);
                            } else
                                ids[idx++] = INVALID_ID;
                        } else {
                            ids[idx++] = INVALID_ID;
                        }
                    } else
                        ids[idx++] = INVALID_ID;
                } catch (URISyntaxException expt) {
                    ids[idx++] = INVALID_ID;
                }
                c.moveToNext();
            }
        }
    } finally {
        c.close();
    }
    if (ids != null) {
        for (long id : ids) {
            if (id != INVALID_ID)
                cr.delete(LauncherSettings.Favorites.getContentUri(id, false), null, null);
        }
    }
}
Also used : Intent(android.content.Intent) ComponentName(android.content.ComponentName) URISyntaxException(java.net.URISyntaxException) Cursor(android.database.Cursor) ContentResolver(android.content.ContentResolver)

Example 63 with URISyntaxException

use of java.net.URISyntaxException in project musiccabinet by hakko.

the class AbstractMusicBrainzClient method getURI.

protected URI getURI(String path, List<NameValuePair> params) throws ApplicationException {
    URI uri = null;
    try {
        URIBuilder uriBuilder = new URIBuilder();
        uriBuilder.setScheme(HTTP);
        uriBuilder.setHost(HOST);
        uriBuilder.setPath(path);
        for (NameValuePair param : params) {
            uriBuilder.addParameter(param.getName(), param.getValue());
        }
        uri = uriBuilder.build();
    } catch (URISyntaxException e) {
        throw new ApplicationException("Could not create MusicBrainz URI!", e);
    }
    return uri;
}
Also used : NameValuePair(org.apache.http.NameValuePair) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 64 with URISyntaxException

use of java.net.URISyntaxException in project hazelcast by hazelcast.

the class HazelcastClientCachingProvider method getOrCreateInstance.

@Override
protected HazelcastInstance getOrCreateInstance(URI uri, ClassLoader classLoader, Properties properties) throws URISyntaxException, IOException {
    HazelcastInstance instanceItself = (HazelcastInstance) properties.get(HAZELCAST_INSTANCE_ITSELF);
    // if instance itself is specified via properties, get instance through it
    if (instanceItself != null) {
        return instanceItself;
    }
    String location = properties.getProperty(HAZELCAST_CONFIG_LOCATION);
    String instanceName = properties.getProperty(HAZELCAST_INSTANCE_NAME);
    // if config location is specified, get instance through it
    if (location != null) {
        ClientConfig config = getConfigFromLocation(location, classLoader, instanceName);
        return getOrCreateInstanceByConfig(config);
    }
    // If config location is specified, get instance with its name.
    if (instanceName != null) {
        return HazelcastClient.getHazelcastClientByName(instanceName);
    }
    final boolean isDefaultURI = (uri == null || uri.equals(getDefaultURI()));
    if (!isDefaultURI) {
        try {
            // try locating a Hazelcast config at CacheManager URI
            ClientConfig config = getConfigFromLocation(uri, classLoader, null);
            return getOrCreateInstanceByConfig(config);
        } catch (Exception e) {
            if (LOGGER.isFinestEnabled()) {
                LOGGER.finest("Could not get or create hazelcast instance from URI " + uri.toString(), e);
            }
        }
        try {
            // try again, this time interpreting CacheManager URI as hazelcast instance name
            return HazelcastClient.getHazelcastClientByName(uri.toString());
        } catch (Exception e) {
            if (LOGGER.isFinestEnabled()) {
                LOGGER.finest("Could not get hazelcast instance from instance name " + uri.toString(), e);
            }
        }
        // could not locate hazelcast instance, return null and an exception will be thrown from invoker
        return null;
    } else {
        return getDefaultInstance();
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientConfig(com.hazelcast.client.config.ClientConfig) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 65 with URISyntaxException

use of java.net.URISyntaxException in project gradle by gradle.

the class ClasspathUtil method getClasspathForClass.

public static File getClasspathForClass(Class<?> targetClass) {
    URI location;
    try {
        CodeSource codeSource = targetClass.getProtectionDomain().getCodeSource();
        if (codeSource != null && codeSource.getLocation() != null) {
            location = toURI(codeSource.getLocation());
            if (location.getScheme().equals("file")) {
                return new File(location);
            }
        }
        if (targetClass.getClassLoader() != null) {
            String resourceName = targetClass.getName().replace('.', '/') + ".class";
            URL resource = targetClass.getClassLoader().getResource(resourceName);
            if (resource != null) {
                return getClasspathForResource(resource, resourceName);
            }
        }
        throw new GradleException(String.format("Cannot determine classpath for class %s.", targetClass.getName()));
    } catch (URISyntaxException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
Also used : GradleException(org.gradle.api.GradleException) URISyntaxException(java.net.URISyntaxException) CodeSource(java.security.CodeSource) URI(java.net.URI) File(java.io.File) URL(java.net.URL)

Aggregations

URISyntaxException (java.net.URISyntaxException)1633 URI (java.net.URI)1080 IOException (java.io.IOException)451 URL (java.net.URL)287 File (java.io.File)280 ArrayList (java.util.ArrayList)146 MalformedURLException (java.net.MalformedURLException)102 InputStream (java.io.InputStream)93 HashMap (java.util.HashMap)91 Test (org.testng.annotations.Test)88 Response (javax.ws.rs.core.Response)87 Builder (javax.ws.rs.client.Invocation.Builder)84 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)84 Parameters (org.testng.annotations.Parameters)84 BaseTest (org.xdi.oxauth.BaseTest)84 ResponseType (org.xdi.oxauth.model.common.ResponseType)84 AuthorizationRequest (org.xdi.oxauth.client.AuthorizationRequest)78 Test (org.junit.Test)75 REGISTRATION_CLIENT_URI (org.xdi.oxauth.model.register.RegisterResponseParam.REGISTRATION_CLIENT_URI)72 Intent (android.content.Intent)63