java.net.URL.getUserInfo()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(204)

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

URL.getUserInfo介绍

[英]Returns the user info of this URL, or null if this URL has no user info.
[中]返回此URL的用户信息,如果此URL没有用户信息,则返回null。

代码示例

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

String urlStr = "http://abc.dev.domain.com/0007AC/ads/800x480 15sec h.264.mp4";
URL url = new URL(urlStr);
URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef());
url = uri.toURL();

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

public static String removeUserInfo(String url) {
    String userInfo = "";
    try {
      userInfo = new URL(url).getUserInfo();
    } catch (MalformedURLException e) {
      // ignore
    }
    if (null == userInfo || userInfo.isEmpty()) {
      return url;
    }
    return url.replace(userInfo, "XXXX:XXXX");
  }
}

代码示例来源:origin: apache/hive

private String evaluate(URL url, int index) {
 if (url == null || index < 0 || index >= partnames.length) {
  return null;
 }
 switch (partnames[index]) {
  case HOST          : return url.getHost();
  case PATH          : return url.getPath();
  case QUERY         : return url.getQuery();
  case REF           : return url.getRef();
  case PROTOCOL      : return url.getProtocol();
  case FILE          : return url.getFile();
  case AUTHORITY     : return url.getAuthority();
  case USERINFO      : return url.getUserInfo();
  case QUERY_WITH_KEY: return evaluateQuery(url.getQuery(), paths[index]);
  case NULLNAME:
  default            : return null;
 }
}

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

URL proximo = new URL(System.getenv("PROXIMO_URL"));
String userInfo = proximo.getUserInfo();
String user = userInfo.substring(0, userInfo.indexOf(':'));
String password = userInfo.substring(userInfo.indexOf(':') + 1);

System.setProperty("socksProxyHost", proximo.getHost());
Authenticator.setDefault(new ProxyAuthenticator(user, password));

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

set(context.protocol, context.getHost(), context.getPort(), context.getAuthority(),
    context.getUserInfo(), context.getPath(), context.getQuery(),
    context.getRef());
if (streamHandler == null) {

代码示例来源:origin: net.sourceforge.htmlunit/htmlunit

/**
 * Creates and returns a new URL identical to the specified URL, except using the specified host.
 * @param u the URL on which to base the returned URL
 * @param newHost the new host to use in the returned URL
 * @return a new URL identical to the specified URL, except using the specified host
 * @throws MalformedURLException if there is a problem creating the new URL
 */
public static URL getUrlWithNewHost(final URL u, final String newHost)
  throws MalformedURLException {
  return createNewUrl(u.getProtocol(), u.getUserInfo(), newHost,
            u.getPort(), u.getPath(), u.getRef(), u.getQuery());
}

代码示例来源:origin: net.sourceforge.htmlunit/htmlunit

/**
 * Creates and returns a new URL identical to the specified URL, except using the specified host.
 * @param u the URL on which to base the returned URL
 * @param newHost the new host to use in the returned URL
 * @param newPort the new port to use in the returned URL
 * @return a new URL identical to the specified URL, except using the specified host
 * @throws MalformedURLException if there is a problem creating the new URL
 */
public static URL getUrlWithNewHostAndPort(final URL u, final String newHost, final int newPort)
  throws MalformedURLException {
  return createNewUrl(u.getProtocol(), u.getUserInfo(), newHost, newPort, u.getPath(), u.getRef(), u.getQuery());
}

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

/**
 * FtpURLConnection constructor comment.
 *
 * @param url
 */
protected FtpURLConnection(URL url) {
  super(url);
  hostName = url.getHost();
  String parse = url.getUserInfo();
  if (parse != null) {
    int split = parse.indexOf(':');
    if (split >= 0) {
      username = parse.substring(0, split);
      password = parse.substring(split + 1);
    } else {
      username = parse;
    }
  }
  uri = null;
  try {
    uri = url.toURI();
  } catch (URISyntaxException e) {
    // do nothing.
  }
}

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

String urlStr = "http://abc.dev.domain.com/0007AC/ads/800x480 15sec h.264.mp4";
URL url = new URL(urlStr);
URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef());
url = uri.toURL();

代码示例来源:origin: oracle/opengrok

/**
 * If given path is a URL, return the string representation with the user-info part filtered out.
 * @param path path to object
 * @return either the original string or string representation of URL with the user-info part removed
 */
public static String redactUrl(String path) {
  URL url;
  try {
    url = new URL(path);
  } catch (MalformedURLException e) {
    // not an URL
    return path;
  }
  if (url.getUserInfo() != null) {
    return url.toString().replace(url.getUserInfo(),
        REDACTED_USER_INFO);
  } else {
    return path;
  }
}

代码示例来源:origin: apache/drill

