use of java.net.MalformedURLException in project checkstyle by checkstyle.
the class CommonUtils method getUriByFilename.
/**
* Resolve the specified filename to a URI.
* @param filename name os the file
* @return resolved header file URI
* @throws CheckstyleException on failure
*/
public static URI getUriByFilename(String filename) throws CheckstyleException {
// figure out if this is a File or a URL
URI uri;
try {
final URL url = new URL(filename);
uri = url.toURI();
} catch (final URISyntaxException | MalformedURLException ignored) {
uri = null;
}
if (uri == null) {
final File file = new File(filename);
if (file.exists()) {
uri = file.toURI();
} else {
// check to see if the file is in the classpath
try {
final URL configUrl = CommonUtils.class.getResource(filename);
if (configUrl == null) {
throw new CheckstyleException(UNABLE_TO_FIND_EXCEPTION_PREFIX + filename);
}
uri = configUrl.toURI();
} catch (final URISyntaxException ex) {
throw new CheckstyleException(UNABLE_TO_FIND_EXCEPTION_PREFIX + filename, ex);
}
}
}
return uri;
}
use of java.net.MalformedURLException in project Java-Mandrill-Wrapper by cribbstechnologies.
the class MandrillRESTRequestTest method testPostRequest.
@Test
public void testPostRequest() throws ClientProtocolException, IOException {
this.request = new MandrillRESTRequest();
this.request.setHttpClient(this.client);
this.request.setConfig(this.config);
this.request.setObjectMapper(new ObjectMapper());
doThrow(new MalformedURLException("Mockito!")).when(this.client).execute(isA(HttpPost.class));
try {
this.request.postRequest(this.emptyBaseRequest, "test", null);
fail("Exception not thrown");
} catch (RequestFailedException e) {
assertEquals("Malformed url", e.getMessage());
}
doThrow(new IOException("Mockito!")).when(this.client).execute(isA(HttpPost.class));
try {
this.request.postRequest(this.emptyBaseRequest, "test", null);
fail("Exception not thrown");
} catch (RequestFailedException e) {
assertEquals("IOException", e.getMessage());
}
}
use of java.net.MalformedURLException in project UltimateAndroid by cymcsg.
the class ImageUtils_Deprecated method returnBitMap.
public static Bitmap returnBitMap(String url) {
URL myFileUrl = null;
Bitmap bitmap = null;
try {
myFileUrl = new URL(url);
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
HttpURLConnection conn = (HttpURLConnection) myFileUrl.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
bitmap = BitmapFactory.decodeStream(is);
is.close();
} catch (IOException e) {
e.printStackTrace();
}
return bitmap;
}
use of java.net.MalformedURLException in project SimplifyReader by chentao0707.
the class AsyncImageLoader method loadImageFromUrl.
private InputStream loadImageFromUrl(String url) {
try {
URL u = new URL(url);
HttpURLConnection c = (HttpURLConnection) u.openConnection();
c.setDoInput(true);
c.connect();
return (InputStream) c.getInputStream();
} catch (MalformedURLException e) {
Logger.e(TAG, "loadImageFromUrl", e);
} catch (IOException e) {
Logger.e(TAG, "loadImageFromUrl", e);
}
return null;
}
use of java.net.MalformedURLException in project druid by druid-io.
the class LookupCoordinatorManager method deleteAllOnTier.
void deleteAllOnTier(final String tier, final Collection<String> dropLookups) throws ExecutionException, InterruptedException, IOException {
if (dropLookups.isEmpty()) {
LOG.debug("Nothing to drop");
return;
}
final Collection<URL> urls = getAllHostsAnnounceEndpoint(tier);
final List<ListenableFuture<?>> futures = new ArrayList<>(urls.size());
for (final URL url : urls) {
futures.add(executorService.submit(new Runnable() {
@Override
public void run() {
for (final String drop : dropLookups) {
final URL lookupURL;
try {
lookupURL = new URL(url.getProtocol(), url.getHost(), url.getPort(), String.format("%s/%s", url.getFile(), drop));
} catch (MalformedURLException e) {
throw new ISE(e, "Error creating url for [%s]/[%s]", url, drop);
}
try {
deleteOnHost(lookupURL);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
LOG.warn("Delete [%s] interrupted", lookupURL);
throw Throwables.propagate(e);
} catch (IOException | ExecutionException e) {
// Don't raise as ExecutionException. Just log and continue
LOG.makeAlert(e, "Error deleting [%s]", lookupURL).emit();
}
}
}
}));
}
final ListenableFuture allFuture = Futures.allAsList(futures);
try {
allFuture.get(lookupCoordinatorManagerConfig.getUpdateAllTimeout().getMillis(), TimeUnit.MILLISECONDS);
} catch (TimeoutException e) {
// This should cause Interrupted exceptions on the offending ones
allFuture.cancel(true);
throw new ExecutionException("Timeout in updating hosts! Attempting to cancel", e);
}
}
Aggregations