List of usage examples for java.net URL getAuthority
public String getAuthority()
From source file:MainClass.java
public static void main(String[] args) { try {/*from w ww . ja v a 2 s. c o m*/ URL url = new URL("http://www.java2s.com"); System.out.println("URL is " + url.toString()); System.out.println("authority is " + url.getAuthority()); System.out.println("path is " + url.getPath()); System.out.println("default port is " + url.getDefaultPort()); System.out.println("query is " + url.getQuery()); System.out.println("ref is " + url.getRef()); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { try {//from w ww. ja v a2s . c om URL url = new URL("http://www.java2s.com/query?abc=def"); System.out.println("URL is " + url.toString()); System.out.println("authority is " + url.getAuthority()); System.out.println("default port is " + url.getDefaultPort()); System.out.println("query is " + url.getQuery()); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { URL url = new URL(args[0]); System.out.println("URL is " + url.toString()); System.out.println("protocol is " + url.getProtocol()); System.out.println("authority is " + url.getAuthority()); System.out.println("file name is " + url.getFile()); System.out.println("host is " + url.getHost()); System.out.println("path is " + url.getPath()); System.out.println("port is " + url.getPort()); System.out.println("default port is " + url.getDefaultPort()); System.out.println("query is " + url.getQuery()); System.out.println("ref is " + url.getRef()); }
From source file:at.fhooe.mcm.webdav.WebDavInterface.java
public static void main(String[] args) throws Exception { URL x = new URL("http://USER:PASSWORD@privatenotes.dyndns-server.com/webdav2/USER"); System.out.println(x.getAuthority()); /*/*from w ww . j a v a 2 s . c o m*/ WebDavInterface wdi = new WebDavInterface("http://USER:PW@privatenotes.dyndns-server.com/webdav2/USER"); Vector<String> children = wdi.getAllChildren(); for (String c : children) { System.out.println(c); } wdi.download("manifest.xml", new File("D:/mymanifest.xml")); wdi.upload(new File("D:/hello.txt"), "supersecretNOT.txt");*/ }
From source file:com.magnet.plugin.helpers.UrlParser.java
public static ParsedUrl parseUrl(String url) { List<PathPart> pathParts = new ArrayList<PathPart>(); List<Query> queries = new ArrayList<Query>(); ParsedUrl parsedUrl;/*from ww w . j a v a 2s .co m*/ String base; try { URL aURL = new URL(url); base = aURL.getAuthority(); String protocol = aURL.getProtocol(); parsedUrl = new ParsedUrl(); parsedUrl.setPathWithEndingSlash(aURL.getPath().endsWith("/")); parsedUrl.setBase(protocol + "://" + base); List<NameValuePair> pairs = URLEncodedUtils.parse(aURL.getQuery(), Charset.defaultCharset()); for (NameValuePair pair : pairs) { Query query = new Query(pair.getName(), pair.getValue()); queries.add(query); } parsedUrl.setQueries(queries); String[] pathStrings = aURL.getPath().split("/"); for (String pathPart : pathStrings) { Matcher m = PATH_PARAM_PATTERN.matcher(pathPart); if (m.find()) { String paramDef = m.group(1); String[] paramParts = paramDef.split(":"); if (paramParts.length > 1) { pathParts.add(new PathPart(paramParts[1].trim(), paramParts[0].trim())); } else { pathParts.add(new PathPart(paramParts[0].trim())); } } else { if (!pathPart.isEmpty()) { pathParts.add(new PathPart(pathPart)); } } } parsedUrl.setPathParts(pathParts); } catch (Exception ex) { Logger.error(UrlParser.class, "Can't parse URL " + url); return null; } return parsedUrl; }
From source file:com.magnet.plugin.r2m.helpers.UrlParser.java
public static ParsedUrl parseUrl(String url) { List<PathPart> pathParts = new ArrayList<PathPart>(); List<Query> queries = new ArrayList<Query>(); ParsedUrl parsedUrl;//w w w .j a va 2 s . c om String base; try { URL aURL = new URL(url); base = aURL.getAuthority(); String protocol = aURL.getProtocol(); parsedUrl = new ParsedUrl(); parsedUrl.setPathWithEndingSlash(aURL.getPath().endsWith("/")); parsedUrl.setBaseUrl(protocol + "://" + base); List<NameValuePair> pairs = URLEncodedUtils.parse(aURL.getQuery(), Charset.defaultCharset()); for (NameValuePair pair : pairs) { Query query = new Query(pair.getName(), pair.getValue()); queries.add(query); } parsedUrl.setQueries(queries); String[] pathStrings = aURL.getPath().split("/"); for (String pathPart : pathStrings) { Matcher m = PATH_PARAM_PATTERN.matcher(pathPart); if (m.find()) { String paramDef = m.group(1); String[] paramParts = paramDef.split(":"); if (paramParts.length > 1) { pathParts.add(new PathPart(paramParts[1].trim(), paramParts[0].trim())); } else { pathParts.add(new PathPart(paramParts[0].trim())); } } else { if (!pathPart.isEmpty()) { pathParts.add(new PathPart(pathPart)); } } } parsedUrl.setPathParts(pathParts); } catch (Exception ex) { Logger.error(UrlParser.class, R2MMessages.getMessage("CANNOT_PARSE_URL", url)); return null; } return parsedUrl; }
From source file:org.apache.maven.wagon.shared.http.EncodingUtil.java
/** * Parses and returns an encoded version of the given URL string. * * @param url Raw/decoded string form of a URL to parse/encode. * @return Parsed/encoded {@link URI} that represents the string form URL passed in. * @throws MalformedURLException/* www. j ava2 s. c o m*/ * @throws URISyntaxException */ public static URI encodeURL(String url) throws MalformedURLException, URISyntaxException { URL urlObject = new URL(url); URI uriEncoded = new URI(urlObject.getProtocol(), // urlObject.getAuthority(), // urlObject.getPath(), // urlObject.getQuery(), // urlObject.getRef()); return uriEncoded; }
From source file:org.andstatus.app.util.UrlUtils.java
public static boolean isHostOnly(URL url) { return url != null && TextUtils.isEmpty(url.getFile()) && url.getHost().contentEquals(url.getAuthority()); }
From source file:FainClasses.HttpBasicAuth.java
public static void auth() { String sHTML = "Can not load page"; URL url; InputStream is;//from w w w. j ava2 s .com BufferedReader buff = null; try { url = new URL("http://vrgaz.ru/lk/index.php?page=ls&lss=1600013620"); url.getAuthority(); String encoding = Base64.encodeBase64String("md_dimka@mail.ru:ufpyflt;ls".getBytes()); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setDoOutput(true); connection.setRequestProperty("Cookie", "PHPSESSID=343266771f5de3a489ba82fe79809854"); // connection. //connection.setRequestProperty("Authorization", "Basic " + encoding); /*connection.setRequestProperty("avl","md_dimka@mail.ru"); connection.setRequestProperty("avp","ufpyflt;ls"); */ //connection.setRequestProperty("page", "ls"); //connection.setRequestProperty("lss", "1600013620"); //URL url = new URL("http://vrgaz.ru/lk/"); // url = new URL(sUrl); //is = url.openStream(); is = connection.getInputStream(); buff = new BufferedReader(new InputStreamReader(is, "windows-1251")); StringBuilder page = new StringBuilder(); String tmp; while ((tmp = buff.readLine()) != null) { page.append(tmp).append("\n"); } sHTML = page.toString(); System.out.println(sHTML); // InputStream content = (InputStream) connection.getInputStream(); // BufferedReader in // = new BufferedReader(new InputStreamReader(content)); // String line; // while ((line = in.readLine()) != null) { // System.out.println(line); // } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.ibm.jaggr.core.util.PathUtil.java
/** * Convenience method to convert a URL to a URI that doesn't throw a * URISyntaxException if the path component for the URL contains * spaces (like {@link URL#toURI()} does). * * @param url The input URL//from w w w .j a va2 s . c o m * @return The URI * @throws URISyntaxException */ public static URI url2uri(URL url) throws URISyntaxException { return new URI(url.getProtocol(), url.getAuthority(), url.getPath(), url.getQuery(), url.getRef()); }