java.net.URI.toString()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(295)

本文整理了Java中java.net.URI.toString()方法的一些代码示例,展示了URI.toString()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。URI.toString()方法的具体详情如下:
包路径:java.net.URI
类名称:URI
方法名:toString

URI.toString介绍

[英]Returns the encoded URI.
[中]返回编码的URI。

代码示例

代码示例来源:origin: spring-projects/spring-framework

/**
 * Insert a base URL (if configured) unless the given URL has a host already.
 */
private URI insertBaseUrl(URI url) {
  try {
    String baseUrl = getBaseUrl();
    if (baseUrl != null && url.getHost() == null) {
      url = new URI(baseUrl + url.toString());
    }
    return url;
  }
  catch (URISyntaxException ex) {
    throw new IllegalArgumentException("Invalid URL after inserting base URL: " + url, ex);
  }
}

代码示例来源:origin: AdoptOpenJDK/jitwatch

public static String getJVMSCSSURL()
{
  File cssFile = new File(JVMS_CSS_FILENAME);
  if (cssFile.exists())
  {
    return cssFile.toURI().toString();
  }
  else
  {
    return null;
  }
}

代码示例来源:origin: gocd/gocd

protected String hostInfoForCommandline() {
  try {
    URI uri = new URI(url);
    if (uri.getUserInfo() != null) {
      //(String scheme, String userInfo, String host, int port, String path, String query, String fragment)
      uri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, null);
    }
    return uri.toString();
  } catch (URISyntaxException e) {
    // In subversion we may have a file path that is not actually a URL
    return url;
  }
}

代码示例来源:origin: deeplearning4j/nd4j

@Override
  public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
    URI fileUri = file.toUri();
    String s = fileUri.toString();
    if(s.endsWith(GIT_PROPERTY_FILE_SUFFIX)){
      out.add(fileUri);
    }
    return FileVisitResult.CONTINUE;
  }
});

代码示例来源:origin: spring-cloud/spring-cloud-config

private List<String> matchingDirectories(File dir, String value) {
  List<String> output = new ArrayList<String>();
  try {
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(
        this.resourceLoader);
    String path = new File(dir, value).toURI().toString();
    for (Resource resource : resolver.getResources(path)) {
      if (resource.getFile().isDirectory()) {
        output.add(resource.getURI().toString());
      }
    }
  }
  catch (IOException e) {
  }
  return output;
}

代码示例来源:origin: checkstyle/checkstyle

@Test
public void testConfigWithIgnoreUsingInputSource() throws Exception {
  final DefaultConfiguration config =
      (DefaultConfiguration) ConfigurationLoader.loadConfiguration(new InputSource(
          new File(getPath("InputConfigurationLoaderModuleIgnoreSeverity.xml"))
            .toURI().toString()),
          new PropertiesExpander(new Properties()), true);
  final Configuration[] children = config.getChildren();
  assertEquals("Invalid children count", 0, children[0].getChildren().length);
}

代码示例来源:origin: apache/hive

private String downloadResource(URI srcUri, String subDir, boolean convertToUnix)
  throws IOException, URISyntaxException {
 LOG.debug("Converting to local {}", srcUri);
 File destinationDir = (subDir == null) ? resourceDir : new File(resourceDir, subDir);
 ensureDirectory(destinationDir);
 File destinationFile = new File(destinationDir, new Path(srcUri.toString()).getName());
 String dest = destinationFile.getCanonicalPath();
 if (destinationFile.exists()) {
  return dest;
 }
 FileSystem fs = FileSystem.get(srcUri, conf);
 fs.copyToLocalFile(new Path(srcUri.toString()), new Path(dest));
 // add "execute" permission to downloaded resource file (needed when loading dll file)
 FileUtil.chmod(dest, "ugo+rx", true);
 return dest;
}

代码示例来源:origin: apache/hive

