java.net.URLConnection#getURL ( )源码实例Demo

下面列出了java.net.URLConnection#getURL ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: dragonwell8_jdk   文件: plain.java
/**
 * Returns one of several object types (this set may change in future
 * versions):
 * 1) instance of Thread:
 *    Invoke the thread to launch an external viewer.
 * 2) instance of InputStream:
 *    Bring up the "Save to disk" dialog page to allow the content
 *    to be saved to disk.
 * 3) instance of InputStreamImageSource:
 *    Load the image into HotJava in an image viewer page.
 * 4) instance of String:
 *    Go to a new page with the string as the plain text content
 *    of that page.
 */
public Object getContent(URLConnection uc) {
    try {
        InputStream is = uc.getInputStream();
        StringBuffer sb = new StringBuffer();
        int c;

        sb.append("[Content of " + uc.getURL() + "]\n\n");
        sb.append("[This opening message brought to you by your plain/text\n");
        sb.append("content handler. To remove this content handler, delete the\n");
        sb.append("COM.foo.content.text directory from your class path and\n");
        sb.append("the java.content.handler.pkgs property from your HotJava\n");
        sb.append("properties file.]\n");
        sb.append("----------------------------------------------------------------\n\n");

        // Read the characters from the source, accumulate them into the string buffer.
        // (Not the most efficient, but simplest for this example.)
        while ((c = is.read()) >= 0) {
            sb.append((char)c);
        }

        // Tidy up
        is.close();

        // Return the resulting string to our client (we're case 4 above)
        return sb.toString();
    } catch (IOException e) {
        // For any exception, just return an indication of what went wrong.
        return "Problem reading document: " + uc.getURL();
    }
}
 
源代码2 项目: HotswapAgent   文件: URLClassPath.java
/**
 * Returns the URL.
 *
 * @return null if the class file could not be obtained. 
 */
@Override
public URL find(String classname) {
    try {
        URLConnection con = openClassfile0(classname);
        InputStream is = con.getInputStream();
        if (is != null) {
            is.close();
            return con.getURL();
        }
    }
    catch (IOException e) {}
    return null; 
}
 
源代码3 项目: TencentKona-8   文件: plain.java
/**
 * Returns one of several object types (this set may change in future
 * versions):
 * 1) instance of Thread:
 *    Invoke the thread to launch an external viewer.
 * 2) instance of InputStream:
 *    Bring up the "Save to disk" dialog page to allow the content
 *    to be saved to disk.
 * 3) instance of InputStreamImageSource:
 *    Load the image into HotJava in an image viewer page.
 * 4) instance of String:
 *    Go to a new page with the string as the plain text content
 *    of that page.
 */
public Object getContent(URLConnection uc) {
    try {
        InputStream is = uc.getInputStream();
        StringBuffer sb = new StringBuffer();
        int c;

        sb.append("[Content of " + uc.getURL() + "]\n\n");
        sb.append("[This opening message brought to you by your plain/text\n");
        sb.append("content handler. To remove this content handler, delete the\n");
        sb.append("COM.foo.content.text directory from your class path and\n");
        sb.append("the java.content.handler.pkgs property from your HotJava\n");
        sb.append("properties file.]\n");
        sb.append("----------------------------------------------------------------\n\n");

        // Read the characters from the source, accumulate them into the string buffer.
        // (Not the most efficient, but simplest for this example.)
        while ((c = is.read()) >= 0) {
            sb.append((char)c);
        }

        // Tidy up
        is.close();

        // Return the resulting string to our client (we're case 4 above)
        return sb.toString();
    } catch (IOException e) {
        // For any exception, just return an indication of what went wrong.
        return "Problem reading document: " + uc.getURL();
    }
}
 
源代码4 项目: jdk8u60   文件: plain.java
/**
 * Returns one of several object types (this set may change in future
 * versions):
 * 1) instance of Thread:
 *    Invoke the thread to launch an external viewer.
 * 2) instance of InputStream:
 *    Bring up the "Save to disk" dialog page to allow the content
 *    to be saved to disk.
 * 3) instance of InputStreamImageSource:
 *    Load the image into HotJava in an image viewer page.
 * 4) instance of String:
 *    Go to a new page with the string as the plain text content
 *    of that page.
 */
public Object getContent(URLConnection uc) {
    try {
        InputStream is = uc.getInputStream();
        StringBuffer sb = new StringBuffer();
        int c;

        sb.append("[Content of " + uc.getURL() + "]\n\n");
        sb.append("[This opening message brought to you by your plain/text\n");
        sb.append("content handler. To remove this content handler, delete the\n");
        sb.append("COM.foo.content.text directory from your class path and\n");
        sb.append("the java.content.handler.pkgs property from your HotJava\n");
        sb.append("properties file.]\n");
        sb.append("----------------------------------------------------------------\n\n");

        // Read the characters from the source, accumulate them into the string buffer.
        // (Not the most efficient, but simplest for this example.)
        while ((c = is.read()) >= 0) {
            sb.append((char)c);
        }

        // Tidy up
        is.close();

        // Return the resulting string to our client (we're case 4 above)
        return sb.toString();
    } catch (IOException e) {
        // For any exception, just return an indication of what went wrong.
        return "Problem reading document: " + uc.getURL();
    }
}
 
