java.net.URLConnection.getURL()方法的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(182)

本文整理了Java中java.net.URLConnection.getURL()方法的一些代码示例,展示了URLConnection.getURL()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。URLConnection.getURL()方法的具体详情如下:
包路径:java.net.URLConnection
类名称:URLConnection
方法名:getURL

URLConnection.getURL介绍

[英]Returns the URL represented by this URLConnection.
[中]返回此URL连接表示的URL。

代码示例

代码示例来源:origin: jenkinsci/jenkins

  1. public NotTalkingToJenkinsException(URLConnection c) {
  2. super("There's no Jenkins running at " + c.getURL().toString());
  3. }
  4. }

代码示例来源:origin: lingochamp/okdownload

  1. DownloadUrlConnection(URLConnection connection, IRedirectHandler redirectHandler) {
  2. this.connection = connection;
  3. this.url = connection.getURL();
  4. this.redirectHandler = redirectHandler;
  5. }

代码示例来源:origin: stackoverflow.com

  1. URLConnection con = new URL( url ).openConnection();
  2. System.out.println( "orignal url: " + con.getURL() );
  3. con.connect();
  4. System.out.println( "connected url: " + con.getURL() );
  5. InputStream is = con.getInputStream();
  6. System.out.println( "redirected url: " + con.getURL() );
  7. is.close();

代码示例来源:origin: redisson/redisson

  1. /**
  2. * Returns the URL.
  3. *
  4. * @return null if the class file could not be obtained.
  5. */
  6. public URL find(String classname) {
  7. try {
  8. URLConnection con = openClassfile0(classname);
  9. InputStream is = con.getInputStream();
  10. if (is != null) {
  11. is.close();
  12. return con.getURL();
  13. }
  14. }
  15. catch (IOException e) {}
  16. return null;
  17. }

代码示例来源:origin: nutzam/nutz

  1. public static String dumpHeaders(URLConnection conn) {
  2. StringBuilder sb = new StringBuilder();
  3. Iterator<?> it = conn.getHeaderFields().keySet().iterator();
  4. sb.append('\n');
  5. sb.append("<HEADERS url=\"" + conn.getURL().toString() + "\">");
  6. while (it.hasNext()) {
  7. String name = (String) it.next();
  8. sb.append('\n');
  9. sb.append("[" + name + "]:");
  10. sb.append(conn.getHeaderField(name));
  11. }
  12. sb.append('\n');
  13. sb.append("</HEADERS>");
  14. return sb.toString();
  15. }

代码示例来源:origin: jenkinsci/jenkins

  1. /**
  2. * If the server advertises CLI endpoint, returns its location.
  3. * @deprecated Specific to {@link Mode#REMOTING}.
  4. */
  5. @Deprecated
  6. protected CliPort getCliTcpPort(URL url) throws IOException {
  7. if (url.getHost()==null || url.getHost().length()==0) {
  8. throw new IOException("Invalid URL: "+url);
  9. }
  10. URLConnection head = url.openConnection();
  11. try {
  12. head.connect();
  13. } catch (IOException e) {
  14. throw (IOException)new IOException("Failed to connect to "+url).initCause(e);
  15. }
  16. String h = head.getHeaderField("X-Jenkins-CLI-Host");
  17. if (h==null) h = head.getURL().getHost();
  18. String p1 = head.getHeaderField("X-Jenkins-CLI-Port");
  19. if (p1==null) p1 = head.getHeaderField("X-Hudson-CLI-Port"); // backward compatibility
  20. String p2 = head.getHeaderField("X-Jenkins-CLI2-Port");
  21. String identity = head.getHeaderField("X-Instance-Identity");
  22. flushURLConnection(head);
  23. if (p1==null && p2==null) {
  24. verifyJenkinsConnection(head);
  25. throw new IOException("No X-Jenkins-CLI2-Port among " + head.getHeaderFields().keySet());
  26. }
  27. if (p2!=null) return new CliPort(new InetSocketAddress(h,Integer.parseInt(p2)),identity,2);
  28. else return new CliPort(new InetSocketAddress(h,Integer.parseInt(p1)),identity,1);
  29. }

代码示例来源:origin: scouter-project/scouter

  1. /**
  2. * Returns the URL.
  3. *
  4. * @return null if the class file could not be obtained.
  5. */
  6. public URL find(String classname) {
  7. try {
  8. URLConnection con = openClassfile0(classname);
  9. InputStream is = con.getInputStream();
  10. if (is != null) {
  11. is.close();
  12. return con.getURL();
  13. }
  14. }
  15. catch (IOException e) {}
  16. return null;
  17. }

代码示例来源:origin: org.javassist/javassist

  1. /**
  2. * Returns the URL.
  3. *
  4. * @return null if the class file could not be obtained.
  5. */
  6. @Override
  7. public URL find(String classname) {
  8. try {
  9. URLConnection con = openClassfile0(classname);
  10. InputStream is = con.getInputStream();
  11. if (is != null) {
  12. is.close();
  13. return con.getURL();
  14. }
  15. }
  16. catch (IOException e) {}
  17. return null;
  18. }

代码示例来源:origin: scouter-project/scouter

  1. /**
  2. * Returns the URL.
  3. *
  4. * @return null if the class file could not be obtained.
  5. */
  6. @Override
  7. public URL find(String classname) {
  8. try {
  9. URLConnection con = openClassfile0(classname);
  10. InputStream is = con.getInputStream();
  11. if (is != null) {
  12. is.close();
  13. return con.getURL();
  14. }
  15. }
  16. catch (IOException e) {}
  17. return null;
  18. }

