Search in sources :

Example 26 with MalformedURLException

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;
}
Also used : MalformedURLException(java.net.MalformedURLException) CheckstyleException(com.puppycrawl.tools.checkstyle.api.CheckstyleException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) File(java.io.File) URL(java.net.URL)

Example 27 with MalformedURLException

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());
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) MalformedURLException(java.net.MalformedURLException) RequestFailedException(com.cribbstechnologies.clients.mandrill.exception.RequestFailedException) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 28 with MalformedURLException

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;
}
Also used : MalformedURLException(java.net.MalformedURLException) HttpURLConnection(java.net.HttpURLConnection) URL(java.net.URL)

Example 29 with MalformedURLException

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;
}
Also used : MalformedURLException(java.net.MalformedURLException) HttpURLConnection(java.net.HttpURLConnection) InputStream(java.io.InputStream) IOException(java.io.IOException) URL(java.net.URL)

Example 30 with MalformedURLException

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);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URL(java.net.URL) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ISE(io.druid.java.util.common.ISE) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

MalformedURLException (java.net.MalformedURLException)1319 URL (java.net.URL)984 IOException (java.io.IOException)397 File (java.io.File)324 ArrayList (java.util.ArrayList)132 HttpURLConnection (java.net.HttpURLConnection)108 InputStream (java.io.InputStream)106 HashMap (java.util.HashMap)89 URISyntaxException (java.net.URISyntaxException)78 URI (java.net.URI)76 Map (java.util.Map)69 URLClassLoader (java.net.URLClassLoader)65 InputStreamReader (java.io.InputStreamReader)61 BufferedReader (java.io.BufferedReader)58 FileNotFoundException (java.io.FileNotFoundException)53 URLConnection (java.net.URLConnection)52 HashSet (java.util.HashSet)50 Test (org.junit.Test)45 JSONException (org.json.JSONException)38 FileInputStream (java.io.FileInputStream)33