本文整理了Java中java.net.URL.getQuery()
方法的一些代码示例,展示了URL.getQuery()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。URL.getQuery()
方法的具体详情如下:
包路径:java.net.URL
类名称:URL
方法名:getQuery
[英]Returns the query part of this URL, or null if this URL has no query.
[中]返回此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: jenkinsci/jenkins
/**
* Normalize the URL so that it ends with '/'.
* <p>
* An attention is paid to preserve the query parameters in URL if any.
*/
protected static URL normalizeToEndWithSlash(URL url) {
if(url.getPath().endsWith("/"))
return url;
// normalize
String q = url.getQuery();
q = q!=null?('?'+q):"";
try {
return new URL(url,url.getPath()+'/'+q);
} catch (MalformedURLException e) {
// impossible
throw new Error(e);
}
}
代码示例来源:origin: mpusher/mpush
public String translate(URL uri) {
StringBuilder sb = new StringBuilder(128);
sb.append(uri.getProtocol()).append("://")
.append(ip)
.append(':')
.append(port)
.append(uri.getPath());
String query = uri.getQuery();
if (query != null) sb.append('?').append(query);
return sb.toString();
}
代码示例来源:origin: Alluxio/alluxio
/**
* Gets object from Qiniu kodo. All requests are authenticated by default,default expires 3600s We
* use okhttp as our HTTP client and support two main parameters in the external adjustment, MAX
* request and timeout time.
* @param key object key
* @param startPos start index for object
* @param endPos end index for object
* @return inputstream
* @param contentLength object file size
* @throws IOException
*/
public InputStream getObject(String key, long startPos, long endPos, long contentLength)
throws IOException {
String baseUrl = String.format("http://%s/%s", mDownloadHost, key);
String privateUrl = mAuth.privateDownloadUrl(baseUrl);
URL url = new URL(privateUrl);
String objectUrl = String.format("http://%s/%s?%s", mEndPoint, key, url.getQuery());
Request request = new Request.Builder().url(objectUrl)
.addHeader("Range",
"bytes=" + String.valueOf(startPos) + "-"
+ String.valueOf(endPos < contentLength ? endPos - 1 : contentLength - 1))
.addHeader("Host", mDownloadHost).get().build();
Response response = mOkHttpClient.newCall(request).execute();
if (response.code() != 200 && response.code() != 206) {
throw new IOException(String.format("Qiniu kodo:get object failed errcode:%d,errmsg:%s",
response.code(), response.message()));
}
return response.body().byteStream();
}
代码示例来源:origin: multidots/android-app-common-tasks
/**
* Parse a URL query and fragment parameters into a key-value bundle.
*
* @param url the URL to parse
* @return a dictionary bundle of keys and values
*/
public static Map<String, String> parseUrl(String url) {
// hack to prevent MalformedURLException
url = url.replace("fbconnect", "http");
try {
URL u = new URL(url);
Map<String, String> params = decodeUrl(u.getQuery());
params.putAll(decodeUrl(u.getRef()));
return params;
} catch (MalformedURLException e) {
return new HashMap<>();
}
}
代码示例来源:origin: ron190/jsql-injection
public static void initQueryString(String urlQuery) throws MalformedURLException {
URL url = new URL(urlQuery);
if ("".equals(urlQuery) || "".equals(url.getHost())) {
throw new MalformedURLException("empty URL");
}
ConnectionUtil.setUrlByUser(urlQuery);
// Parse url and GET query string
ParameterUtil.setQueryString(new ArrayList<SimpleEntry<String, String>>());
Matcher regexSearch = Pattern.compile("(.*\\?)(.*)").matcher(urlQuery);
if (regexSearch.find()) {
ConnectionUtil.setUrlBase(regexSearch.group(1));
if (!"".equals(url.getQuery())) {
ParameterUtil.setQueryString(
Pattern.compile("&").splitAsStream(regexSearch.group(2))
.map(s -> Arrays.copyOf(s.split("="), 2))
.map(o -> new SimpleEntry<String, String>(o[0], o[1] == null ? "" : o[1]))
.collect(Collectors.toList())
);
}
} else {
ConnectionUtil.setUrlBase(urlQuery);
}
}
代码示例来源:origin: geoserver/geoserver
assertTrue(graphic instanceof ExternalGraphic);
assertEquals(
((ExternalGraphic) graphic).getLocation().getPath(),
iconFile.toURI().toURL().getPath());
assertEquals("param1=1", ((ExternalGraphic) graphic).getLocation().getQuery());
assertEquals("textAfterHash", ((ExternalGraphic) graphic).getLocation().getRef());
代码示例来源:origin: geotools/geotools
if (input instanceof URL && (((URL) input).getProtocol().equalsIgnoreCase("http"))) {
try {
java.net.URLDecoder.decode(((URL) input).getQuery().intern(), "UTF-8");
代码示例来源:origin: geoserver/geoserver
assertTrue(graphic instanceof ExternalGraphic);
assertEquals(
((ExternalGraphic) graphic).getLocation().getPath(),
iconFile.toURI().toURL().getPath());
assertEquals("param1=1", ((ExternalGraphic) graphic).getLocation().getQuery());
代码示例来源:origin: RipMeApp/ripme
private URL getJsonURL(URL url) throws MalformedURLException {
// Append ".json" to URL in appropriate location.
String result = url.getProtocol() + "://" + url.getHost() + url.getPath() + ".json";
if (url.getQuery() != null) {
result += "?" + url.getQuery();
}
return new URL(result);
}
代码示例来源:origin: ltsopensource/light-task-scheduler
private static URL buildGetUrl(String strUrl, String query) throws IOException {
URL url = new URL(strUrl);
if (StringUtils.isEmpty(query)) {
return url;
}
if (StringUtils.isEmpty(url.getQuery())) {
if (strUrl.endsWith("?")) {
strUrl = strUrl + query;
} else {
strUrl = strUrl + "?" + query;
}
} else {
if (strUrl.endsWith("&")) {
strUrl = strUrl + query;
} else {
strUrl = strUrl + "&" + query;
}
}
return new URL(strUrl);
}
代码示例来源:origin: i2p/i2p.i2p
public static final String toRelativeURL(String urlStr, boolean withParam)
{
String uri = urlStr;
if (isAbsoluteURL(urlStr) == false) {
if (0 < urlStr.length() && urlStr.charAt(0) != '/')
uri = "/" + urlStr;
}
else {
try{
URL url = new URL(urlStr);
uri = url.getPath();
if (withParam == true) {
String queryStr = url.getQuery();
if (!queryStr.equals("")){
uri += "?" + queryStr;
}
}
if (uri.endsWith("/"))
uri = uri.substring(0,uri.length()-1);
}catch(Exception e){}
}
return uri;
}
代码示例来源:origin: multidots/android-app-common-tasks
/**
* Parse a URL query and fragment parameters into a key-value bundle.
*
* @param url the URL to parse
* @return a dictionary bundle of keys and values
*/
public static Map<String, String> parseUrl(String url) {
// hack to prevent MalformedURLException
url = url.replace("fbconnect", "http");
try {
URL u = new URL(url);
Map<String, String> params = decodeUrl(u.getQuery());
params.putAll(decodeUrl(u.getRef()));
return params;
} catch (MalformedURLException e) {
return new HashMap<>();
}
}
代码示例来源:origin: geotools/geotools
if (!"file".equals(url.getProtocol())) {
return null; // not a File URL
if (url.getQuery() != null) {
string = string.substring(0, string.indexOf("?"));
} else {
String auth = url.getAuthority();
String path2 = url.getPath();
try {
path2 = URLDecoder.decode(path2, java.nio.charset.StandardCharsets.UTF_8.name());
代码示例来源:origin: geotools/geotools
final String protocol = url.getProtocol();
if (protocol.equalsIgnoreCase("file")) pathname = URLs.urlToFile(url).getPath();
else {
final String query;
try {
query = java.net.URLDecoder.decode(url.getQuery().intern(), "UTF-8");
} catch (UnsupportedEncodingException e) {
if (LOGGER.isLoggable(Level.FINE))
代码示例来源: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: ltsopensource/light-task-scheduler
private static URL buildGetUrl(String strUrl, String query) throws IOException {
URL url = new URL(strUrl);
if (StringUtils.isEmpty(query)) {
return url;
}
if (StringUtils.isEmpty(url.getQuery())) {
if (strUrl.endsWith("?")) {
strUrl = strUrl + query;
} else {
strUrl = strUrl + "?" + query;
}
} else {
if (strUrl.endsWith("&")) {
strUrl = strUrl + query;
} else {
strUrl = strUrl + "&" + query;
}
}
return new URL(strUrl);
}
代码示例来源:origin: tomoya92/pybbs
String href = element.text();
if (href.contains("//www.youtube.com/watch")) {
URL aUrl = new URL(href);
String query = aUrl.getQuery();
Map<String, Object> querys = StringUtil.formatParams(query);
element.text("");
} else if (href.contains("//v.youku.com/v_show/")) {
element.text("");
URL aUrl = new URL(href);
String _href = "https://player.youku.com/embed/" + aUrl.getPath().replace("/v_show/id_", "").replace(".html", "");
element.addClass("embedded_video_wrapper");
element.append("<iframe class='embedded_video' src='" + _href + "' frameborder='0' allowfullscreen></iframe>");
代码示例来源:origin: geotools/geotools
protected RenderableSVG toRenderableSVG(String svgfile, URL svgUrl)
throws SAXException, IOException {
RenderableSVG svg;
String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
String svgUri = svgfile;
// Remove parameters from file URLs, as it is not supported by Windows
if ("file".equals(svgUrl.getProtocol()) && svgUrl.getQuery() != null) {
int idx = svgfile.indexOf('?');
if (idx > -1) {
svgUri = svgfile.substring(0, idx);
}
}
Document doc = f.createDocument(svgUri);
Map<String, String> parameters = getParametersFromUrl(svgfile);
if (!parameters.isEmpty() || hasParameters(doc.getDocumentElement())) {
replaceParameters(doc.getDocumentElement(), parameters);
}
svg = new RenderableSVG(doc);
return svg;
}
代码示例来源: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());
内容来源于网络,如有侵权,请联系作者删除!