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

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

@Before
public void setUp() throws IOException {
  // Chart is arbitrary, but it does have subcharts in it, which exercise some tricky logic
  final URI uri = URI.create("https://kubernetes-charts.storage.googleapis.com/wordpress-0.6.6.tgz");
  assertNotNull(uri);
  final URL url = uri.toURL();
  assertNotNull(url);
  try (final URLChartLoader loader = new URLChartLoader()) {
    this.chart = loader.load(url);
  }
  assertNotNull(this.chart);
  final Path buildDirectory = Paths.get(System.getProperty("project.build.directory"));
  assertNotNull(buildDirectory);
  assertTrue(Files.isDirectory(buildDirectory));
  assertTrue(Files.isWritable(buildDirectory));
  this.buildDirectory = buildDirectory;
}
 
源代码2 项目: webauthn4j   文件: Origin.java
public Origin(String originUrl) {
    URI uri = URI.create(originUrl);
    this.scheme = uri.getScheme();
    this.host = uri.getHost();
    int originPort = uri.getPort();

    if (originPort == -1) {
        if (this.scheme == null) {
            throw new IllegalArgumentException(SCHEME_ERROR_MESSAGE);
        }
        switch (this.scheme) {
            case SCHEME_HTTPS:
                originPort = 443;
                break;
            case SCHEME_HTTP:
                originPort = 80;
                break;
            default:
                throw new IllegalArgumentException(SCHEME_ERROR_MESSAGE);
        }
    }
    this.port = originPort;
}
 
源代码3 项目: cloud-odata-java   文件: RequestContentTypeTest.java
@Test
public void contentTypeAndSubtypeIllegal() throws Exception {
  HttpPost post = new HttpPost(URI.create(getEndpoint().toString() + "Rooms"));
  post.addHeader(HttpHeaders.CONTENT_TYPE, "illegal/illegal");
  final HttpResponse response = getHttpClient().execute(post);
  assertEquals(HttpStatusCodes.UNSUPPORTED_MEDIA_TYPE.getStatusCode(), response.getStatusLine().getStatusCode());
}
 
源代码4 项目: spring-cloud-dataflow   文件: DataFlowIT.java
@BeforeEach
public void before() {
	dataFlowOperations = new DataFlowTemplate(URI.create(testProperties.getDataflowServerUrl()));
	runtimeApps = new RuntimeApplicationHelper(dataFlowOperations,
			testProperties.getPlatformName(), testProperties.getKubernetesAppHostSuffix());
	tasks = new Tasks(dataFlowOperations);
	restTemplate = new RestTemplate(); // used for HTTP post in tests

	Awaitility.setDefaultPollInterval(Duration.ofSeconds(5));
	Awaitility.setDefaultTimeout(Duration.ofMinutes(10));
}
 
源代码5 项目: zsync4j   文件: HttpClientTest.java
@Test
public void testTransferListener() throws IOException, HttpError {
  final URI uri = URI.create("http://host/bla");

  final byte[] data = new byte[17];
  final ResponseBody body = mock(ResponseBody.class);
  when(body.contentLength()).thenReturn((long) data.length);
  when(body.source()).thenReturn(mock(BufferedSource.class));
  final InputStream inputStream = new ByteArrayInputStream(data);
  when(body.byteStream()).thenReturn(inputStream);

  final Request request = new Request.Builder().url(uri.toString()).build();
  final Response response = new Response.Builder().protocol(HTTP_1_1).body(body).request(request).code(200).build();

  final Call mockCall = mock(Call.class);
  when(mockCall.execute()).thenReturn(response);
  final OkHttpClient mockHttpClient = mock(OkHttpClient.class);
  when(mockHttpClient.newCall(any(Request.class))).thenReturn(mockCall);

  final EventLogHttpTransferListener listener = new EventLogHttpTransferListener();
  final InputStream in =
      new HttpClient(mockHttpClient).get(uri, Collections.<String, Credentials>emptyMap(), listener);
  final byte[] b = new byte[8];
  assertEquals(0, in.read());
  assertEquals(8, in.read(b));
  assertEquals(8, in.read(b, 0, 8));
  assertEquals(-1, in.read());
  in.close();

  final List<Event> events =
      ImmutableList.of(new Initialized(new Request.Builder().url(uri.toString()).build()), new Started(uri,
          data.length), new Transferred(1), new Transferred(8), new Transferred(8), Closed.INSTANCE);
  assertEquals(events, listener.getEventLog());
}
 
源代码6 项目: olingo-odata4   文件: Services.java
@GET
@Path("/GetDefaultColor()")
public Response functionGetDefaultColor(
    @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
    @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format) {

  try {
    final Accept acceptType;
    if (StringUtils.isNotBlank(format)) {
      acceptType = Accept.valueOf(format.toUpperCase());
    } else {
      acceptType = Accept.parse(accept);
    }

    final Property property = new Property();
    property.setType("Microsoft.Test.OData.Services.ODataWCFService.Color");
    property.setValue(ValueType.ENUM, "Red");
    final ResWrap<Property> container = new ResWrap<Property>(
        URI.create(Constants.get(ConstantKey.ODATA_METADATA_PREFIX) + property.getType()), null,
        property);

    return xml.createResponse(
        null,
        xml.writeProperty(acceptType, container),
        null,
        acceptType);
  } catch (Exception e) {
    return xml.createFaultResponse(accept, e);
  }
}
 
