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;
}
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);
}
}
}
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;
}
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();
}
}
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);
}
}
Aggregations