List of usage examples for java.net URI URI
public URI(String scheme, String host, String path, String fragment) throws URISyntaxException
From source file:Main.java
public static void main(String[] args) throws URISyntaxException { URI uri = new URI("http", "java2s.com", "/path", "fragment"); System.out.println(uri);//from ww w . j a v a 2s .c o m }
From source file:Main.java
public static String buildUri(String host, String path) { try {/*from w w w .ja v a 2s .c om*/ return new URI("https", host, "/" + path, null).toASCIIString(); } catch (URISyntaxException ex) { throw new AssertionError("URI creation failed, host=" + host + ", path=" + path, ex); } }
From source file:com.blacklocus.jres.strings.JresPaths.java
/** * @return fragments encoded as valid URI path sections, each appended with '/' if not present. <code>null</code>s * upgraded to empty strings. Appends nothing to blank strings (and nulls). Any leading slashes will be dropped. *///from w ww. j a v a2 s . c o m public static String slashedPath(String... fragments) { String slashed = slashed(fragments); try { // Encode (anything that needs to be) in the path. Surprisingly this works. String encodedPath = new URI(null, null, slashed, null).getRawPath(); // Strip leading slash. Omitting it is slightly more portable where URIs are being constructed. return encodedPath.startsWith("/") ? encodedPath.substring(1) : encodedPath; } catch (URISyntaxException e) { throw new RuntimeException(e); } }
From source file:org.wwscc.registration.attendance.Attendance.java
/** * Retrieve the attendance report from the main host * @param host the hostname to retrieve from * @throws IOException //from ww w . j a va 2 s .c o m * @throws URISyntaxException * @throws UnsupportedEncodingException */ public static void getAttendance(String host) throws IOException, URISyntaxException { DefaultHttpClient httpclient = new DefaultHttpClient(); HttpProtocolParams.setUserAgent(httpclient.getParams(), "Scorekeeper/2.0"); MonitorProgressStream monitor = new MonitorProgressStream("Download Attendance"); monitor.setProgress(1); monitor.setNote("Initialize"); HttpPost request = new HttpPost(new URI("http", host, "/history/attendance", null)); File temp = File.createTempFile("attendance", "tmp"); monitor.setProgress(2); monitor.setNote("Connecting/Calcuation..."); HttpEntity download = httpclient.execute(request).getEntity(); monitor.setProgress(3); monitor.setNote("Downloading..."); FileOutputStream todisk = new FileOutputStream(temp); monitor.setStream(todisk, download.getContentLength()); download.writeTo(monitor); FileUtils.copyFile(temp, defaultfile); }
From source file:com.cloud.utils.UriUtils.java
public static String formNfsUri(String host, String path) { try {/*from w w w .j a v a 2 s.c o m*/ URI uri = new URI("nfs", host, path, null); return uri.toString(); } catch (URISyntaxException e) { throw new CloudRuntimeException("Unable to form nfs URI: " + host + " - " + path); } }
From source file:com.pinterest.terrapin.hadoop.HdfsUploader.java
public HdfsUploader(TerrapinUploaderOptions uploaderOptions, String absoluteHdfsDir) throws IOException, URISyntaxException { super(uploaderOptions); Path hdfsPathTmp = new Path(absoluteHdfsDir); URI namenodeUri = new URI(hdfsPathTmp.toUri().getScheme(), hdfsPathTmp.toUri().getAuthority(), null, null); this.dfsClient = new DFSClient(namenodeUri, new Configuration()); this.hdfsDir = new Path(hdfsPathTmp.toUri().getPath()); }