Java Code Examples for java.net.URI#getScheme()
The following examples show how to use
java.net.URI#getScheme() .
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: AbstractFileStateBackend.java From flink with Apache License 2.0 | 7 votes |
/** * Checks the validity of the path's scheme and path. * * @param path The path to check. * @return The URI as a Path. * * @throws IllegalArgumentException Thrown, if the URI misses scheme or path. */ private static Path validatePath(Path path) { final URI uri = path.toUri(); final String scheme = uri.getScheme(); final String pathPart = uri.getPath(); // some validity checks if (scheme == null) { throw new IllegalArgumentException("The scheme (hdfs://, file://, etc) is null. " + "Please specify the file system scheme explicitly in the URI."); } if (pathPart == null) { throw new IllegalArgumentException("The path to store the checkpoint data in is null. " + "Please specify a directory path for the checkpoint data."); } if (pathPart.length() == 0 || pathPart.equals("/")) { throw new IllegalArgumentException("Cannot use the root directory for checkpoints."); } return path; }
Example 2
Source File: TestImgLocationResolver.java From scifio with BSD 2-Clause "Simplified" License | 6 votes |
@Override public TestImgLocation resolve(final URI uri) throws URISyntaxException { final String data; switch (uri.getScheme()) { case "scifioTestImg": data = uri.getHost() + "&" + uri.getQuery(); break; case "file": final String path = uri.getPath(); data = path.substring(0, path.length() - 5); // strip .fake extension break; default: throw new UnsupportedOperationException("Invalid scheme: " + uri.getScheme()); } final Map<String, Object> map = meta.parse(data); return TestImgLocation.fromMap(map); }
Example 3
Source File: ConfigClientUtils.java From incubator-gobblin with Apache License 2.0 | 6 votes |
/** * Build the URI based on the {@link ConfigStore} or input cnofigKeyURI * * @param configKeyPath : relative path to the input config store cs * @param returnURIWithAuthority : return the URI with input config store's authority and absolute path * @param cs : the config store of the input configKeyURI * @return : return the URI of the same format with the input configKeyURI * * for example, configKeyPath is /tags/retention, * with returnURIWithAuthority as false, return "etl-hdfs:///tags/retention * with returnURIWithAuthority as true , then return * etl-hdfs://eat1-nertznn01.grid.linkedin.com:9000/user/mitu/HdfsBasedConfigTest/tags/retention */ public static URI buildUriInClientFormat(ConfigKeyPath configKeyPath, ConfigStore cs, boolean returnURIWithAuthority) { try { if (!returnURIWithAuthority) { return new URI(cs.getStoreURI().getScheme(), null, configKeyPath.getAbsolutePathString(), null, null); } URI storeRoot = cs.getStoreURI(); // if configKeyPath is root, the configKeyPath.getAbsolutePathString().substring(1) will return "" and // will cause the Path creation failure if not handled here if (configKeyPath.isRootPath()) { return storeRoot; } Path absPath = new Path(storeRoot.getPath(), configKeyPath.getAbsolutePathString().substring(1)); // remote the first "/"; return new URI(storeRoot.getScheme(), storeRoot.getAuthority(), absPath.toString(), null, null); } catch (URISyntaxException e) { // should not come here throw new RuntimeException("Can not build URI based on " + configKeyPath); } }
Example 4
Source File: SeedProxySelector.java From seed with Mozilla Public License 2.0 | 6 votes |
@Override public List<Proxy> select(URI uri) { if (uri == null) { throw new IllegalArgumentException("URI can't be null."); } String protocol = uri.getScheme(); if (isNotExcluded(uri) && ("http".equalsIgnoreCase(protocol))) { return Lists.newArrayList(httpProxy); } else if (isNotExcluded(uri) && ("https".equalsIgnoreCase(protocol))) { return Lists.newArrayList(httpsProxy); } else if (defaultProxySelector != null) { return defaultProxySelector.select(uri); } else { return Lists.newArrayList(Proxy.NO_PROXY); } }
Example 5
Source File: PreferencesFragment.java From zxingfragmentlib with Apache License 2.0 | 6 votes |
private boolean isValid(Object newValue) { // Allow empty/null value if (newValue == null) { return true; } String valueString = newValue.toString(); if (valueString.isEmpty()) { return true; } // Before validating, remove custom placeholders, which will not // be considered valid parts of the URL in some locations: // Blank %t and %s: valueString = valueString.replaceAll("%[st]", ""); // Blank %f but not if followed by digit or a-f as it may be a hex sequence valueString = valueString.replaceAll("%f(?![0-9a-f])", ""); // Require a scheme otherwise: try { URI uri = new URI(valueString); return uri.getScheme() != null; } catch (URISyntaxException use) { return false; } }
Example 6
Source File: ExchangeServiceBase.java From ews-java-api with MIT License | 6 votes |
/** * Creates an HttpWebRequest instance from a pooling connection manager and initialises it with * the appropriate parameters, based on the configuration of this service object. * <p> * This is used for subscriptions. * </p> * * @param url The URL that the HttpWebRequest should target. * @param acceptGzipEncoding If true, ask server for GZip compressed content. * @param allowAutoRedirect If true, redirection response will be automatically followed. * @return An initialised instance of HttpWebRequest. * @throws ServiceLocalException the service local exception * @throws java.net.URISyntaxException the uRI syntax exception */ protected HttpWebRequest prepareHttpPoolingWebRequestForUrl(URI url, boolean acceptGzipEncoding, boolean allowAutoRedirect) throws ServiceLocalException, URISyntaxException { // Verify that the protocol is something that we can handle String scheme = url.getScheme(); if (!scheme.equalsIgnoreCase(EWSConstants.HTTP_SCHEME) && !scheme.equalsIgnoreCase(EWSConstants.HTTPS_SCHEME)) { String strErr = String.format("Protocol %s isn't supported for service request.", scheme); throw new ServiceLocalException(strErr); } if (httpPoolingClient == null) { initializeHttpPoolingClient(); } HttpClientWebRequest request = new HttpClientWebRequest(httpPoolingClient, httpContext); prepareHttpWebRequestForUrl(url, acceptGzipEncoding, allowAutoRedirect, request); return request; }
Example 7
Source File: SerialPortRegistry.java From smarthome with Eclipse Public License 2.0 | 6 votes |
/** * Gets the best applicable {@link SerialPortProvider} for the given <code>portName</code> * * @param portName The port's name. * @return all possible {@link SerialPortProvider}. If no provider is available an empty collection is returned */ public Collection<SerialPortProvider> getPortProvidersForPortName(URI portName) { final String scheme = portName.getScheme(); final PathType pathType = PathType.fromURI(portName); final Predicate<SerialPortProvider> filter; if (scheme != null) { // Get port providers which accept exactly the port with its scheme. filter = provider -> provider.getAcceptedProtocols().filter(prot -> prot.getScheme().equals(scheme)) .count() > 0; } else { // Get port providers which accept the same type (local, net) filter = provider -> provider.getAcceptedProtocols().filter(prot -> prot.getPathType().equals(pathType)) .count() > 0; } return portCreators.stream().filter(filter).collect(Collectors.toList()); }
Example 8
Source File: GerritOptions.java From copybara with Apache License 2.0 | 5 votes |
/** * Return the url removing the path part, since the API needs the host. */ private static URI hostUrl(String url) throws ValidationException { URI result = asUri(url); try { checkCondition(result.getHost() != null, "Wrong url: %s", url); checkCondition(result.getScheme() != null, "Wrong url: %s", url); return new URI(result.getScheme(), result.getUserInfo(), result.getHost(), result.getPort(), /*path=*/null, /*query=*/null, /*fragment=*/null); } catch (URISyntaxException e) { // Shouldn't happen throw new IllegalStateException(e); } }
Example 9
Source File: FileSystem.java From hadoop with Apache License 2.0 | 5 votes |
Key(URI uri, Configuration conf, long unique) throws IOException { scheme = uri.getScheme()==null ? "" : StringUtils.toLowerCase(uri.getScheme()); authority = uri.getAuthority()==null ? "" : StringUtils.toLowerCase(uri.getAuthority()); this.unique = unique; this.ugi = UserGroupInformation.getCurrentUser(); }
Example 10
Source File: Converter.java From ttt with BSD 2-Clause "Simplified" License | 5 votes |
public static boolean isStandardInput(URI uri) { String scheme = uri.getScheme(); if ((scheme == null) || !scheme.equals(uriFileDescriptorScheme)) return false; String schemeSpecificPart = uri.getSchemeSpecificPart(); if ((schemeSpecificPart == null) || !schemeSpecificPart.equals(uriFileDescriptorStandardIn)) return false; return true; }
Example 11
Source File: ProxyExchange.java From spring-cloud-gateway with Apache License 2.0 | 5 votes |
private void appendXForwarded(URI uri) { // Append the legacy headers if they were already added upstream String host = headers.getFirst("x-forwarded-host"); if (host == null) { return; } host = host + "," + uri.getHost(); headers.set("x-forwarded-host", host); String proto = headers.getFirst("x-forwarded-proto"); if (proto == null) { return; } proto = proto + "," + uri.getScheme(); headers.set("x-forwarded-proto", proto); }
Example 12
Source File: PrimitiveHadoopOperationHandler.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 5 votes |
public HadoopInfo(HadoopFileStatus file, String connectionId) throws IOException { this.file = file; URI tmp = file.getFile(); try { this.uri = new URI(tmp.getScheme(), connectionId, tmp.getPath(), null, null); } catch (URISyntaxException e) { throw new IOException(e); } }
Example 13
Source File: IdentityProviderManager.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
private String getTenantUrl(String url, String tenantDomain) throws URISyntaxException { URI uri = new URI(url); URI uriModified = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), ("/t/" + tenantDomain + uri.getPath()), uri.getQuery(), uri.getFragment()); return uriModified.toString(); }
Example 14
Source File: TestViewFileSystemDelegation.java From big-c with Apache License 2.0 | 5 votes |
private static FileSystem setupMockFileSystem(Configuration conf, URI uri) throws Exception { String scheme = uri.getScheme(); conf.set("fs." + scheme + ".impl", MockFileSystem.class.getName()); FileSystem fs = FileSystem.get(uri, conf); ConfigUtil.addLink(conf, "/mounts/" + scheme, uri); return ((MockFileSystem)fs).getRawFileSystem(); }
Example 15
Source File: FileSystem.java From RDFS with Apache License 2.0 | 5 votes |
Key(URI uri, Configuration conf, long unique) throws IOException { scheme = uri.getScheme()==null?"":uri.getScheme().toLowerCase(); authority = uri.getAuthority()==null?"":uri.getAuthority().toLowerCase(); this.unique = unique; UserGroupInformation ugi = UserGroupInformation.readFrom(conf); if (ugi == null) { try { ugi = UserGroupInformation.login(conf); } catch(LoginException e) { LOG.warn("uri=" + uri, e); } } username = ugi == null? null: ugi.getUserName(); }
Example 16
Source File: URIUtils.java From spark-sdk-android with Apache License 2.0 | 5 votes |
public static URI replaceQueryParameters(URI uri, String queryParams) { try { return new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), queryParams, uri.getFragment()); } catch (URISyntaxException e) { throw new IllegalArgumentException("Invalid URI/Scheme: replacing query parameters with '"+queryParams+"' for "+uri); } }
Example 17
Source File: GoalDao.java From careconnect-reference-implementation with Apache License 2.0 | 4 votes |
@Override public Goal create(FhirContext ctx, Goal goal, IdType theId, String theConditional) throws OperationOutcomeException { log.debug("Goal.save"); // log.info(ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(encounter)); GoalEntity goalEntity = null; if (goal.hasId()) goalEntity = readEntity(ctx, goal.getIdElement()); if (theConditional != null) { try { if (theConditional.contains("fhir.leedsth.nhs.uk/Id/goal")) { URI uri = new URI(theConditional); String scheme = uri.getScheme(); String host = uri.getHost(); String query = uri.getRawQuery(); log.debug(query); String[] spiltStr = query.split("%7C"); log.debug(spiltStr[1]); List<GoalEntity> results = searchEntity(ctx, null, new TokenParam().setValue(spiltStr[1]).setSystem("https://fhir.leedsth.nhs.uk/Id/goal"),null); for (GoalEntity con : results) { goalEntity = con; break; } } else { log.info("NOT SUPPORTED: Conditional Url = "+theConditional); } } catch (Exception ex) { } } if (goalEntity == null) goalEntity = new GoalEntity(); PatientEntity patientEntity = null; if (goal.hasSubject()) { log.trace(goal.getSubject().getReference()); patientEntity = patientDao.readEntity(ctx, new IdType(goal.getSubject().getReference())); goalEntity.setPatient(patientEntity); } if (goal.hasStatus()) { goalEntity.setStatus(goal.getStatus()); } em.persist(goalEntity); for (Identifier identifier : goal.getIdentifier()) { GoalIdentifier goalIdentifier = null; for (GoalIdentifier orgSearch : goalEntity.getIdentifiers()) { if (identifier.getSystem().equals(orgSearch.getSystemUri()) && identifier.getValue().equals(orgSearch.getValue())) { goalIdentifier = orgSearch; break; } } if (goalIdentifier == null) goalIdentifier = new GoalIdentifier(); goalIdentifier= (GoalIdentifier) libDao.setIdentifier(identifier, goalIdentifier ); goalIdentifier.setGoal(goalEntity); em.persist(goalIdentifier); } return goalEntityToFHIRGoalTransformer.transform(goalEntity); }
Example 18
Source File: OFSPath.java From hadoop-ozone with Apache License 2.0 | 4 votes |
private void initOFSPath(URI uri) { // Scheme is case-insensitive String scheme = uri.getScheme(); if (scheme != null) { if (!scheme.toLowerCase().equals(OZONE_OFS_URI_SCHEME)) { throw new ParseException("Can't parse schemes other than ofs://."); } } // authority could be empty authority = uri.getAuthority() == null ? "" : uri.getAuthority(); String pathStr = uri.getPath(); StringTokenizer token = new StringTokenizer(pathStr, OZONE_URI_DELIMITER); int numToken = token.countTokens(); if (numToken > 0) { String firstToken = token.nextToken(); // TODO: Compare a list of mounts in the future. if (firstToken.equals(OFS_MOUNT_NAME_TMP)) { mountName = firstToken; // TODO: Make this configurable in the future. volumeName = OFS_MOUNT_TMP_VOLUMENAME; try { bucketName = getTempMountBucketNameOfCurrentUser(); } catch (IOException ex) { throw new ParseException( "Failed to get temp bucket name for current user."); } } else if (numToken >= 2) { // Regular volume and bucket path volumeName = firstToken; bucketName = token.nextToken(); } else { // Volume only volumeName = firstToken; } } // Compose key name if (token.hasMoreTokens()) { keyName = token.nextToken("").substring(1); } }
Example 19
Source File: ConfigDescriptionGroupI18nUtil.java From openhab-core with Eclipse Public License 2.0 | 4 votes |
private String inferKey(URI configDescriptionURI, String groupName, String lastSegment) { String uri = configDescriptionURI.getSchemeSpecificPart().replace(":", "."); return configDescriptionURI.getScheme() + ".config." + uri + ".group." + groupName + "." + lastSegment; }
Example 20
Source File: FileSystems.java From jdk8u_jdk with GNU General Public License v2.0 | 3 votes |
/** * Returns a reference to an existing {@code FileSystem}. * * <p> This method iterates over the {@link FileSystemProvider#installedProviders() * installed} providers to locate the provider that is identified by the URI * {@link URI#getScheme scheme} of the given URI. URI schemes are compared * without regard to case. The exact form of the URI is highly provider * dependent. If found, the provider's {@link FileSystemProvider#getFileSystem * getFileSystem} method is invoked to obtain a reference to the {@code * FileSystem}. * * <p> Once a file system created by this provider is {@link FileSystem#close * closed} it is provider-dependent if this method returns a reference to * the closed file system or throws {@link FileSystemNotFoundException}. * If the provider allows a new file system to be created with the same URI * as a file system it previously created then this method throws the * exception if invoked after the file system is closed (and before a new * instance is created by the {@link #newFileSystem newFileSystem} method). * * <p> If a security manager is installed then a provider implementation * may require to check a permission before returning a reference to an * existing file system. In the case of the {@link FileSystems#getDefault * default} file system, no permission check is required. * * @param uri the URI to locate the file system * * @return the reference to the file system * * @throws IllegalArgumentException * if the pre-conditions for the {@code uri} parameter are not met * @throws FileSystemNotFoundException * if the file system, identified by the URI, does not exist * @throws ProviderNotFoundException * if a provider supporting the URI scheme is not installed * @throws SecurityException * if a security manager is installed and it denies an unspecified * permission */ public static FileSystem getFileSystem(URI uri) { String scheme = uri.getScheme(); for (FileSystemProvider provider: FileSystemProvider.installedProviders()) { if (scheme.equalsIgnoreCase(provider.getScheme())) { return provider.getFileSystem(uri); } } throw new ProviderNotFoundException("Provider \"" + scheme + "\" not found"); }