源代码7 项目: fcrepo-import-export   文件: BagItIT.java
@Test
public void testImportSerializedBag() throws FcrepoOperationFailedException {
    final URI rootURI = URI.create(serverAddress);
    final URI resourceURI = URI.create(serverAddress + "testBagImport");
    final String bagPath = TARGET_DIR + "/test-classes/sample/compress/bag-tar.tar";

    final Config config = new Config();
    config.setMode("import");
    config.setBaseDirectory(bagPath);
    config.setRdfLanguage(DEFAULT_RDF_LANG);
    config.setResource(rootURI);
    config.setMap(new String[]{"http://localhost:8080/fcrepo/rest/", serverAddress});
    config.setUsername(USERNAME);
    config.setPassword(PASSWORD);
    config.setBagProfile(BagProfile.BuiltIn.BEYOND_THE_REPOSITORY.getIdentifier());
    config.setIncludeBinaries(true);
    config.setLegacy(true);

    // Resource doesn't exist
    if (exists(resourceURI)) {
        removeAndReset(resourceURI);
    }
    assertFalse(exists(resourceURI));

    // run import
    final Importer importer = new Importer(config, clientBuilder);
    importer.run();

    // Resource does exist.
    assertTrue(exists(resourceURI));
}
 
源代码8 项目: fcrepo-import-export   文件: RoundtripIT.java
@Test
public void testRoundtripDirectContainer() throws Exception {
    final String baseURI = serverAddress + UUID.randomUUID();
    final URI res1 = URI.create(baseURI + "/res1");
    final URI parts = URI.create(baseURI + "/res1/parts");
    final URI part1 = URI.create(baseURI + "/res1/parts/part1");


    final String partsTurtle = " <> <" + LDP_HAS_MEMBER_RELATION + "> <" + DCTERMS_HAS_PART + "> ; "
        + "<" + LDP_MEMBERSHIP_RESOURCE + "> <" +  res1.toString() + "> .";

    create(res1);

    final Map<String, String> headers = new HashMap<>();
    headers.put("Link", "<" + LDP_DIRECT_CONTAINER + ">; rel=\"type\"");

    createTurtle(parts, partsTurtle, headers);
    create(part1);

    roundtrip(URI.create(baseURI), true);

    final Resource parent = createResource(res1.toString());
    final Resource container = createResource(parts.toString());
    final Resource member = createResource(part1.toString());

    final Model model1 = getAsModel(res1);
    assertTrue(model1.contains(parent, createProperty(DCTERMS_HAS_PART), member));

    final Model model2 = getAsModel(parts);
    assertTrue(model2.contains(container, RDF_TYPE, createResource(LDP_DIRECT_CONTAINER)));
    assertTrue(model2.contains(container, createProperty(LDP_HAS_MEMBER_RELATION),
            createResource(DCTERMS_HAS_PART)));
    assertTrue(model2.contains(container, createProperty(LDP_MEMBERSHIP_RESOURCE), parent));

    // make sure membership triples were generated by the container
    client.delete(part1).perform();
    final Model model3 = getAsModel(res1);
    assertFalse(model3.contains(parent, createProperty(DCTERMS_HAS_PART), member));
}
 
源代码9 项目: azure-cosmosdb-java   文件: Uri.java
public Uri(String uri) {
    this.uriAsString = uri;

    URI uriValue = null;
    try {
        uriValue = URI.create(uri);
    } catch (IllegalArgumentException e) {
        uriValue = null;
    }
    this.uri = uriValue;
}
 
源代码10 项目: crail   文件: RdmaStorageActiveGroup.java
public StorageEndpoint createEndpoint(InetSocketAddress inetAddress) throws Exception {
	if (RdmaConstants.STORAGE_RDMA_LOCAL_MAP && CrailUtils.isLocalAddress(inetAddress.getAddress())){
		RdmaStorageLocalEndpoint localEndpoint = localCache.get(inetAddress.getAddress());
		if (localEndpoint == null){
			localEndpoint = new RdmaStorageLocalEndpoint(inetAddress);
			localCache.put(inetAddress, localEndpoint);
		}
		return localEndpoint;			
	}
	
	RdmaStorageActiveEndpoint endpoint = super.createEndpoint();
	URI uri = URI.create("rdma://" + inetAddress.getAddress().getHostAddress() + ":" + inetAddress.getPort());
	endpoint.connect(uri);
	return endpoint;
}
 
源代码11 项目: Refactoring-Bot   文件: GitlabDataGrabber.java
/**
 * This method tries to get a repository from GitLab.
 * 
 * @param repoName
 * @param repoOwner
 * @param botToken
 * @param apiLink
 * @throws GitLabAPIException
 */
