本文整理匯總了Java中com.jcraft.jsch.ChannelSftp.realpath方法的典型用法代碼示例。如果您正苦於以下問題:Java ChannelSftp.realpath方法的具體用法?Java ChannelSftp.realpath怎麽用?Java ChannelSftp.realpath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.jcraft.jsch.ChannelSftp
的用法示例。
在下文中一共展示了ChannelSftp.realpath方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getFileStatus
import com.jcraft.jsch.ChannelSftp; //導入方法依賴的package包/類
/**
* Convert the file information in LsEntry to a {@link FileStatus} object. *
*
* @param sftpFile
* @param parentPath
* @return file status
* @throws IOException
*/
private FileStatus getFileStatus(ChannelSftp channel, LsEntry sftpFile,
Path parentPath) throws IOException {
SftpATTRS attr = sftpFile.getAttrs();
long length = attr.getSize();
boolean isDir = attr.isDir();
boolean isLink = attr.isLink();
if (isLink) {
String link = parentPath.toUri().getPath() + "/" + sftpFile.getFilename();
try {
link = channel.realpath(link);
Path linkParent = new Path("/", link);
FileStatus fstat = getFileStatus(channel, linkParent);
isDir = fstat.isDirectory();
length = fstat.getLen();
} catch (Exception e) {
throw new IOException(e);
}
}
int blockReplication = 1;
// Using default block size since there is no way in SFTP channel to know of
// block sizes on server. The assumption could be less than ideal.
long blockSize = DEFAULT_BLOCK_SIZE;
long modTime = attr.getMTime() * 1000; // convert to milliseconds
long accessTime = 0;
FsPermission permission = getPermissions(sftpFile);
// not be able to get the real user group name, just use the user and group
// id
String user = Integer.toString(attr.getUId());
String group = Integer.toString(attr.getGId());
Path filePath = new Path(parentPath, sftpFile.getFilename());
return new FileStatus(length, isDir, blockReplication, blockSize, modTime,
accessTime, permission, user, group, filePath.makeQualified(
this.getUri(), this.getWorkingDirectory()));
}
示例2: getAbsolutePath
import com.jcraft.jsch.ChannelSftp; //導入方法依賴的package包/類
public String getAbsolutePath(String path) throws SshException {
if (path.startsWith("~")) {
path = getHomePath() + path.substring(1);
}
ChannelSftp sftp = getSftpChannel();
try {
return sftp.realpath(path);
} catch (SftpException e) {
throw new SshException(e);
}
}