本文整理汇总了Java中org.apache.camel.util.FileUtil.compactPath方法的典型用法代码示例。如果您正苦于以下问题:Java FileUtil.compactPath方法的具体用法?Java FileUtil.compactPath怎么用?Java FileUtil.compactPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.camel.util.FileUtil
的用法示例。
在下文中一共展示了FileUtil.compactPath方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolveResource
import org.apache.camel.util.FileUtil; //导入方法依赖的package包/类
@Override
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
// systemId should be mandatory
if (systemId == null) {
throw new IllegalArgumentException(String.format("Resource: %s refers an invalid resource without SystemId."
+ " Invalid resource has type: %s, namespaceURI: %s, publicId: %s, systemId: %s, baseURI: %s", resourceUri, type, namespaceURI, publicId, systemId, baseURI));
}
String resourceURI = null;
// Build up the relative path for using relatedURI and baseURI
if (baseURI == null) {
relatedURI = FileUtil.compactPath(getUri(systemId), '/');
resourceURI = relatedURI;
} else {
String relatedPath = relatedURIMap.get(baseURI);
if (relatedPath == null) {
relatedPath = FileUtil.onlyPath(relatedURI);
if (relatedPath == null) {
relatedPath = "";
}
relatedURI = FileUtil.compactPath(FileUtil.onlyPath(relatedURI) + "/" + systemId, '/');
resourceURI = relatedURI;
relatedURIMap.put(baseURI, relatedPath);
} else {
resourceURI = FileUtil.compactPath(relatedPath + "/" + systemId, '/');
relatedURI = resourceURI;
}
}
return new DefaultLSInput(publicId, systemId, baseURI, resourceURI);
}
示例2: changeToParentDirectory
import org.apache.camel.util.FileUtil; //导入方法依赖的package包/类
public synchronized void changeToParentDirectory() throws GenericFileOperationFailedException {
LOG.trace("changeToParentDirectory()");
String current = getCurrentDirectory();
String parent = FileUtil.compactPath(current + "/..");
// must start with absolute
if (!parent.startsWith("/")) {
parent = "/" + parent;
}
changeCurrentDirectory(parent);
}
示例3: changeCurrentDirectory
import org.apache.camel.util.FileUtil; //导入方法依赖的package包/类
public synchronized void changeCurrentDirectory(String path) throws GenericFileOperationFailedException {
LOG.trace("changeCurrentDirectory({})", path);
if (ObjectHelper.isEmpty(path)) {
return;
}
// must compact path so SFTP server can traverse correctly, make use of the '/'
// separator because JSch expects this as the file separator even on Windows
String before = path;
char separatorChar = '/';
path = FileUtil.compactPath(path, separatorChar);
if (LOG.isTraceEnabled()) {
LOG.trace("Compacted path: {} -> {} using separator: {}", new Object[]{before, path, separatorChar});
}
// not stepwise should change directory in one operation
if (!endpoint.getConfiguration().isStepwise()) {
doChangeDirectory(path);
return;
}
if (getCurrentDirectory().startsWith(path)) {
// extract the path segment relative to the target path and make sure it keeps the preceding '/' for the regex op
String p = getCurrentDirectory().substring(path.length() - (path.endsWith("/") ? 1 : 0));
if (p.length() == 0) {
return;
}
// the first character must be '/' and hence removed
path = UP_DIR_PATTERN.matcher(p).replaceAll("/..").substring(1);
}
// if it starts with the root path then a little special handling for that
if (FileUtil.hasLeadingSeparator(path)) {
// change to root path
doChangeDirectory(path.substring(0, 1));
path = path.substring(1);
}
// split into multiple dirs
final String[] dirs = path.split("/|\\\\");
if (dirs == null || dirs.length == 0) {
// path was just a relative single path
doChangeDirectory(path);
return;
}
// there are multiple dirs so do this in chunks
for (String dir : dirs) {
doChangeDirectory(dir);
}
}
示例4: resolveUriPath
import org.apache.camel.util.FileUtil; //导入方法依赖的package包/类
/**
* Helper operation used to remove relative path notation from
* resources. Most critical for resources on the Classpath
* as resource loaders will not resolve the relative paths correctly.
*
* @param name the name of the resource to load
* @return the modified or unmodified string if there were no changes
*/
private static String resolveUriPath(String name) {
// compact the path and use / as separator as that's used for loading resources on the classpath
return FileUtil.compactPath(name, '/');
}