代码示例来源:origin: spotbugs/spotbugs

  1. public InputStream progessMonitoredInputStream(URLConnection c, String msg) throws IOException {
  2. InputStream in = c.getInputStream();
  3. int length = c.getContentLength();
  4. return wrapGzip(progressMonitoredInputStream(in, length, msg), c.getURL());
  5. }

代码示例来源:origin: jenkinsci/jenkins

  1. if (con != null && con.getURL() != null && !src.toString().equals(con.getURL().toString())) {
  2. extraMessage = " (redirected to: " + con.getURL() + ")";

代码示例来源:origin: org.codehaus.groovy/groovy

  1. public URL loadGroovySource(String className) throws MalformedURLException {
  2. String filename;
  3. for (String extension : getConfig().getScriptExtensions()) {
  4. filename = className.replace('.', File.separatorChar) + "." + extension;
  5. try {
  6. URLConnection dependentScriptConn = rc.getResourceConnection(filename);
  7. return dependentScriptConn.getURL();
  8. } catch (ResourceException e) {
  9. //TODO: maybe do something here?
  10. }
  11. }
  12. return rl.loadGroovySource(className);
  13. }
  14. });

代码示例来源:origin: org.codehaus.groovy/groovy

  1. /**
  2. * Get the class of the scriptName in question, so that you can instantiate
  3. * Groovy objects with caching and reloading.
  4. *
  5. * @param scriptName resource name pointing to the script
  6. * @return the loaded scriptName as a compiled class
  7. * @throws ResourceException if there is a problem accessing the script
  8. * @throws ScriptException if there is a problem parsing the script
  9. */
  10. public Class loadScriptByName(String scriptName) throws ResourceException, ScriptException {
  11. URLConnection conn = rc.getResourceConnection(scriptName);
  12. String path = conn.getURL().toExternalForm();
  13. ScriptCacheEntry entry = scriptCache.get(path);
  14. Class clazz = null;
  15. if (entry != null) clazz = entry.scriptClass;
  16. try {
  17. if (isSourceNewer(entry)) {
  18. try {
  19. String encoding = conn.getContentEncoding() != null ? conn.getContentEncoding() : config.getSourceEncoding();
  20. String content = IOGroovyMethods.getText(conn.getInputStream(), encoding);
  21. clazz = groovyLoader.parseClass(content, path);
  22. } catch (IOException e) {
  23. throw new ResourceException(e);
  24. }
  25. }
  26. } finally {
  27. forceClose(conn);
  28. }
  29. return clazz;
  30. }

代码示例来源:origin: org.codehaus.groovy/groovy

  1. String finalName = name + "." + ext;
  2. URLConnection conn = rc.getResourceConnection(finalName);
  3. URL url = conn.getURL();
  4. String path = url.toExternalForm();
  5. ScriptCacheEntry entry = scriptCache.get(path);

代码示例来源:origin: org.codehaus.groovy/groovy

  1. try {
  2. cache.get(depSourcePath);
  3. cu.addSource(getResourceConnection(depSourcePath).getURL());
  4. } catch (ResourceException e) {

代码示例来源:origin: stackoverflow.com

  1. URLConnection con = new URL(url).openConnection();
  2. System.out.println("Orignal URL: " + con.getURL());
  3. con.connect();
  4. System.out.println("Connected URL: " + con.getURL());
  5. InputStream is = con.getInputStream();
  6. System.out.println("Redirected URL: " + con.getURL());
  7. is.close();

代码示例来源:origin: stackoverflow.com

  1. String getShareURL(String strURL) {
  2. URLConnection conn = null;
  3. String redirectedUrl = null;
  4. try {
  5. URL inputURL = new URL(strURL);
  6. conn = inputURL.openConnection();
  7. conn.connect();
  8. InputStream is = conn.getInputStream();
  9. System.out.println("Redirected URL: " + conn.getURL());
  10. redirectedUrl = conn.getURL().toString();
  11. is.close();
  12. } catch (MalformedURLException e) {
  13. Log.d(TAG, "Please input a valid URL");
  14. } catch (IOException ioe) {
  15. Log.d(TAG, "Can not connect to the URL");
  16. }
  17. return redirectedUrl;
  18. }

代码示例来源:origin: magefree/mage

  1. try (InputStream inputStream = conn.getURL().openStream()) {
  2. List<TokenData> siteTokensData = parseTokensData(inputStream);
  3. for (TokenData siteData : siteTokensData) {

代码示例来源:origin: biz.aQute.bnd/biz.aQute.bndlib

  1. /**
  2. * Convenience method to make it easier to verify connections
  3. *
  4. * @param connection The connection to match
  5. * @return true if this connection should be handled.
  6. */
  7. protected boolean matches(URLConnection connection) {
  8. return matches(connection.getURL());
  9. }

代码示例来源:origin: rometools/rome

  1. /**
  2. * @param eventType The event type to fire
  3. * @param connection the current connection
  4. */
  5. protected void fireEvent(final String eventType, final URLConnection connection) {
  6. fireEvent(eventType, connection.getURL().toExternalForm(), null);
  7. }

相关文章

URLConnection类方法