本文整理汇总了Java中java.net.URI.getPath方法的典型用法代码示例。如果您正苦于以下问题:Java URI.getPath方法的具体用法?Java URI.getPath怎么用?Java URI.getPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.URI
的用法示例。
在下文中一共展示了URI.getPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: relativize
import java.net.URI; //导入方法依赖的package包/类
private static String relativize(URI cwdUri, URI srcUri, boolean isDir) {
String uriPath = srcUri.getPath();
String cwdPath = cwdUri.getPath();
if (cwdPath.equals(uriPath)) {
return Path.CUR_DIR;
}
// find common ancestor
int lastSep = findLongestDirPrefix(cwdPath, uriPath, isDir);
StringBuilder relPath = new StringBuilder();
// take the remaining path fragment after the ancestor
if (lastSep < uriPath.length()) {
relPath.append(uriPath.substring(lastSep+1));
}
// if cwd has a path fragment after the ancestor, convert them to ".."
if (lastSep < cwdPath.length()) {
while (lastSep != -1) {
if (relPath.length() != 0) relPath.insert(0, Path.SEPARATOR);
relPath.insert(0, "..");
lastSep = cwdPath.indexOf(Path.SEPARATOR, lastSep+1);
}
}
return relPath.toString();
}
示例2: performCommand
import java.net.URI; //导入方法依赖的package包/类
@Override
public boolean performCommand(ConsoleInput ci, DownloadManager dm, List args)
{
if (args.isEmpty()) {
ci.out.println("> Command 'hack': Not enough parameters for subcommand parameter 'port'.");
return false;
}
TRTrackerAnnouncer client = dm.getTrackerClient();
try {
URI uold = new URI(client.getTrackerURL().toString());
String portStr = (String) args.get(0);
URI unew = new URI(uold.getScheme(), uold.getUserInfo(), uold.getHost(), Integer.parseInt(portStr), uold.getPath(), uold.getQuery(), uold.getFragment());
client.setTrackerURL(new URL(unew.toString()));
ci.out.println("> Set Tracker URL for '"+dm.getSaveLocation()+"' to '"+unew.toString()+"'");
} catch (Exception e) {
ci.out.println("> Command 'hack': Assembling new tracker url failed: "+e.getMessage());
return false;
}
return true;
}
示例3: setNextPage
import java.net.URI; //导入方法依赖的package包/类
protected void setNextPage() throws Exception {
String url = driver.getCurrentUrl();
URI url2 = new URI(url);
url = url2.getPath();
AbstractPage x = mapper.get(url);
if(x != null){
if(!x.equals(currentPage)){
this.completePendingAsyncTasks();
}
} else {
x = PageObjectFactory.getInstance(url);
this.addPageObject(x);
}
currentPage.transferControlTo(x);
currentPage = x;
Assert.assertNotNull(currentPage, "No Page Object found for " + url);
currentPage.map(currentPage);
}
示例4: setServiceURL
import java.net.URI; //导入方法依赖的package包/类
/**
* Set the service URL to make requests against.
*
* This can either be just the host name or can include the full path to the service.
*
* @param serviceUrl URL to make requests against
*/
public void setServiceURL(String serviceUrl) {
try {
URI fullURI = URI.create(serviceUrl);
URI partialURI = new URI(fullURI.getScheme(), null, fullURI.getHost(),
fullURI.getPort(), null, null, null);
cc.setEndpoint(partialURI);
String path = fullURI.getPath();
if (path != null) {
path = path.substring(path.startsWith("/") ? 1 : 0);
path = path.substring(0, path.length() - (path.endsWith("/") ? 1 : 0));
}
if (path == null || path.isEmpty()) {
this.servicePath = DEFAULT_SERVICE_PATH;
} else {
this.servicePath = path;
}
} catch (Exception e) {
throw MwsUtl.wrap(e);
}
}
开发者ID:trifonnt,项目名称:ext-lib-amazon-mws-fulfillment-inbound-shipment,代码行数:28,代码来源:FBAInboundServiceMWSConfig.java
示例5: uriToCommandArray
import java.net.URI; //导入方法依赖的package包/类
private static String[] uriToCommandArray(URI uri) {
String command = uri.getPath();
List<String> args = Strings.split(uri.getQuery(), '&', -1);
String[] commandArray = new String[args.size() + 1];
commandArray[0] = command;
for (int i = 1; i < commandArray.length; ++i)
commandArray[i] = args.get(i - 1);
return commandArray;
}
示例6: createServiceInfo
import java.net.URI; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public FeatureFlagsServiceInfo createServiceInfo(Map<String, Object> serviceData) {
String id = getId(serviceData);
Map<String, Object> credentials = getCredentials(serviceData);
URI url = URI.create(getUriFromCredentials(credentials));
String username = (String) credentials.get(USERNAME);
String password = (String) credentials.get(PASSWORD);
return new FeatureFlagsServiceInfo(id, url.getHost(), url.getPort(), username, password, url.getPath());
}
示例7: checkUri
import java.net.URI; //导入方法依赖的package包/类
private void checkUri(URI uri) {
if (!uri.getScheme().equalsIgnoreCase(getScheme()))
throw new IllegalArgumentException("URI does not match this provider");
if (uri.getAuthority() != null)
throw new IllegalArgumentException("Authority component present");
if (uri.getPath() == null)
throw new IllegalArgumentException("Path component is undefined");
if (!uri.getPath().equals("/"))
throw new IllegalArgumentException("Path component should be '/'");
if (uri.getQuery() != null)
throw new IllegalArgumentException("Query component present");
if (uri.getFragment() != null)
throw new IllegalArgumentException("Fragment component present");
}
示例8: ChRootedFileSystem
import java.net.URI; //导入方法依赖的package包/类
/**
* Constructor
* @param uri base file system
* @param conf configuration
* @throws IOException
*/
public ChRootedFileSystem(final URI uri, Configuration conf)
throws IOException {
super(FileSystem.get(uri, conf));
String pathString = uri.getPath();
if (pathString.isEmpty()) {
pathString = "/";
}
chRootPathPart = new Path(pathString);
chRootPathPartString = chRootPathPart.toUri().getPath();
myUri = uri;
workingDir = getHomeDirectory();
// We don't use the wd of the myFs
}
示例9: get
import java.net.URI; //导入方法依赖的package包/类
@Override
public RESTResource get(URI uri, Map<String, String> parameters) throws RESTException {
RESTResource resource = new RESTResource(name(uri), this);
resource.contentType = "application/json";
resource.content = "[";
Set<String> vocabs = new HashSet<String>();
// Return all TDs
try {
vocabs = VocabularyUtils.listVocabularies();
} catch (Exception e) {
throw new BadRequestException();
}
Iterator<String> it = vocabs.iterator();
while (it.hasNext()) {
String vocab = it.next();
URI vocabUri = URI.create(vocab);
resource.content += "\"" + vocabUri.getPath() + "\"";
if (it.hasNext()) {
resource.content += ",";
}
}
resource.content += "]";
return resource;
}
示例10: getPathAndQuery
import java.net.URI; //导入方法依赖的package包/类
private String getPathAndQuery(URI uri) {
String path = uri.getPath();
String query = uri.getQuery();
if (path == null || path.equals("")) {
path = "/";
}
if (query == null) {
query = "";
}
if (query.equals("")) {
return path;
} else {
return path + "?" + query;
}
}
示例11: safeUri
import java.net.URI; //导入方法依赖的package包/类
/**
* Create a safe URI from the given one by stripping out user info.
*
* @param uri Original URI
* @return a new URI with no user info
*/
private static URI safeUri(URI uri) {
try {
return new URI(uri.getScheme(), null, uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment());
} catch (URISyntaxException e) {
throw UncheckedException.throwAsUncheckedException(e);
}
}
示例12: getEncodeRequestSize
import java.net.URI; //导入方法依赖的package包/类
private int getEncodeRequestSize(URI requestURI, String[] names, String[] values) {
int size = 0;
// Encode Request line
size += GET_BYTES.length;
size += SPACE_BYTES.length;
String path = requestURI.getPath();
if (requestURI.getQuery() != null) {
path += "?" + requestURI.getQuery();
}
size += path.getBytes().length;
size += SPACE_BYTES.length;
size += HTTP_1_1_BYTES.length;
size += CRLF_BYTES.length;
// Encode headers
for (int i = 0; i < names.length; i++) {
String headerName = names[i];
String headerValue = values[i];
if (headerName != null && headerValue != null) {
size += headerName.getBytes().length;
size += COLON_BYTES.length;
size += SPACE_BYTES.length;
size += headerValue.getBytes().length;
size += CRLF_BYTES.length;
}
}
size += CRLF_BYTES.length;
LOG.fine("Returning a request size of " + size);
return size;
}
示例13: getServerPath
import java.net.URI; //导入方法依赖的package包/类
private static String getServerPath(URI serverUrl) {
String path = serverUrl.getPath();
int endIndex = path.lastIndexOf("/");
if (endIndex == -1 ) {
return path;
} else if (endIndex == 0) {
return path.substring(1);
} else {
return path.substring(1, endIndex); // Also strip leading /
}
}
示例14: name
import java.net.URI; //导入方法依赖的package包/类
private String name(URI uri) {
String path = uri.getPath();
if (path.contains("/")) {
return path.substring(uri.getPath().lastIndexOf("/") + 1);
}
return path;
}
示例15: createSocketAddr
import java.net.URI; //导入方法依赖的package包/类
/**
* 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);
}