use of java.net.URI in project hadoop by apache.
the class TestDefaultUri method tetGetDefaultUriTrailingSlash.
@Test
public void tetGetDefaultUriTrailingSlash() {
conf.set(FS_DEFAULT_NAME_KEY, "hdfs://nn_host/");
URI uri = FileSystem.getDefaultUri(conf);
assertThat(uri.getScheme(), is("hdfs"));
assertThat(uri.getAuthority(), is("nn_host"));
}
use of java.net.URI in project hadoop by apache.
the class TestDelegateToFsCheckPath method testCheckPathWithoutDefaultPort.
@Test
public void testCheckPathWithoutDefaultPort() throws URISyntaxException, IOException {
URI uri = new URI("dummy://dummy-host");
AbstractFileSystem afs = new DummyDelegateToFileSystem(uri, new UnOverrideDefaultPortFileSystem());
afs.checkPath(new Path("dummy://dummy-host"));
}
use of java.net.URI in project hadoop by apache.
the class TestDelegateToFsCheckPath method testCheckPathWithDefaultPort.
@Test
public void testCheckPathWithDefaultPort() throws URISyntaxException, IOException {
URI uri = new URI(String.format("dummy://dummy-host:%d", OverrideDefaultPortFileSystem.DEFAULT_PORT));
AbstractFileSystem afs = new DummyDelegateToFileSystem(uri, new OverrideDefaultPortFileSystem());
afs.checkPath(new Path("dummy://dummy-host/user/john/test"));
}
use of java.net.URI in project groovy by apache.
the class AbstractHttpServlet method generateNamePrefixOnce.
protected void generateNamePrefixOnce() {
URI uri = null;
String realPath = servletContext.getRealPath("/");
//prevent NPE if in .war
if (realPath != null) {
uri = new File(realPath).toURI();
}
try {
URL res = servletContext.getResource("/");
if (res != null) {
uri = res.toURI();
}
} catch (MalformedURLException ignore) {
} catch (URISyntaxException ignore) {
}
if (uri != null) {
try {
namePrefix = uri.toURL().toExternalForm();
return;
} catch (MalformedURLException e) {
log("generateNamePrefixOnce [ERROR] Malformed URL for base path / == '" + uri + '\'', e);
}
}
namePrefix = "";
}
use of java.net.URI in project hadoop by apache.
the class NetUtils method createSocketAddr.
/**
* Create an InetSocketAddress from the given target string and
* default port. If the string cannot be parsed correctly, the
* <code>configName</code> parameter is used as part of the
* exception message, allowing the user to better diagnose
* the misconfiguration.
*
* @param target a string of either "host" or "host:port"
* @param defaultPort the default port if <code>target</code> does not
* include a port number
* @param configName the name of the configuration from which
* <code>target</code> was loaded. This is used in the
* exception message in the case that parsing fails.
*/
public static InetSocketAddress createSocketAddr(String target, int defaultPort, String configName) {
String helpText = "";
if (configName != null) {
helpText = " (configuration property '" + configName + "')";
}
if (target == null) {
throw new IllegalArgumentException("Target address cannot be null." + helpText);
}
target = target.trim();
boolean hasScheme = target.contains("://");
URI uri = null;
try {
uri = hasScheme ? URI.create(target) : URI.create("dummyscheme://" + target);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Does not contain a valid host:port authority: " + target + helpText);
}
String host = uri.getHost();
int port = uri.getPort();
if (port == -1) {
port = defaultPort;
}
String path = uri.getPath();
if ((host == null) || (port < 0) || (!hasScheme && path != null && !path.isEmpty())) {
throw new IllegalArgumentException("Does not contain a valid host:port authority: " + target + helpText);
}
return createSocketAddrForHost(host, port);
}
Aggregations