源代码5 项目: materialup   文件: CookieManager.java
/**
 * Prior to opening a URLConnection, calling this method will set all unexpired cookies that match the path or subpaths for thi
 * underlying URL The connection MUST NOT have been opened method or an IOException will be thrown.
 *
 * @param conn a java.net.URLConnection - must NOT be open, or IOException will be thrown
 * @throws java.io.IOException Thrown if conn has already been opened.
 */
public void setCookies(URLConnection conn) throws IOException {

    // let's determine the domain and path to retrieve the appropriate cookies
    URL url = conn.getURL();
    String domain = getDomainFromHost(url.getHost());
    String path = url.getPath();

    Map domainStore = (Map) store.get(domain);
    if (domainStore == null)
        return;
    StringBuffer cookieStringBuffer = new StringBuffer();

    Iterator cookieNames = domainStore.keySet().iterator();
    while (cookieNames.hasNext()) {
        String cookieName = (String) cookieNames.next();
        Map cookie = (Map) domainStore.get(cookieName);
        // check cookie to ensure path matches and cookie is not expired
        // if all is cool, add cookie to header string
        if (comparePaths((String) cookie.get(PATH), path) && isNotExpired((String) cookie.get(EXPIRES))) {
            cookieStringBuffer.append(cookieName);
            cookieStringBuffer.append("=");
            cookieStringBuffer.append((String) cookie.get(cookieName));
            if (cookieNames.hasNext())
                cookieStringBuffer.append(SET_COOKIE_SEPARATOR);
        }
    }
    try {
        conn.setRequestProperty(COOKIE, cookieStringBuffer.toString());
    } catch (java.lang.IllegalStateException ise) {
        IOException ioe = new IOException("Illegal State! Cookies cannot be set on a URLConnection that is already connected. " + "Only call setCookies(java.net.URLConnection) AFTER calling java.net.URLConnection.connect().");
        throw ioe;
    }
}
 
源代码6 项目: android-discourse   文件: CookieManager.java
/**
 * Prior to opening a URLConnection, calling this method will set all unexpired cookies that match the path or subpaths for thi
 * underlying URL The connection MUST NOT have been opened method or an IOException will be thrown.
 *
 * @param conn a java.net.URLConnection - must NOT be open, or IOException will be thrown
 * @throws java.io.IOException Thrown if conn has already been opened.
 */
public void setCookies(URLConnection conn) throws IOException {

    // let's determine the domain and path to retrieve the appropriate cookies
    URL url = conn.getURL();
    String domain = getDomainFromHost(url.getHost());
    String path = url.getPath();

    Map domainStore = (Map) store.get(domain);
    if (domainStore == null)
        return;
    StringBuffer cookieStringBuffer = new StringBuffer();

    Iterator cookieNames = domainStore.keySet().iterator();
    while (cookieNames.hasNext()) {
        String cookieName = (String) cookieNames.next();
        Map cookie = (Map) domainStore.get(cookieName);
        // check cookie to ensure path matches and cookie is not expired
        // if all is cool, add cookie to header string
        if (comparePaths((String) cookie.get(PATH), path) && isNotExpired((String) cookie.get(EXPIRES))) {
            cookieStringBuffer.append(cookieName);
            cookieStringBuffer.append("=");
            cookieStringBuffer.append((String) cookie.get(cookieName));
            if (cookieNames.hasNext())
                cookieStringBuffer.append(SET_COOKIE_SEPARATOR);
        }
    }
    try {
        conn.setRequestProperty(COOKIE, cookieStringBuffer.toString());
    } catch (java.lang.IllegalStateException ise) {
        IOException ioe = new IOException("Illegal State! Cookies cannot be set on a URLConnection that is already connected. " + "Only call setCookies(java.net.URLConnection) AFTER calling java.net.URLConnection.connect().");
        throw ioe;
    }
}
 
源代码7 项目: jdk8u-dev-jdk   文件: plain.java
/**
 * Returns one of several object types (this set may change in future
 * versions):
 * 1) instance of Thread:
 *    Invoke the thread to launch an external viewer.
 * 2) instance of InputStream:
 *    Bring up the "Save to disk" dialog page to allow the content
 *    to be saved to disk.
 * 3) instance of InputStreamImageSource:
 *    Load the image into HotJava in an image viewer page.
 * 4) instance of String:
 *    Go to a new page with the string as the plain text content
 *    of that page.
 */