private String evaluate(URL url, int index) {
 if (url == null || index < 0 || index >= partnames.length) {
  return null;
 }
 switch (partnames[index]) {
  case HOST          : return url.getHost();
  case PATH          : return url.getPath();
  case QUERY         : return url.getQuery();
  case REF           : return url.getRef();
  case PROTOCOL      : return url.getProtocol();
  case FILE          : return url.getFile();
  case AUTHORITY     : return url.getAuthority();
  case USERINFO      : return url.getUserInfo();
  case QUERY_WITH_KEY: return evaluateQuery(url.getQuery(), paths[index]);
  case NULLNAME:
  default            : return null;
 }
}

代码示例来源:origin: apache/activemq

protected FTPClient createFTP() throws IOException, JMSException {
  String connectUrl = url.getHost();
  setUserInformation(url.getUserInfo());
  int port = url.getPort() < 1 ? 21 : url.getPort();
  
  FTPClient ftp = new FTPClient();
  try {
    ftp.connect(connectUrl, port);
  } catch(ConnectException e) {
    throw new JMSException("Problem connecting the FTP-server");
  }
  if(!ftp.login(ftpUser, ftpPass)) {
    ftp.quit();
    ftp.disconnect();
    throw new JMSException("Cant Authentificate to FTP-Server");
  }
  return ftp;
}

代码示例来源:origin: HtmlUnit/htmlunit

/**
 * Creates and returns a new URL identical to the specified URL, except using the specified host.
 * @param u the URL on which to base the returned URL
 * @param newHost the new host to use in the returned URL
 * @return a new URL identical to the specified URL, except using the specified host
 * @throws MalformedURLException if there is a problem creating the new URL
 */
public static URL getUrlWithNewHost(final URL u, final String newHost)
  throws MalformedURLException {
  return createNewUrl(u.getProtocol(), u.getUserInfo(), newHost,
            u.getPort(), u.getPath(), u.getRef(), u.getQuery());
}

代码示例来源:origin: igvteam/igv

public IGVSeekableFTPStream(URL url) throws IOException {
  this.source = url.toExternalForm();
  this.userInfo = url.getUserInfo();
  this.host = url.getHost();
  this.path = url.getPath();
  ftp = FTPUtils.connect(host, userInfo, new UserPasswordInputImpl());
}

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

String urlStr = "http://www.example.com/CEREC® Materials & Accessories/IPS Empress® CAD.pdf"
 URL url= new URL(urlStr);
 URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef());

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

URL url = new URL("http://user:pass@domain.com/url");
URLConnection urlConnection = url.openConnection();

if (url.getUserInfo() != null) {
  String basicAuth = "Basic " + new String(new Base64().encode(url.getUserInfo().getBytes()));
  urlConnection.setRequestProperty("Authorization", basicAuth);
}

InputStream inputStream = urlConnection.getInputStream();

代码示例来源:origin: net.sourceforge.htmlunit/htmlunit

/**
 * Creates and returns a new URL identical to the specified URL, except using the specified port.
 * @param u the URL on which to base the returned URL
 * @param newPort the new port to use in the returned URL
 * @return a new URL identical to the specified URL, except using the specified port
 * @throws MalformedURLException if there is a problem creating the new URL
 */
public static URL getUrlWithNewPort(final URL u, final int newPort) throws MalformedURLException {
  return createNewUrl(u.getProtocol(), u.getUserInfo(), u.getHost(),
            newPort, u.getPath(), u.getRef(), u.getQuery());
}

代码示例来源:origin: neo4j-contrib/rabbithole

private HttpClient clientFor(URL url) {
  HttpClientBuilder builder = HttpClients.custom();
  final String userInfo = url.getUserInfo();
  if (userInfo != null) {
    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    final String[] usernamePassword = userInfo.split(":");
    credsProvider.setCredentials(new AuthScope(url.getHost(), url.getPort()),
        new UsernamePasswordCredentials(usernamePassword[0], usernamePassword[1]));
    builder = builder.setDefaultCredentialsProvider(credsProvider);
  }
  return builder.build();
}

代码示例来源:origin: org.utgenome.thirdparty/picard

@Override
public InputStream openInputStream() throws IOException {
  String file = url.getPath();
  FTPClient ftp = FTPUtils.connect(url.getHost(), url.getUserInfo(), null);
  ftp.pasv();
  ftp.retr(file);
  return new FTPStream(ftp);
}

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

public URL convertToURLEscapingIllegalCharacters(String string){
  try {
    String decodedURL = URLDecoder.decode(string, "UTF-8");
    URL url = new URL(decodedURL);
    URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); 
    return uri.toURL(); 
  } catch (Exception ex) {
    ex.printStackTrace();
    return null;
  }
}

相关文章