本文整理汇总了Java中java.net.URLConnection.getURL方法的典型用法代码示例。如果您正苦于以下问题:Java URLConnection.getURL方法的具体用法?Java URLConnection.getURL怎么用?Java URLConnection.getURL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.URLConnection
的用法示例。
在下文中一共展示了URLConnection.getURL方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkHttpConnection
import java.net.URLConnection; //导入方法依赖的package包/类
public static void checkHttpConnection(URLConnection urlConnection) {
URL url = null;
try {
if (urlConnection != null) {
url = urlConnection.getURL();
}
} catch (Exception e) {
HookHandler.LOGGER.warn(e.getMessage());
}
if (url != null) {
checkHttpUrl(url.toString(), urlConnection.getURL().getHost(), "url_open_connection");
}
}
示例2: initPumping
import java.net.URLConnection; //导入方法依赖的package包/类
private void initPumping(URLConnection connection) throws IOException {
final Date lastModif = new Date(connection.getLastModified());
final URL realUrl = connection.getURL();
final String accept = connection.getHeaderField("Accept-Ranges");
final boolean acceptBytes = accept != null ? accept.contains("bytes"): false;
final long length = connection.getContentLength();
pumping.init(realUrl, length, lastModif, acceptBytes);
}
示例3: getContent
import java.net.URLConnection; //导入方法依赖的package包/类
/**
* 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: getJSFileFromURL
import java.net.URLConnection; //导入方法依赖的package包/类
private String getJSFileFromURL(URLConnection paramURLConnection)
throws Exception {
// Trace.msgNetPrintln("net.proxy.auto.download.js", new Object[] {
// paramURLConnection.getURL() });
try {
// RemoveCommentReader localRemoveCommentReader = new
// RemoveCommentReader(new
// InputStreamReader(paramURLConnection.getInputStream()));
InputStreamReader localRemoveCommentReader = new InputStreamReader(
paramURLConnection.getInputStream());
BufferedReader localBufferedReader = new BufferedReader(
localRemoveCommentReader);
StringWriter localStringWriter = new StringWriter();
char[] arrayOfChar = new char[100];
int i;
while ((i = localBufferedReader.read(arrayOfChar)) != -1) {
localStringWriter.write(arrayOfChar, 0, i);
}
localBufferedReader.close();
localRemoveCommentReader.close();
localStringWriter.close();
return localStringWriter.toString();
} catch (Throwable localThrowable) {
throw new Exception("Unable to obtain auto proxy file from "
+ paramURLConnection.getURL(), localThrowable);
}
}
示例5: getInputStreamOfURL
import java.net.URLConnection; //导入方法依赖的package包/类
public InputStream getInputStreamOfURL(URL downloadURL, Proxy proxy) throws IOException{
URLConnection ucn = null;
// loop until no more redirections are
for (;;) {
if (Thread.currentThread().isInterrupted()) {
return null;
}
if(proxy != null) {
ucn = downloadURL.openConnection(proxy);
} else {
ucn = downloadURL.openConnection();
}
HttpURLConnection hucn = doConfigureURLConnection(ucn);
if(Thread.currentThread().isInterrupted())
return null;
ucn.connect();
int rc = hucn.getResponseCode();
boolean isRedirect =
rc == HttpURLConnection.HTTP_MOVED_TEMP ||
rc == HttpURLConnection.HTTP_MOVED_PERM;
if (!isRedirect) {
break;
}
String addr = hucn.getHeaderField(HTTP_REDIRECT_LOCATION);
URL newURL = new URL(addr);
if (!downloadURL.getProtocol().equalsIgnoreCase(newURL.getProtocol())) {
throw new ResourceRedirectException(newURL);
}
downloadURL = newURL;
}
ucn.setReadTimeout(10000);
InputStream is = ucn.getInputStream();
streamLength = ucn.getContentLength();
effectiveURL = ucn.getURL();
return is;
}
示例6: URLImageSource
import java.net.URLConnection; //导入方法依赖的package包/类
public URLImageSource(URLConnection uc) {
this(uc.getURL(), uc);
}
示例7: newResponse
import java.net.URLConnection; //导入方法依赖的package包/类
/**
* Returns a web response built from a URL connection. Provided to allow
* access to WebResponse parsing without using a WebClient.
**/
public static WebResponse newResponse( URLConnection connection ) throws IOException {
return new HttpWebResponse( null, FrameSelector.TOP_FRAME, connection.getURL(), connection, HttpUnitOptions.getExceptionsThrownOnErrorStatus() );
}
示例8: newResponse
import java.net.URLConnection; //导入方法依赖的package包/类
/**
* Returns a web response built from a URL connection. Provided to allow
* access to WebResponse parsing without using a WebClient.
**/
public static WebResponse newResponse( URLConnection connection ) throws IOException {
return new HttpWebResponse( null, "_top", connection.getURL(), connection, HttpUnitOptions.getExceptionsThrownOnErrorStatus() );
}