本文整理汇总了Java中org.apache.camel.util.FileUtil.hasLeadingSeparator方法的典型用法代码示例。如果您正苦于以下问题:Java FileUtil.hasLeadingSeparator方法的具体用法?Java FileUtil.hasLeadingSeparator怎么用?Java FileUtil.hasLeadingSeparator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.camel.util.FileUtil
的用法示例。
在下文中一共展示了FileUtil.hasLeadingSeparator方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: asRemoteFile
import org.apache.camel.util.FileUtil; //导入方法依赖的package包/类
private RemoteFile<ChannelSftp.LsEntry> asRemoteFile(String absolutePath, ChannelSftp.LsEntry file, String charset) {
RemoteFile<ChannelSftp.LsEntry> answer = new RemoteFile<ChannelSftp.LsEntry>();
answer.setCharset(charset);
answer.setEndpointPath(endpointPath);
answer.setFile(file);
answer.setFileNameOnly(file.getFilename());
answer.setFileLength(file.getAttrs().getSize());
answer.setLastModified(file.getAttrs().getMTime() * 1000L);
answer.setHostname(((RemoteFileConfiguration) endpoint.getConfiguration()).getHost());
answer.setDirectory(file.getAttrs().isDir());
// absolute or relative path
boolean absolute = FileUtil.hasLeadingSeparator(absolutePath);
answer.setAbsolute(absolute);
// create a pseudo absolute name
String dir = FileUtil.stripTrailingSeparator(absolutePath);
String absoluteFileName = FileUtil.stripLeadingSeparator(dir + "/" + file.getFilename());
// if absolute start with a leading separator otherwise let it be relative
if (absolute) {
absoluteFileName = "/" + absoluteFileName;
}
answer.setAbsoluteFilePath(absoluteFileName);
// the relative filename, skip the leading endpoint configured path
String relativePath = ObjectHelper.after(absoluteFileName, endpointPath);
// skip trailing /
relativePath = FileUtil.stripLeadingSeparator(relativePath);
answer.setRelativeFilePath(relativePath);
// the file name should be the relative path
answer.setFileName(answer.getRelativeFilePath());
return answer;
}
示例2: changeCurrentDirectory
import org.apache.camel.util.FileUtil; //导入方法依赖的package包/类
public void changeCurrentDirectory(String path) throws GenericFileOperationFailedException {
log.trace("changeCurrentDirectory({})", path);
if (ObjectHelper.isEmpty(path)) {
return;
}
// must compact path so FTP server can traverse correctly
// use the ftp utils implementation of the compact path
path = FtpUtils.compactPath(path);
// not stepwise should change directory in one operation
if (!endpoint.getConfiguration().isStepwise()) {
doChangeDirectory(path);
return;
}
// 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);
}
}
示例3: ensureRelativeFtpDirectory
import org.apache.camel.util.FileUtil; //导入方法依赖的package包/类
/**
* Checks whether directory used in ftp/ftps/sftp endpoint URI is relative.
* Absolute path will be converted to relative path and a WARN will be printed.
* @see <a href="http://camel.apache.org/ftp2.html">FTP/SFTP/FTPS Component</a>
* @param ftpComponent
* @param configuration
*/
public static void ensureRelativeFtpDirectory(Component ftpComponent, RemoteFileConfiguration configuration) {
if (FileUtil.hasLeadingSeparator(configuration.getDirectoryName())) {
String relativePath = FileUtil.stripLeadingSeparator(configuration.getDirectoryName());
LOG.warn(String.format("%s doesn't support absolute paths, \"%s\" will be converted to \"%s\". "
+ "After Camel 2.16, absolute paths will be invalid.",
ftpComponent.getClass().getSimpleName(),
configuration.getDirectoryName(),
relativePath));
configuration.setDirectory(relativePath);
configuration.setDirectoryName(relativePath);
}
}
示例4: asRemoteFile
import org.apache.camel.util.FileUtil; //导入方法依赖的package包/类
private RemoteFile<FTPFile> asRemoteFile(String absolutePath, FTPFile file, String charset) {
RemoteFile<FTPFile> answer = new RemoteFile<FTPFile>();
answer.setCharset(charset);
answer.setEndpointPath(endpointPath);
answer.setFile(file);
answer.setFileNameOnly(file.getName());
answer.setFileLength(file.getSize());
answer.setDirectory(file.isDirectory());
if (file.getTimestamp() != null) {
answer.setLastModified(file.getTimestamp().getTimeInMillis());
}
answer.setHostname(((RemoteFileConfiguration) endpoint.getConfiguration()).getHost());
// absolute or relative path
boolean absolute = FileUtil.hasLeadingSeparator(absolutePath);
answer.setAbsolute(absolute);
// create a pseudo absolute name
String dir = FileUtil.stripTrailingSeparator(absolutePath);
String absoluteFileName = FileUtil.stripLeadingSeparator(dir + "/" + file.getName());
// if absolute start with a leading separator otherwise let it be relative
if (absolute) {
absoluteFileName = "/" + absoluteFileName;
}
answer.setAbsoluteFilePath(absoluteFileName);
// the relative filename, skip the leading endpoint configured path
String relativePath = ObjectHelper.after(absoluteFileName, endpointPath);
// skip leading /
relativePath = FileUtil.stripLeadingSeparator(relativePath);
answer.setRelativeFilePath(relativePath);
// the file name should be the relative path
answer.setFileName(answer.getRelativeFilePath());
return answer;
}
示例5: 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);
}
}