public GitLabRepository checkRepository(String repoName, String repoOwner, String botToken, String apiLink)
		throws GitLabAPIException {

	// Build URI
	URI gitlabURI = null;

	if (apiLink == null || apiLink.isEmpty()) {
		gitlabURI = URI.create(GITLAB_DEFAULT_APILINK + "/projects/" + repoOwner + "%2F" + repoName);
	} else {
		gitlabURI = URI.create(apiLink + "/projects/" + repoOwner + "%2F" + repoName);
	}

	RestTemplate rest = new RestTemplate();

	HttpHeaders headers = new HttpHeaders();
	headers.set("User-Agent", USER_AGENT);
	headers.set(TOKEN_HEADER, botToken);
	HttpEntity<String> entity = new HttpEntity<>("parameters", headers);

	try {
		// Send request to the GitLab-API
		return rest.exchange(gitlabURI, HttpMethod.GET, entity, GitLabRepository.class).getBody();
	} catch (RestClientException e) {
		logger.error(e.getMessage(), e);
		throw new GitLabAPIException("Repository does not exist on GitLab or invalid Bot-Token!", e);
	}
}
 
源代码12 项目: openjdk-jdk8u-backup   文件: TestToString.java
public JavaSource(String stmt) {
    super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
    source = source.replace("#S", stmt);
}
 
源代码13 项目: TencentKona-8   文件: TestSelfRef.java
public JavaSource() {
    super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
    source = bodyTemplate.replace("#B",
            ek.enclStr.replace("#S", sk.siteStr.replace("#I", ik.innerStr.replace("#R", rk.refStr))));
}
 
源代码14 项目: intercom-java   文件: Avatar.java
public Avatar setImageURL(String imageURL) {
    if(imageURL != null) {
        this.imageURL = URI.create(imageURL);
    }
    return this;
}
 
源代码15 项目: TencentKona-8   文件: T7142086.java
public AnSource(int n) {
    super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
    source = classTemplate.replace("#N", String.valueOf(n));
}
 
源代码16 项目: openjdk-8-source   文件: T6457284.java
public MyFileObject() {
    super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
}
 
源代码17 项目: openjdk-jdk8u   文件: TestClose.java
MemFile(String name, String text) {
    super(URI.create(name), JavaFileObject.Kind.SOURCE);
    this.text = text;
}
 
public MockJavaClassObject(String name, Kind kind)
{
    super(URI.create("string:///" + name.replace('.', '/') + kind.extension), kind);
}
 
@Test()
public void testSslContextEmpty() throws Exception {
    new DefaultDockerClientConfig(URI.create("tcp://foo"), "dockerConfig", "apiVersion", "registryUrl", "registryUsername", "registryPassword", "registryEmail",
            null);
}
 
源代码20 项目: fcrepo-import-export   文件: RoundtripIT.java
@Test
public void testRoundtripIndirectContainer() throws Exception {
    final String baseURI = serverAddress + UUID.randomUUID();
    final URI res1 = URI.create(baseURI + "/res1");
    final URI res2 = URI.create(baseURI + "/res2");
    final URI parts = URI.create(baseURI + "/res2/parts");
    final URI proxy = URI.create(baseURI + "/res2/parts/proxy1");

    final String partsTurtle = "<> <" + LDP_HAS_MEMBER_RELATION + "> <" + DCTERMS_HAS_PART + "> ; "
        + "<" + LDP_MEMBERSHIP_RESOURCE + "> <" +  res2.toString() + "> ; "
        + "<" + LDP_INSERTED_CONTENT_RELATION + "> <" + ORE_PROXY_FOR + "> .";

    final String proxyTurtle = "<> a <" + ORE_PROXY + "> ; "
        + "<" + ORE_PROXY_FOR + "> <" + res1.toString() + "> . ";

    create(res1);
    create(res2);
    final Map<String, String> headers = new HashMap<>();
    headers.put("Link", "<" + LDP_INDIRECT_CONTAINER + ">; rel=\"type\"");
    createTurtle(parts, partsTurtle, headers);
    createTurtle(proxy, proxyTurtle);

    roundtrip(URI.create(baseURI), true);

    final Resource member = createResource(res1.toString());
    final Resource parent = createResource(res2.toString());
    final Resource container = createResource(parts.toString());

    final Model model1 = getAsModel(res2);
    assertTrue(model1.contains(parent, createProperty(DCTERMS_HAS_PART), member));

    final Model model2 = getAsModel(parts);
    assertTrue(model2.contains(container, RDF_TYPE, createResource(LDP_INDIRECT_CONTAINER)));
    assertTrue(model2.contains(container, createProperty(LDP_HAS_MEMBER_RELATION),
            createResource(DCTERMS_HAS_PART)));
    assertTrue(model2.contains(container, createProperty(LDP_MEMBERSHIP_RESOURCE), parent));
    assertTrue(model2.contains(container, createProperty(LDP_INSERTED_CONTENT_RELATION),
            createResource(ORE_PROXY_FOR)));

    // make sure membership triples were generated by the container
    client.delete(proxy).perform();
    final Model model3 = getAsModel(res2);
    assertFalse(model3.contains(parent, createProperty(DCTERMS_HAS_PART), member));
}