Example usage for java.net URL toString

List of usage examples for java.net URL toString

Introduction

In this page you can find the example usage for java.net URL toString.

Prototype

public String toString() 

Source Link

Document

Constructs a string representation of this URL .

Usage

From source file:kontrol.HttpUtil.java

public static InputStream getUrlAsStream(URL url) throws IOException {
    return getUrlAsStream(URI.create(url.toString()), HTTP_TIMEOUT, Locale.US);
}

From source file:com.microsoft.azure.hdinsight.common.StreamUtil.java

public static File getResourceFile(String resource) throws IOException {
    File file = null;//from   ww  w  .j  av a  2s.  com
    URL res = streamUtil.getClass().getResource(resource);

    if (res.toString().startsWith("jar:")) {
        InputStream input = null;
        OutputStream out = null;

        try {
            input = streamUtil.getClass().getResourceAsStream(resource);
            file = File.createTempFile(String.valueOf(new Date().getTime()), ".tmp");
            out = new FileOutputStream(file);

            int read;
            byte[] bytes = new byte[1024];

            while ((read = input.read(bytes)) != -1) {
                out.write(bytes, 0, read);
            }
        } finally {
            if (input != null) {
                input.close();
            }

            if (out != null) {
                out.flush();
                out.close();
            }

            if (file != null) {
                file.deleteOnExit();
            }
        }

    } else {
        file = new File(res.getFile());
    }

    return file;
}

From source file:com.tc.admin.UpdateCheckRequestTest.java

public static String getResponseBody(URL url, HttpClient client) throws ConnectException, IOException {
    GetMethod get = new GetMethod(url.toString());

    get.setFollowRedirects(true);/*from  w  w  w.j  av a  2s .  c o m*/
    try {
        int status = client.executeMethod(get);
        if (status != HttpStatus.SC_OK) {
            throw new ConnectException(
                    "The http client has encountered a status code other than ok for the url: " + url
                            + " status: " + HttpStatus.getStatusText(status));
        }
        return get.getResponseBodyAsString();
    } finally {
        get.releaseConnection();
    }
}

From source file:kontrol.HttpUtil.java

public static InputStream getUrlAsStream(URL url, int timeout) throws IOException {
    return getUrlAsStream(URI.create(url.toString()), timeout, Locale.US);
}

From source file:kontrol.HttpUtil.java

public static String getUrlAsString(URL url, int timeout) throws IOException {
    return getUrlAsString(URI.create(url.toString()), timeout, Locale.US);
}

From source file:kontrol.HttpUtil.java

public static InputStream getUrlAsStream(URL url, Locale locale) throws IOException {
    return getUrlAsStream(URI.create(url.toString()), HTTP_TIMEOUT, locale);
}

From source file:kontrol.HttpUtil.java

public static String getUrlAsString(URL url, Locale locale) throws IOException {
    return getUrlAsString(URI.create(url.toString()), HTTP_TIMEOUT, locale);
}

From source file:com.comcast.viper.hlsparserj.PlaylistFactory.java

/**
 * Returns a playlist inputStream given an httpClient and a URL.
 * @param httpClient http client//  w w w .j  a v  a  2s.  c o  m
 * @param url URL to a playlist
 * @return inputStream
 * @throws IOException on HTTP connection exception
 */
private static InputStream getPlaylistInputStream(final CloseableHttpClient httpClient, final URL url)
        throws IOException {
    HttpGet get = new HttpGet(url.toString());
    CloseableHttpResponse response = null;
    response = httpClient.execute(get);
    if (response == null) {
        throw new IOException("Request returned a null response");
    }
    if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
        response.close();
        throw new IOException("Request returned a status code of " + response.getStatusLine().getStatusCode());
    }

    return response.getEntity().getContent();
}

From source file:de.l3s.boilerpipe.sax.HTMLFetcher.java

/**
 * Fetches the document at the given URL, using {@link URLConnection}.
 * /*from   www .  ja  v a2s.c o  m*/
 * @param url
 * @return the document at the given URL
 * @throws IOException
 */
public static HTMLDocument fetch(final URL url) throws IOException {
    return fetch(url.toString());
    //return fetchOk(url.toString());

    //return fetchHelper(url);

}

From source file:Main.java

protected static synchronized InputStream getAWebPage(URL url) throws ClientProtocolException, IOException {
    HttpClient httpClient = new DefaultHttpClient();
    HttpContext localContext = new BasicHttpContext();
    HttpGet httpGet = new HttpGet(url.toString());
    try {//w ww .jav a  2s.  co m
        //do the request
        HttpResponse response = httpClient.execute(httpGet, localContext);
        StatusLine status = response.getStatusLine();
        if (status.getStatusCode() != HTTP_STATUS_OK) {
            throw new IOException("Invalid response from the IKSU server! " + status.toString());
        }
        //InputStream ist = response.getEntity().getContent();

        return response.getEntity().getContent();
    } catch (Exception e) {
        e.printStackTrace();
        throw new ClientProtocolException("Protocol Exception! " + e.toString());
    }
}