本文整理汇总了Java中java.net.URI类的典型用法代码示例。如果您正苦于以下问题:Java URI类的具体用法?Java URI怎么用?Java URI使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
URI类属于java.net包,在下文中一共展示了URI类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getClasspathForClass
import java.net.URI; //导入依赖的package包/类
public static File getClasspathForClass(Class<?> targetClass) {
URI location;
try {
CodeSource codeSource = targetClass.getProtectionDomain().getCodeSource();
if (codeSource != null && codeSource.getLocation() != null) {
location = codeSource.getLocation().toURI();
if (location.getScheme().equals("file")) {
return new File(location);
}
}
if (targetClass.getClassLoader() != null) {
String resourceName = targetClass.getName().replace('.', '/') + ".class";
URL resource = targetClass.getClassLoader().getResource(resourceName);
if (resource != null) {
return getClasspathForResource(resource, resourceName);
}
}
throw new GradleException(String.format("Cannot determine classpath for class %s.", targetClass.getName()));
} catch (URISyntaxException e) {
throw UncheckedException.throwAsUncheckedException(e);
}
}
示例2: testZipRepoContent
import java.net.URI; //导入依赖的package包/类
@Test
public void testZipRepoContent() throws Exception {
Path repoDir = Paths.get(getClass().getResource(repository).toURI());
Path mtarZip = null;
try {
mtarZip = step.zipRepoContent(repoDir.toAbsolutePath());
URI jarMtarUri = URI.create("jar:" + mtarZip.toAbsolutePath().toUri().toString());
try (FileSystem mtarFS = FileSystems.newFileSystem(jarMtarUri, new HashMap<>())) {
Path mtarRoot = mtarFS.getRootDirectories().iterator().next();
assertFalse(Files.exists(mtarRoot.resolve(".git")));
assertFalse(Files.exists(mtarRoot.resolve(".gitignore")));
assertTrue(Files.exists(mtarRoot.resolve("a/cool-script.script")));
assertTrue(Files.exists(mtarRoot.resolve("META-INF/mtad.yaml")));
assertTrue(Files.exists(mtarRoot.resolve("META-INF/MANIFEST.MF")));
}
} finally {
if (mtarZip != null) {
Files.deleteIfExists(mtarZip);
}
}
}
示例3: checkSlaveNodesChange
import java.net.URI; //导入依赖的package包/类
private void checkSlaveNodesChange(Collection<ClusterPartition> newPartitions) {
for (ClusterPartition newPart : newPartitions) {
for (ClusterPartition currentPart : getLastPartitions()) {
if (!newPart.getMasterAddress().equals(currentPart.getMasterAddress())) {
continue;
}
MasterSlaveEntry entry = getEntry(currentPart.getMasterAddr());
// should be invoked first in order to remove stale failedSlaveAddresses
Set<URI> addedSlaves = addRemoveSlaves(entry, currentPart, newPart);
// Do some slaves have changed state from failed to alive?
upDownSlaves(entry, currentPart, newPart, addedSlaves);
break;
}
}
}
示例4: testGetInfoServer
import java.net.URI; //导入依赖的package包/类
@Test
public void testGetInfoServer() throws IOException, URISyntaxException {
HdfsConfiguration conf = new HdfsConfiguration();
URI httpsport = DFSUtil.getInfoServer(null, conf, "https");
assertEquals(new URI("https", null, "0.0.0.0",
DFS_NAMENODE_HTTPS_PORT_DEFAULT, null, null, null), httpsport);
URI httpport = DFSUtil.getInfoServer(null, conf, "http");
assertEquals(new URI("http", null, "0.0.0.0",
DFS_NAMENODE_HTTP_PORT_DEFAULT, null, null, null), httpport);
URI httpAddress = DFSUtil.getInfoServer(new InetSocketAddress(
"localhost", 8020), conf, "http");
assertEquals(
URI.create("http://localhost:" + DFS_NAMENODE_HTTP_PORT_DEFAULT),
httpAddress);
}
示例5: enforceValueEquality
import java.net.URI; //导入依赖的package包/类
@Test
public void enforceValueEquality() {
URI omero = URI.create("h:1");
String sessionKey = "sk";
FutureTimepoint now = now();
QueuedOmeroKeepAlive value =
new QueuedOmeroKeepAlive(omero, sessionKey, now);
QueuedOmeroKeepAlive valueCopy =
new QueuedOmeroKeepAlive(omero, sessionKey, now);
assertThat(value.getOmero(), is(omero));
assertThat(value.getSessionKey(), is(sessionKey));
assertThat(value.getUntilWhen(), is(now));
assertThat(value, is(valueCopy));
assertThat(value.hashCode(), is(valueCopy.hashCode()));
}
示例6: applyImage
import java.net.URI; //导入依赖的package包/类
private void applyImage ( final Symbol symbol, final SymbolLoader symbolLoader )
{
if ( symbol.getBackgroundImage () == null || symbol.getBackgroundImage ().isEmpty () )
{
return;
}
logInfo ( "Trying to load background image: " + symbol.getBackgroundImage () );
final String uriString = symbolLoader.resolveUri ( symbol.getBackgroundImage () );
final org.eclipse.emf.common.util.URI uri = org.eclipse.emf.common.util.URI.createURI ( uriString );
this.loadedResources.add ( uri );
try
{
final Image img = this.manager.createImageWithDefault ( ImageDescriptor.createFromURL ( new URL ( uriString ) ) );
this.canvas.setBackgroundImage ( img );
}
catch ( final MalformedURLException e )
{
logError ( "Loading background image: " + uriString, e ); //$NON-NLS-1$
}
}
示例7: check
import java.net.URI; //导入依赖的package包/类
public static RevocationStatus check(X509Certificate cert,
X509Certificate issuerCert,
URI responderURI,
X509Certificate responderCert,
Date date, List<Extension> extensions)
throws IOException, CertPathValidatorException
{
CertId certId = null;
try {
X509CertImpl certImpl = X509CertImpl.toImpl(cert);
certId = new CertId(issuerCert, certImpl.getSerialNumberObject());
} catch (CertificateException | IOException e) {
throw new CertPathValidatorException
("Exception while encoding OCSPRequest", e);
}
OCSPResponse ocspResponse = check(Collections.singletonList(certId),
responderURI, issuerCert, responderCert, date, extensions);
return (RevocationStatus) ocspResponse.getSingleResponse(certId);
}
示例8: Key
import java.net.URI; //导入依赖的package包/类
private Key (
@NonNull final AntArtifact a,
@NonNull final URI uri,
@NonNull final String classPathId,
@NonNull final String entryId,
@NullAllowed final Consumer<Pair<String,String>> preRemoveAction,
@NullAllowed final Consumer<Pair<String,String>> postRemoveAction,
boolean shared) {
this.type = TYPE_PROJECT;
this.antArtifact = a;
this.uri = uri;
this.classPathId = classPathId;
this.entryId = entryId;
this.preRemoveAction = preRemoveAction;
this.postRemoveAction = postRemoveAction;
this.shared = shared;
}
示例9: testListEventsByCategory
import java.net.URI; //导入依赖的package包/类
@Test
public void testListEventsByCategory() throws URISyntaxException {
UriInfo ui = mock(UriInfo.class);
when(ui.getBaseUriBuilder()).then(new UriBuilderFactory(URI.create("http://mock")));
Request request = mock(Request.class);
when(archivist.getEventsForCategory(Event.getCategory("some", "category"), Optional.empty()))
.thenReturn(Collections.singletonList(new Event(new URI("customer-events/some-category/eventSID"),
"some-category", CurrentTime.now())));
Response response = service.getCustomerEventsByCategory(ui, request, "application/hal+json", "some-category", "");
EventsRepresentation events = (EventsRepresentation) response.getEntity();
assertEquals(1, events.getEvents().size());
assertEquals("http://mock/customer-events", events.getSelf().getHref());
response = service.getCustomerEventsByCategory(ui, request, "application/hal+json;no-real-type", "some-category", "");
assertEquals(415,response.getStatus());
}
示例10: launch
import java.net.URI; //导入依赖的package包/类
private void launch(URI uri) throws IOException {
byte[] uriByteArray = ( uri.toString() + '\0' ).getBytes();
boolean result = false;
XToolkit.awtLock();
try {
if (!nativeLibraryLoaded) {
throw new IOException("Failed to load native libraries.");
}
result = gnome_url_show(uriByteArray);
} finally {
XToolkit.awtUnlock();
}
if (!result) {
throw new IOException("Failed to show URI:" + uri);
}
}
示例11: buildUri
import java.net.URI; //导入依赖的package包/类
private static URI buildUri(String pathPrefix, String path, Map<String, String> params) {
Objects.requireNonNull(path, "path must not be null");
try {
String fullPath;
if (pathPrefix != null) {
if (path.startsWith("/")) {
fullPath = pathPrefix + path;
} else {
fullPath = pathPrefix + "/" + path;
}
} else {
fullPath = path;
}
URIBuilder uriBuilder = new URIBuilder(fullPath);
for (Map.Entry<String, String> param : params.entrySet()) {
uriBuilder.addParameter(param.getKey(), param.getValue());
}
return uriBuilder.build();
} catch(URISyntaxException e) {
throw new IllegalArgumentException(e.getMessage(), e);
}
}
示例12: defaultPage
import java.net.URI; //导入依赖的package包/类
@GET
@Produces(MediaType.TEXT_HTML)
public Response defaultPage(@Context UriInfo ui) throws URISyntaxException {
/*
* This redirect is required due to change of "Jersey" version from "1.17" to "2.13".
* The "1.*" version of jersey has property "FEATURE_REDIRECT".
* For example, when making request "localhost:8888/context/dev", Jersey checks whether "FEATURE_REDIRECT" is set to "true" in ServletContainer and request does not end with '/'.
* If so, trailing slash is added and redirect is occurred to "localhost:8888/context/dev/"
*
* Jersey "2.*" does not contain property "FEATURE_REDIRECT".
* The code that made redirect in "1.*" jersey is commented out in ServletContainer.java:504
* Jersey "2.*" resolves request even if '/' was not present in the end.
* But all links in our *.jsp and *.html to *.js and *.css are relative. So without adding '/' in the end, files can not be opened.
* To solve it, we introduced this redirect
*/
if (!ui.getAbsolutePath().toString().endsWith("/")) {
return Response.temporaryRedirect(new URI(ui.getAbsolutePath().toString() + "/")).build();
} else {
return Response.ok(new Viewable("/index.jsp", new HashMap<String, Object>())).build();
}
}
示例13: generateHealthCheckFailureDescription
import java.net.URI; //导入依赖的package包/类
private MatchingServiceHealthCheckDetails generateHealthCheckFailureDescription(
final MatchingServiceHealthCheckResponseDto response,
final URI matchingServiceUri,
final boolean isOnboarding) {
if (!response.getResponse().isPresent()) {
return generateHealthCheckDescription("no response", matchingServiceUri, response.getVersionNumber(), isOnboarding);
}
return generateHealthCheckDescription("responded with non-healthy status", matchingServiceUri,
response.getVersionNumber(), isOnboarding);
}
示例14: readListAndSynchronize
import java.net.URI; //导入依赖的package包/类
public void readListAndSynchronize() throws Exception {
List<URI> uriList = new ArrayList<>();
Scanner scanner = new Scanner(new File(getUriListLocation()));
while (scanner.hasNextLine()) {
String uriString = scanner.nextLine();
Optional<URI> maybeUri = NormURI.normalize(uriString);
if (maybeUri.isPresent()) {
uriList.add(maybeUri.get());
} else {
logger.warn("Unable to convert {} to a URI", uriString);
}
}
synchronize(uriList);
}
示例15: FileBackedHttpResource
import java.net.URI; //导入依赖的package包/类
/**
* Constructor.
*
* @param resource HTTP(S) URL of the resource
* @param backingFile file: URI location to store the resource
*
* @since 1.2
*/
public FileBackedHttpResource(String resource, URI backingFile) {
super(resource);
if (backingFile == null) {
throw new IllegalArgumentException("Backing file path may not be null or empty");
}
resourceFile = new File(backingFile);
}