java.net.URI#getScheme ( )源码实例Demo

下面列出了java.net.URI#getScheme ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: flink   文件: AbstractFileStateBackend.java
/**
 * 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;
}
 
源代码2 项目: seed   文件: SeedProxySelector.java
@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);
    }
}
 
源代码3 项目: zxingfragmentlib   文件: PreferencesFragment.java
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;
  }
}
 
源代码4 项目: smarthome   文件: SerialPortRegistry.java
/**
 * 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());
}
 
源代码5 项目: ews-java-api   文件: ExchangeServiceBase.java
/**
 * 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;
}
 
源代码6 项目: incubator-gobblin   文件: ConfigClientUtils.java
/**
 * 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);
  }
}
 
源代码7 项目: scifio   文件: TestImgLocationResolver.java
@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);
}
 
源代码8 项目: spark-sdk-android   文件: URIUtils.java
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);
    }
}
 
源代码9 项目: RDFS   文件: FileSystem.java
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();
}
 
源代码10 项目: big-c   文件: TestViewFileSystemDelegation.java
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();
}
 
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();
    }
 
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);
	}
}
 
源代码13 项目: spring-cloud-gateway   文件: ProxyExchange.java
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);
}
 
源代码14 项目: ttt   文件: Converter.java
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;
}
 
源代码15 项目: hadoop   文件: FileSystem.java
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();
}
 
源代码16 项目: copybara   文件: GerritOptions.java
/**
 * 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);
  }
}
 
private String inferKey(URI configDescriptionURI, String groupName, String lastSegment) {
    String uri = configDescriptionURI.getSchemeSpecificPart().replace(":", ".");
    return configDescriptionURI.getScheme() + ".config." + uri + ".group." + groupName + "." + lastSegment;
}
 
源代码18 项目: hadoop-ozone   文件: OFSPath.java
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);
  }
}
 
@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);
}
 
源代码20 项目: jdk8u_jdk   文件: FileSystems.java
/**
 * 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");
}