public Object getContent(URLConnection uc) {
    try {
        InputStream is = uc.getInputStream();
        StringBuffer sb = new StringBuffer();
        int c;

        sb.append("[Content of " + uc.getURL() + "]\n\n");
        sb.append("[This opening message brought to you by your plain/text\n");
        sb.append("content handler. To remove this content handler, delete the\n");
        sb.append("COM.foo.content.text directory from your class path and\n");
        sb.append("the java.content.handler.pkgs property from your HotJava\n");
        sb.append("properties file.]\n");
        sb.append("----------------------------------------------------------------\n\n");

        // Read the characters from the source, accumulate them into the string buffer.
        // (Not the most efficient, but simplest for this example.)
        while ((c = is.read()) >= 0) {
            sb.append((char)c);
        }

        // Tidy up
        is.close();

        // Return the resulting string to our client (we're case 4 above)
        return sb.toString();
    } catch (IOException e) {
        // For any exception, just return an indication of what went wrong.
        return "Problem reading document: " + uc.getURL();
    }
}
 
源代码8 项目: mycore   文件: MCRXMLResource.java
@Override
public long getLastModified() throws IOException {
    URLConnection con = getResourceURLConnection(name, classLoader);
    if (con == null) {
        return -1;
    }
    try {
        long lastModified = con.getLastModified();
        resolvedURL = con.getURL();
        LOGGER.debug("{} last modified: {}", name, lastModified);
        return lastModified;
    } finally {
        closeURLConnection(con);
    }
}
 
源代码9 项目: mycore   文件: MCRXMLResource.java
public URL getURL(String name, ClassLoader classLoader) throws IOException {
    URLConnection con = getResourceURLConnection(name, classLoader);
    if (con == null) {
        return null;
    }
    try {
        return con.getURL();
    } finally {
        closeURLConnection(con);
    }
}
 
源代码10 项目: hottub   文件: plain.java
/**
 * Returns one of several object types (this set may change in future
 * versions):
 * 1) instance of Thread:
 *    Invoke the thread to launch an external viewer.
 * 2) instance of InputStream:
 *    Bring up the "Save to disk" dialog page to allow the content
 *    to be saved to disk.
 * 3) instance of InputStreamImageSource:
 *    Load the image into HotJava in an image viewer page.
 * 4) instance of String:
 *    Go to a new page with the string as the plain text content
 *    of that page.
 */
public Object getContent(URLConnection uc) {
    try {
        InputStream is = uc.getInputStream();
        StringBuffer sb = new StringBuffer();
        int c;

        sb.append("[Content of " + uc.getURL() + "]\n\n");
        sb.append("[This opening message brought to you by your plain/text\n");
        sb.append("content handler. To remove this content handler, delete the\n");
        sb.append("COM.foo.content.text directory from your class path and\n");
        sb.append("the java.content.handler.pkgs property from your HotJava\n");
        sb.append("properties file.]\n");
        sb.append("----------------------------------------------------------------\n\n");

        // Read the characters from the source, accumulate them into the string buffer.
        // (Not the most efficient, but simplest for this example.)
        while ((c = is.read()) >= 0) {
            sb.append((char)c);
        }

        // Tidy up
        is.close();

        // Return the resulting string to our client (we're case 4 above)
        return sb.toString();
    } catch (IOException e) {
        // For any exception, just return an indication of what went wrong.
        return "Problem reading document: " + uc.getURL();
    }
}
 
源代码11 项目: openjdk-8-source   文件: plain.java
/**
 * Returns one of several object types (this set may change in future
 * versions):
 * 1) instance of Thread:
 *    Invoke the thread to launch an external viewer.
 * 2) instance of InputStream:
 *    Bring up the "Save to disk" dialog page to allow the content
 *    to be saved to disk.
 * 3) instance of InputStreamImageSource:
 *    Load the image into HotJava in an image viewer page.
 * 4) instance of String:
 *    Go to a new page with the string as the plain text content
 *    of that page.
 */
public Object getContent(URLConnection uc) {
    try {
        InputStream is = uc.getInputStream();
        StringBuffer sb = new StringBuffer();
        int c;

        sb.append("[Content of " + uc.getURL() + "]\n\n");
        sb.append("[This opening message brought to you by your plain/text\n");
        sb.append("content handler. To remove this content handler, delete the\n");
        sb.append("COM.foo.content.text directory from your class path and\n");
        sb.append("the java.content.handler.pkgs property from your HotJava\n");
        sb.append("properties file.]\n");
        sb.append("----------------------------------------------------------------\n\n");

        // Read the characters from the source, accumulate them into the string buffer.
        // (Not the most efficient, but simplest for this example.)
        while ((c = is.read()) >= 0) {
            sb.append((char)c);
        }

        // Tidy up
        is.close();

        // Return the resulting string to our client (we're case 4 above)
        return sb.toString();
    } catch (IOException e) {
        // For any exception, just return an indication of what went wrong.
        return "Problem reading document: " + uc.getURL();
    }
}
 
