Java Code Examples for java.net.URI#toString()
The following examples show how to use
java.net.URI#toString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProjectContentsLocationArea.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
/** * Return the path we are going to display. If it is a file URI then remove the file prefix. * * @return String */ private String getDefaultPathDisplayString() { URI defaultURI = null; if (existingProject != null) { defaultURI = existingProject.getLocationURI(); } // Handle files specially. Assume a file if there is no project to query if (defaultURI == null || defaultURI.getScheme().equals(FILE_SCHEME)) { return Platform.getLocation().append(projectName).toOSString(); } return defaultURI.toString(); }
Example 2
Source File: ZxtMediaPlayer.java From TVRemoteIME with GNU General Public License v2.0 | 6 votes |
synchronized public void setURI(URI uri, String type, String name, String currentURIMetaData) { Log.i(TAG, "setURI " + uri); currentMediaInfo = new MediaInfo(uri.toString(),currentURIMetaData); currentPositionInfo = new PositionInfo(1, "", uri.toString()); getAvTransportLastChange().setEventedValue(getInstanceId(), new AVTransportVariable.AVTransportURI(uri), new AVTransportVariable.CurrentTrackURI(uri)); transportStateChanged(TransportState.STOPPED); IJKPlayer.setMediaListener(new GstMediaListener()); Intent intent = new Intent(); intent.setClass(mContext, RenderPlayerService.class); intent.putExtra("type", type); intent.putExtra("name", name); intent.putExtra("playURI", uri.toString()); mContext.startService(intent); }
Example 3
Source File: SFTPFileSystemProvider.java From sftp-fs with Apache License 2.0 | 6 votes |
/** * Constructs a new {@code FileSystem} object identified by a URI. * <p> * The URI must have a {@link URI#getScheme() scheme} equal to {@link #getScheme()}, and no {@link URI#getUserInfo() user information}, * {@link URI#getPath() path}, {@link URI#getQuery() query} or {@link URI#getFragment() fragment}. Authentication credentials must be set through * the given environment map, preferably through {@link SFTPEnvironment}. * <p> * This provider allows multiple file systems per host, but only one file system per user on a host. * Once a file system is {@link FileSystem#close() closed}, this provider allows a new file system to be created with the same URI and credentials * as the closed file system. */ @Override @SuppressWarnings("resource") public FileSystem newFileSystem(URI uri, Map<String, ?> env) throws IOException { // user info must come from the environment map checkURI(uri, false, false); SFTPEnvironment environment = wrapEnvironment(env); String username = environment.getUsername(); URI normalizedURI = normalizeWithUsername(uri, username); synchronized (fileSystems) { if (fileSystems.containsKey(normalizedURI)) { throw new FileSystemAlreadyExistsException(normalizedURI.toString()); } SFTPFileSystem fs = new SFTPFileSystem(this, normalizedURI, environment); fileSystems.put(normalizedURI, fs); return fs; } }
Example 4
Source File: RheemPlansOperators.java From rheem with Apache License 2.0 | 6 votes |
public static RheemPlan distinct(URI inputFileUri1, Collection<String> collector){ TextFileSource source = new TextFileSource(inputFileUri1.toString()); MapOperator<String, String> mapOperator = new MapOperator<String, String>( line -> { return line.toLowerCase(); }, String.class, String.class ); DistinctOperator<String> distinctOperator = new DistinctOperator<String>(String.class); LocalCallbackSink<String> sink = LocalCallbackSink.createCollectingSink(collector, String.class); source.connectTo(0, mapOperator, 0); mapOperator.connectTo(0, distinctOperator, 0); distinctOperator.connectTo(0, sink, 0); return new RheemPlan(sink); }
Example 5
Source File: TransformInputOutput.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
protected static EntityResolver createRelativePathResolver(final String workingDirectory) { return new EntityResolver() { public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { if (systemId != null && systemId.startsWith("file:/")) { URI workingDirectoryURI = new File(workingDirectory).toURI(); URI workingFile; try { // Construction new File(new URI(String)).toURI() is used to be sure URI has correct representation without redundant '/' workingFile = convertToNewWorkingDirectory(currentJavaWorkingDirectory, workingDirectoryURI, new File(new URI(systemId)).toURI()); return new InputSource(workingFile.toString()); } catch (URISyntaxException ex) { //Should not get here } } return null; } }; }
Example 6
Source File: TransformInputOutput.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
protected static EntityResolver createRelativePathResolver(final String workingDirectory) { return new EntityResolver() { public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { if (systemId != null && systemId.startsWith("file:/")) { URI workingDirectoryURI = new File(workingDirectory).toURI(); URI workingFile; try { // Construction new File(new URI(String)).toURI() is used to be sure URI has correct representation without redundant '/' workingFile = convertToNewWorkingDirectory(currentJavaWorkingDirectory, workingDirectoryURI, new File(new URI(systemId)).toURI()); return new InputSource(workingFile.toString()); } catch (URISyntaxException ex) { //Should not get here } } return null; } }; }
Example 7
Source File: SFTPFileSystemProvider.java From sftp-fs with Apache License 2.0 | 5 votes |
private SFTPFileSystem getExistingFileSystem(URI uri) { URI normalizedURI = normalizeWithoutPassword(uri); synchronized (fileSystems) { SFTPFileSystem fs = fileSystems.get(normalizedURI); if (fs == null) { throw new FileSystemNotFoundException(uri.toString()); } return fs; } }
Example 8
Source File: Goto.java From JVoiceXML with GNU Lesser General Public License v2.1 | 5 votes |
/** * Set the next attribute. * @param uri Value of the next attribute. * @see #ATTRIBUTE_NEXT */ public void setNext(final URI uri) { final String next; if (uri == null) { next = null; } else { next = uri.toString(); } setNext(next); }
Example 9
Source File: GitRepositoryAwareWorkingSetManager.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Returns with the {@link URI#toString()} of the argument. Trims the trailing forward slash if any. */ private static String toUriString(final URI uri) { final String uriString = uri.toString(); final int length = uriString.length(); if (uriString.charAt(length - 1) == '/') { return uriString.substring(0, length - 1); } return uriString; }
Example 10
Source File: HostedSiteServlet.java From orion.server with Eclipse Public License 1.0 | 5 votes |
private String mapLocation(String location) { Map<String, List<String>> mappings = site.getMappings(); String bestMatch = ""; String prefix = null; for (Iterator<Entry<String, List<String>>> iterator = mappings.entrySet().iterator(); iterator.hasNext();) { Entry<String, List<String>> entry = iterator.next(); List<String> candidates = entry.getValue(); for (Iterator<String> candidateIt = candidates.iterator(); candidateIt.hasNext();) { String candidate = candidateIt.next(); if (location.startsWith(candidate) && candidate.length() > bestMatch.length()) { bestMatch = candidate; prefix = entry.getKey(); } } } if (prefix != null) { String suffix = location.substring(bestMatch.length()); String separator = suffix.length() > 0 && !prefix.endsWith("/") && !suffix.startsWith("/") ? "/" : ""; String reverseMappedPath = prefix + separator + suffix; try { URI pathlessRequestURI = new URI(request.getScheme(), null, request.getServerName(), request.getServerPort(), null, null, null); return pathlessRequestURI.toString() + reverseMappedPath; } catch (URISyntaxException t) { // best effort System.err.println(t); } } return location; }
Example 11
Source File: NettyTcpTransportFactoryTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout = 30000) public void testCreateWithCustomOptions() throws Exception { URI BASE_URI = new URI("tcp://localhost:5672"); URI configuredURI = new URI(BASE_URI.toString() + "?" + "transport.connectTimeout=" + CUSTOM_CONNECT_TIMEOUT + "&" + "transport.sendBufferSize=" + CUSTOM_SEND_BUFFER_SIZE + "&" + "transport.receiveBufferSize=" + CUSTOM_RECEIVE_BUFFER_SIZE + "&" + "transport.trafficClass=" + CUSTOM_TRAFFIC_CLASS + "&" + "transport.tcpNoDelay=" + CUSTOM_TCP_NO_DELAY + "&" + "transport.tcpKeepAlive=" + CUSTOM_TCP_KEEP_ALIVE + "&" + "transport.soLinger=" + CUSTOM_SO_LINGER + "&" + "transport.soTimeout=" + CUSTOM_SO_TIMEOUT + "&" + "transport.localAddress=" + CUSTOM_LOCAL_ADDRESS + "&" + "transport.localPort=" + CUSTOM_LOCAL_PORT); NettyTcpTransportFactory factory = new NettyTcpTransportFactory(); Transport transport = factory.createTransport(configuredURI); assertNotNull(transport); assertTrue(transport instanceof NettyTcpTransport); assertFalse(transport.isConnected()); TransportOptions options = transport.getTransportOptions(); assertNotNull(options); assertEquals(CUSTOM_CONNECT_TIMEOUT, options.getConnectTimeout()); assertEquals(CUSTOM_SEND_BUFFER_SIZE, options.getSendBufferSize()); assertEquals(CUSTOM_RECEIVE_BUFFER_SIZE, options.getReceiveBufferSize()); assertEquals(CUSTOM_TRAFFIC_CLASS, options.getTrafficClass()); assertEquals(CUSTOM_TCP_NO_DELAY, options.isTcpNoDelay()); assertEquals(CUSTOM_TCP_KEEP_ALIVE, options.isTcpKeepAlive()); assertEquals(CUSTOM_SO_LINGER, options.getSoLinger()); assertEquals(CUSTOM_SO_TIMEOUT, options.getSoTimeout()); }
Example 12
Source File: Test.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private Test(String s, String h, String p, String f) { testCount++; try { uri = new URI(s, h, p, f); } catch (URISyntaxException x) { exc = x; input = x.getInput(); } if (uri != null) input = uri.toString(); originalURI = uri; }
Example 13
Source File: O365Authenticator.java From davmail with GNU General Public License v2.0 | 5 votes |
public static String buildAuthorizeUrl(String tenantId, String clientId, String redirectUri, String username) throws IOException { URI uri; try { URIBuilder uriBuilder = new URIBuilder() .setScheme("https") .setHost("login.microsoftonline.com") .addParameter("client_id", clientId) .addParameter("response_type", "code") .addParameter("redirect_uri", redirectUri) .addParameter("response_mode", "query") .addParameter("login_hint", username); // force consent //uriBuilder.addParameter("prompt", "consent") // switch to new v2.0 OIDC compliant endpoint https://docs.microsoft.com/en-us/azure/active-directory/develop/azure-ad-endpoint-comparison if (Settings.getBooleanProperty("davmail.enableOidc", false)) { uriBuilder.setPath("/" + tenantId + "/oauth2/v2.0/authorize") .addParameter("scope", "openid https://outlook.office365.com/EWS.AccessAsUser.All"); } else { uriBuilder.setPath("/" + tenantId + "/oauth2/authorize") .addParameter("resource", RESOURCE); } uri = uriBuilder.build(); } catch (URISyntaxException e) { throw new IOException(e); } return uri.toString(); }
Example 14
Source File: JFXProjectGenerator.java From netbeans with Apache License 2.0 | 5 votes |
/** append path to given jar root uri */ private static URI appendJarFolder(URI u, String jarFolder) { try { if (u.isAbsolute()) { return new URI("jar:" + u.toString() + "!/" + (jarFolder == null ? "" : jarFolder.replace('\\', '/'))); // NOI18N } else { return new URI(u.toString() + "!/" + (jarFolder == null ? "" : jarFolder.replace('\\', '/'))); // NOI18N } } catch (URISyntaxException e) { throw new AssertionError(e); } }
Example 15
Source File: OlatJerseyTestCase.java From olat with Apache License 2.0 | 5 votes |
public PostMethod createPost(final URI requestURI, final String accept, final boolean cookie) { final PostMethod method = new PostMethod(requestURI.toString()); if (cookie) { method.getParams().setCookiePolicy(CookiePolicy.RFC_2109); } if (StringHelper.containsNonWhitespace(accept)) { method.addRequestHeader("Accept", accept); } return method; }
Example 16
Source File: RestSteps.java From cucumber-rest-steps with MIT License | 5 votes |
private void call(String httpMethodString, URI uri, Object requestObj) throws JSONException { HttpMethod httpMethod = HttpMethod.valueOf(httpMethodString.toUpperCase()); if (httpMethod.equals(HttpMethod.GET) && requestObj != null) { throw new IllegalArgumentException("You can't pass data in a GET call"); } final String path = uri.toString(); if (path.contains("$.")) { initExpectBody(); Pattern pattern = Pattern.compile("(((\\$.*)\\/.*)|(\\$.*))"); Matcher matcher = pattern.matcher(path); assertTrue(matcher.find()); final String jsonPath = matcher.group(0); final byte[] responseBody = expectBody.jsonPath(jsonPath).exists().returnResult().getResponseBody(); final String value = ((JSONObject) JSONParser.parseJSON(new String(responseBody))).getString(jsonPath.replace("$.", "")); uri = URI.create(path.replace(jsonPath, value)); } final RequestBodySpec requestBodySpec = webClient.method(httpMethod).uri(uri); if (requestObj != null) { requestBodySpec.syncBody(requestObj); requestBodySpec.contentType(MediaType.APPLICATION_JSON); } if (headers != null) { headers.forEach((key, value) -> requestBodySpec.header(key, value.toArray(new String[0]))); } responseSpec = requestBodySpec.exchange(); expectBody = null; headers = null; }
Example 17
Source File: SubredditRequestFailure.java From RedReader with GNU General Public License v3.0 | 4 votes |
public SubredditRequestFailure(@CacheRequest.RequestFailureType int requestFailureType, Throwable t, Integer statusLine, String readableMessage, URI url) { this(requestFailureType, t, statusLine, readableMessage, url != null ? url.toString() : null); }
Example 18
Source File: GetAppCommand.java From orion.server with Eclipse Public License 1.0 | 4 votes |
public ServerStatus _doIt() { try { List<Object> key = Arrays.asList(target, name); app = appCache.get(key); if (app != null) { return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, this.app.toJSON()); } URI targetURI = URIUtil.toURI(target.getUrl()); // Find the app String appsUrl = target.getSpace().getCFJSON().getJSONObject("entity").getString("apps_url"); URI appsURI = targetURI.resolve(appsUrl); GetMethod getAppsMethod = new GetMethod(appsURI.toString()); ServerStatus confStatus = HttpUtil.configureHttpMethod(getAppsMethod, target.getCloud()); if (!confStatus.isOK()) return confStatus; getAppsMethod.setQueryString("q=name:" + URLEncoder.encode(name, "UTF8") + "&inline-relations-depth=1"); ServerStatus getStatus = HttpUtil.executeMethod(getAppsMethod); if (!getStatus.isOK()) return getStatus; JSONObject apps = getStatus.getJsonData(); if (!apps.has("resources") || apps.getJSONArray("resources").length() == 0) return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, "Application not found", null); // Get more details about the app JSONObject appJSON = apps.getJSONArray("resources").getJSONObject(0).getJSONObject("metadata"); String summaryAppUrl = appJSON.getString("url") + "/summary"; URI summaryAppURI = targetURI.resolve(summaryAppUrl); GetMethod getSummaryMethod = new GetMethod(summaryAppURI.toString()); confStatus = HttpUtil.configureHttpMethod(getSummaryMethod, target.getCloud()); if (!confStatus.isOK()) return confStatus; getStatus = HttpUtil.executeMethod(getSummaryMethod); if (!getStatus.isOK()) return getStatus; JSONObject summaryJSON = getStatus.getJsonData(); // instances String instancesUrl = appJSON.getString("url") + "/instances"; URI instancesURI = targetURI.resolve(instancesUrl); GetMethod getInstancesMethod = new GetMethod(instancesURI.toString()); confStatus = HttpUtil.configureHttpMethod(getInstancesMethod, target.getCloud()); if (!confStatus.isOK()) return confStatus; getStatus = HttpUtil.executeMethod(getInstancesMethod); JSONObject instancesJSON = getStatus.getJsonData(); this.app = new App(); this.app.setAppJSON(appJSON); this.app.setSummaryJSON(summaryJSON); this.app.setName(summaryJSON.getString("name")); this.app.setGuid(summaryJSON.getString("guid")); appCache.put(key, app); JSONObject result = this.app.toJSON(); result.put("instances_details", instancesJSON); return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, this.app.toJSON()); } catch (Exception e) { String msg = NLS.bind("An error occured when performing operation {0}", commandName); //$NON-NLS-1$ logger.error(msg, e); return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e); } }
Example 19
Source File: RoundtripIT.java From fcrepo-import-export with Apache License 2.0 | 4 votes |
@Test public void testRoundtripBinaries() throws Exception { final UUID uuid = UUID.randomUUID(); final String baseURI = serverAddress + uuid; final URI res1 = URI.create(baseURI); final URI file1 = URI.create(baseURI + "/file1"); final Resource container = createResource(res1.toString()); final Resource binary = createResource(file1.toString()); final String file1patch = "insert data { " + "<" + file1.toString() + "> <" + SKOS_PREFLABEL + "> \"original version\" . }"; create(res1); final FcrepoResponse resp = createBody(file1, "this is some content", "text/plain"); final URI file1desc = resp.getLinkHeaders("describedby").get(0); patch(file1desc, file1patch); final Config config = roundtrip(URI.create(baseURI), true); // verify that files exist and contain expected content final File exportDir = config.getBaseDirectory(); final File containerFile = new File(exportDir, ROOT_PATH + uuid + config.getRdfExtension()); final File binaryFile = new File(exportDir, ROOT_PATH + uuid + "/file1.binary"); final File descFile = new File(exportDir, ROOT_PATH + uuid + "/file1/fcr%3Ametadata" + config.getRdfExtension()); assertTrue(containerFile.exists() && containerFile.isFile()); final Model contModel = loadModel(containerFile.getAbsolutePath()); assertTrue(contModel.contains(container, RDF_TYPE, CONTAINER)); assertTrue(binaryFile.exists() && binaryFile.isFile()); assertEquals("this is some content", IOUtils.toString(new FileInputStream(binaryFile))); assertEquals(20L, binaryFile.length()); assertTrue(descFile.exists() && descFile.isFile()); final Model descModel = loadModel(descFile.getAbsolutePath()); assertTrue(descModel.contains(binary, RDF_TYPE, NON_RDF_SOURCE)); // verify that the resources exist in the repository assertTrue(exists(res1)); assertTrue(exists(file1)); final Model model = getAsModel(file1desc); assertTrue(model.contains(binary, RDF_TYPE, createResource(LDP_NON_RDF_SOURCE))); assertTrue(model.contains(binary, createProperty(SKOS_PREFLABEL), "original version")); assertTrue(model.contains(binary, createProperty(PREMIS_DIGEST), createResource("urn:sha1:5ec1a3cb71c75c52cf23934b137985bd2499bd85"))); }
Example 20
Source File: CoapClient.java From SI with BSD 2-Clause "Simplified" License | 2 votes |
/** * Constructs a new CoapClient that sends request to the specified URI. * * @param uri the uri */ public CoapClient(URI uri) { this(uri.toString()); }