@Test
public void databases() throws TException, URISyntaxException {
 String[] dbNames = {"db1", "db9"};
 String expectedLocation = new File(expectedBaseDir(), dbNames[0] + ".db").toURI().toString();
 Assert.assertEquals(expectedCatalog(), fetched.getCatalogName());
 Assert.assertEquals(expectedLocation, fetched.getLocationUri() + "/");
 String db0Location = new URI(fetched.getLocationUri()).getPath();
 File dir = new File(db0Location);
 Assert.assertTrue(dir.exists() && dir.isDirectory());
 Assert.assertEquals(expectedCatalog(), fetched.getCatalogName());
 Assert.assertEquals(new File(db1Location).toURI().toString(), fetched.getLocationUri() + "/");
 dir = new File(new URI(fetched.getLocationUri()).getPath());
 Assert.assertTrue(dir.exists() && dir.isDirectory());
 Assert.assertEquals(expectedCatalog(), fetched.getCatalogName());
 dir = new File(db0Location);
 Assert.assertFalse(dir.exists());

代码示例来源:origin: spring-projects/spring-framework

@Test  // SPR-9317
public void fromUriEncodedQuery() throws URISyntaxException {
  URI uri = new URI("http://www.example.org/?param=aGVsbG9Xb3JsZA%3D%3D");
  String fromUri = UriComponentsBuilder.fromUri(uri).build().getQueryParams().get("param").get(0);
  String fromUriString = UriComponentsBuilder.fromUriString(uri.toString())
      .build().getQueryParams().get("param").get(0);
  assertEquals(fromUri, fromUriString);
}

代码示例来源:origin: apache/flink

public static String constructTestURI(Class<?> forClass, String folder) {
  return new File(constructTestPath(forClass, folder)).toURI().toString();
}

代码示例来源:origin: spring-projects/spring-framework

@Test	// SPR-14147
public void defaultUriVariables() throws Exception {
  Map<String, String> defaultVars = new HashMap<>(2);
  defaultVars.put("host", "api.example.com");
  defaultVars.put("port", "443");
  this.handler.setDefaultUriVariables(defaultVars);
  Map<String, Object> vars = new HashMap<>(1);
  vars.put("id", 123L);
  String template = "https://{host}:{port}/v42/customers/{id}";
  URI actual = this.handler.expand(template, vars);
  assertEquals("https://api.example.com:443/v42/customers/123", actual.toString());
}

代码示例来源:origin: apache/flink

@Test
public void testWithFsBackendAsync() throws Exception {
  FsStateBackend asyncFsBackend = new FsStateBackend(tmpFolder.newFolder().toURI().toString(), true);
  testProgramWithBackend(asyncFsBackend);
}

代码示例来源:origin: apache/flink

@Test
public void testExplicitlySetToLocal() throws Exception {
  final Configuration conf = new Configuration();
  conf.setString(CoreOptions.DEFAULT_FILESYSTEM_SCHEME, LocalFileSystem.getLocalFsURI().toString());
  FileSystem.initialize(conf);
  URI justPath = new URI(tempFolder.newFile().toURI().getPath());
  assertNull(justPath.getScheme());
  FileSystem fs = FileSystem.get(justPath);
  assertEquals("file", fs.getUri().getScheme());
}

代码示例来源:origin: gocd/gocd

@Test
public void shouldSetHeadersAndBaseDirectory() throws IOException {
  assertThat(handler.getContextPath(), is("/go/assets"));
  assertThat(((HandlerWrapper) handler.getHandler()).getHandler() instanceof AssetsContextHandler.AssetsHandler, is(true));
  AssetsContextHandler.AssetsHandler assetsHandler = (AssetsContextHandler.AssetsHandler) ((HandlerWrapper) handler.getHandler()).getHandler();
  ResourceHandler resourceHandler = (ResourceHandler) ReflectionUtil.getField(assetsHandler, "resourceHandler");
  assertThat(resourceHandler.getCacheControl(), is("max-age=31536000,public"));
  assertThat(resourceHandler.getResourceBase(), isSameFileAs(new File("WEB-INF/rails.root/public/assets").toPath().toAbsolutePath().toUri().toString()));
}

代码示例来源:origin: gocd/gocd

public String defaultRemoteUrl() {
    final String sanitizedUrl = sanitizeUrl();
    try {
      URI uri = new URI(sanitizedUrl);
      if (uri.getUserInfo() != null) {
        uri = new URI(uri.getScheme(), removePassword(uri.getUserInfo()), uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment());
        return uri.toString();
      }
    } catch (URISyntaxException e) {
      return sanitizedUrl;
    }
    return sanitizedUrl;
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void classpathURLWithWhitespace() throws Exception {
  PropertyEditor uriEditor = new URIEditor(getClass().getClassLoader());
  uriEditor.setAsText("  classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) +
      "/" + ClassUtils.getShortName(getClass()) + ".class  ");
  Object value = uriEditor.getValue();
  assertTrue(value instanceof URI);
  URI uri = (URI) value;
  assertEquals(uri.toString(), uriEditor.getAsText());
  assertTrue(!uri.getScheme().startsWith("classpath"));
}

代码示例来源:origin: stackoverflow.com

URI a = new URI("http://www.foo.com");
URI b = new URI("bar.html");
URI c = a.resolve(b);
c.toString()     -> "http://www.foo.combar.html"
c.getAuthority() -> "www.foo.com"
c.getPath()      -> "bar.html"

代码示例来源:origin: neo4j/neo4j

private String ensureRelativeUri( String mountPoint )
{
  try
  {
    URI result = new URI( mountPoint );
    if ( result.isAbsolute() )
    {
      return result.getPath();
    }
    else
    {
      return result.toString();
    }
  }
  catch ( URISyntaxException e )
  {
    log.debug( "Unable to translate [%s] to a relative URI in ensureRelativeUri(String mountPoint)", mountPoint );
    return mountPoint;
  }
}

代码示例来源:origin: spockframework/spock

public static String asClickableFileUrl(File path) {
  try {
   // File.toURI().toURL().toString() isn't clickable in Mac Terminal
   return new URI("file", "", path.toURI().getPath(), null, null).toString();
  } catch (URISyntaxException e) {
   throw new InternalSpockError(e);
  }
 }
}

代码示例来源:origin: neo4j/neo4j

@Documented( "Get non-existent node." )
@Test
public void shouldGet404WhenRetrievingNonExistentNode() throws Exception
{
  long nonExistentNode = helper.createNode();
  helper.deleteNode( nonExistentNode );
  URI nonExistentNodeUri = new URI( functionalTestHelper.nodeUri() + "/" + nonExistentNode );
  gen.get()
      .expectedStatus( 404 )
      .get( nonExistentNodeUri.toString() );
}

相关文章

微信公众号

最新文章

更多