源代码12 项目: openjdk-8   文件: plain.java
/**
 * Returns one of several object types (this set may change in future
 * versions):
 * 1) instance of Thread:
 *    Invoke the thread to launch an external viewer.
 * 2) instance of InputStream:
 *    Bring up the "Save to disk" dialog page to allow the content
 *    to be saved to disk.
 * 3) instance of InputStreamImageSource:
 *    Load the image into HotJava in an image viewer page.
 * 4) instance of String:
 *    Go to a new page with the string as the plain text content
 *    of that page.
 */
public Object getContent(URLConnection uc) {
    try {
        InputStream is = uc.getInputStream();
        StringBuffer sb = new StringBuffer();
        int c;

        sb.append("[Content of " + uc.getURL() + "]\n\n");
        sb.append("[This opening message brought to you by your plain/text\n");
        sb.append("content handler. To remove this content handler, delete the\n");
        sb.append("COM.foo.content.text directory from your class path and\n");
        sb.append("the java.content.handler.pkgs property from your HotJava\n");
        sb.append("properties file.]\n");
        sb.append("----------------------------------------------------------------\n\n");

        // Read the characters from the source, accumulate them into the string buffer.
        // (Not the most efficient, but simplest for this example.)
        while ((c = is.read()) >= 0) {
            sb.append((char)c);
        }

        // Tidy up
        is.close();

        // Return the resulting string to our client (we're case 4 above)
        return sb.toString();
    } catch (IOException e) {
        // For any exception, just return an indication of what went wrong.
        return "Problem reading document: " + uc.getURL();
    }
}
 
源代码13 项目: jdk8u_jdk   文件: plain.java
/**
 * Returns one of several object types (this set may change in future
 * versions):
 * 1) instance of Thread:
 *    Invoke the thread to launch an external viewer.
 * 2) instance of InputStream:
 *    Bring up the "Save to disk" dialog page to allow the content
 *    to be saved to disk.
 * 3) instance of InputStreamImageSource:
 *    Load the image into HotJava in an image viewer page.
 * 4) instance of String:
 *    Go to a new page with the string as the plain text content
 *    of that page.
 */
public Object getContent(URLConnection uc) {
    try {
        InputStream is = uc.getInputStream();
        StringBuffer sb = new StringBuffer();
        int c;

        sb.append("[Content of " + uc.getURL() + "]\n\n");
        sb.append("[This opening message brought to you by your plain/text\n");
        sb.append("content handler. To remove this content handler, delete the\n");
        sb.append("COM.foo.content.text directory from your class path and\n");
        sb.append("the java.content.handler.pkgs property from your HotJava\n");
        sb.append("properties file.]\n");
        sb.append("----------------------------------------------------------------\n\n");

        // Read the characters from the source, accumulate them into the string buffer.
        // (Not the most efficient, but simplest for this example.)
        while ((c = is.read()) >= 0) {
            sb.append((char)c);
        }

        // Tidy up
        is.close();

        // Return the resulting string to our client (we're case 4 above)
        return sb.toString();
    } catch (IOException e) {
        // For any exception, just return an indication of what went wrong.
        return "Problem reading document: " + uc.getURL();
    }
}
 
源代码14 项目: openjdk-8-source   文件: URLImageSource.java
public URLImageSource(URLConnection uc) {
    this(uc.getURL(), uc);
}
 
源代码15 项目: Onosendai   文件: HttpHelper.java
@Override
public R handleStream (final URLConnection connection, final InputStream is, final int contentLength) throws IOException {
	this.url = connection.getURL();
	this.contentLength = contentLength;
	return this.delagate.handleStream(connection, is, contentLength);
}
 
源代码16 项目: openjdk-8   文件: URLImageSource.java
public URLImageSource(URLConnection uc) {
    this(uc.getURL(), uc);
}
 
源代码17 项目: openjdk-jdk8u-backup   文件: URLImageSource.java
public URLImageSource(URLConnection uc) {
    this(uc.getURL(), uc);
}
 
源代码18 项目: jdk8u-jdk   文件: URLImageSource.java
public URLImageSource(URLConnection uc) {
    this(uc.getURL(), uc);
}
 
源代码19 项目: jdk8u-jdk   文件: URLImageSource.java
public URLImageSource(URLConnection uc) {
    this(uc.getURL(), uc);
}
 
源代码20 项目: jdk8u-dev-jdk   文件: URLImageSource.java
public URLImageSource(URLConnection uc) {
    this(uc.getURL(), uc);
}