java jsch isdir_Java SftpATTRS.isDir方法代碼示例

本文整理匯總了Java中com.jcraft.jsch.SftpATTRS.isDir方法的典型用法代碼示例。如果您正苦於以下問題:Java SftpATTRS.isDir方法的具體用法?Java SftpATTRS.isDir怎麽用?Java SftpATTRS.isDir使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.jcraft.jsch.SftpATTRS的用法示例。

在下文中一共展示了SftpATTRS.isDir方法的21個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。

示例1: createStatInfo

​點讚 4

import com.jcraft.jsch.SftpATTRS; //導入方法依賴的package包/類

private StatInfo createStatInfo(String dirName, String baseName, SftpATTRS attrs, ChannelSftp cftp) throws SftpException {

String linkTarget = null;

if (attrs.isLink()) {

String path = dirName + '/' + baseName;

RemoteStatistics.ActivityID activityID = RemoteStatistics.startChannelActivity("readlink", path); // NOI18N

try {

if (LOG.isLoggable(Level.FINE)) {

LOG.log(Level.FINE, "performing readlink {0}", path);

}

linkTarget = cftp.readlink(path);

} finally {

RemoteStatistics.stopChannelActivity(activityID);

}

}

Date lastModified = new Date(attrs.getMTime() * 1000L);

StatInfo result = new FileInfoProvider.StatInfo(baseName, attrs.getUId(), attrs.getGId(), attrs.getSize(),

attrs.isDir(), attrs.isLink(), linkTarget, attrs.getPermissions(), lastModified);

return result;

}

開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:20,

示例2: LsEntry2EncFSFileInfo

​點讚 4

import com.jcraft.jsch.SftpATTRS; //導入方法依賴的package包/類

private EncFSFileInfo LsEntry2EncFSFileInfo(String parentPath, LsEntry file){

EncFSFileInfo result;

try {

String name = file.getFilename();

SftpATTRS attrs = file.getAttrs();

long mtime = attrs.getMTime();

boolean isDir = attrs.isDir();

long length = attrs.getSize();

String relativePath=this.getRelativePathFromAbsolutePath(parentPath);

if (name.endsWith("/")) name=name.substring(0,name.length()-1);

result = new EncFSFileInfo(name,relativePath,isDir,mtime,length,true,true,true);

} catch (Exception e){

throw new RuntimeException(e);

}

return result;

}

開發者ID:starn,項目名稱:encdroidMC,代碼行數:23,

示例3: getFileStatus

​點讚 3

import com.jcraft.jsch.SftpATTRS; //導入方法依賴的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()));

}

開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:47,

示例4: SFTPFile2

​點讚 3

import com.jcraft.jsch.SftpATTRS; //導入方法依賴的package包/類

public SFTPFile2(SftpATTRS stat, String filename, Uri uri) {

if (filename == null){

throw new IllegalArgumentException("filename cannot be null");

}

if (uri == null) {

throw new IllegalArgumentException("uri cannot be null");

}

mUriString = uri.toString();

mName = filename;

mIsDirectory = stat.isDir();

mIsFile = !stat.isDir();

mLastModified = stat.getMTime();

//TODO : permissions

mCanRead = true;

mCanWrite = true;

mLength = stat.getSize();

}

開發者ID:archos-sa,項目名稱:aos-FileCoreLibrary,代碼行數:19,

示例5: _buildFiles

​點讚 3

import com.jcraft.jsch.SftpATTRS; //導入方法依賴的package包/類

private List _buildFiles(Vector ls,String dir) throws Exception {

if (ls != null && ls.size() >= 0) {

List list = new ArrayList();

for (int i = 0; i < ls.size(); i++) {

LsEntry f = (LsEntry) ls.get(i);

String nm = f.getFilename();

if (nm.equals(".") || nm.equals(".."))

continue;

SftpATTRS attr = f.getAttrs();

FileBean fileBean=new FileBean();

if (attr.isDir()) {

fileBean.setDir(true);

} else {

fileBean.setDir(false);

}

fileBean.setAttrs(attr);

fileBean.setFilePath(dir);

fileBean.setFileName(nm);

list.add(fileBean);

}

return list;

}

return null;

}

開發者ID:xnx3,項目名稱:xnx3,代碼行數:26,

示例6: existsDirectory

​點讚 3

import com.jcraft.jsch.SftpATTRS; //導入方法依賴的package包/類

/**

* Determines whether a directory exists or not

* 如果是文件,也會拋出異常,返回 false

*

* @param remoteDirectoryPath

* @return true if exists, false otherwise

* @throws IOException thrown if any I/O error occurred.

*/

@Override

public boolean existsDirectory(String remoteDirectoryPath) {

try {

// System.out.println(channel.realpath(remoteFilePath));

SftpATTRS attrs = channel.stat(remoteDirectoryPath);

return attrs.isDir();

} catch (SftpException e) {

// e.printStackTrace();

return false;

}

// String originalWorkingDirectory = getWorkingDirectory();

// try {

// changeDirectory(remoteDirectoryPath);

// } catch (FtpException e) {

// //文件夾不存在,會拋出異常。

// return false;

// }

// //恢複 ftpClient 當前工作目錄屬性

// changeDirectory(originalWorkingDirectory);

// return true;

}

開發者ID:h819,項目名稱:spring-boot,代碼行數:33,

示例7: traverse

​點讚 3

import com.jcraft.jsch.SftpATTRS; //導入方法依賴的package包/類

/**

* Delete directory and its content recursively.

*

* @param channel

* open channel to SFTP server

* @param path

* path of the directory

* @throws SftpException

* when something went wrong

*/

@SuppressWarnings("unchecked")

private void traverse(ChannelSftp channel, String path)

throws SftpException {

SftpATTRS attrs = channel.stat(path);

if (attrs.isDir()) {

Vector files = channel.ls(path);

if (files != null && files.size() > 0) {

Iterator it = files.iterator();

while (it.hasNext()) {

LsEntry entry = it.next();

if ((!entry.getFilename().equals(".")) && (!entry.getFilename().equals(".."))) {

traverse(channel, path + "/" + entry.getFilename());

}

}

}

channel.rmdir(path);

} else {

channel.rm(path);

}

}

開發者ID:psnc-dl,項目名稱:darceo,代碼行數:31,

示例8: getFileType

​點讚 3

import com.jcraft.jsch.SftpATTRS; //導入方法依賴的package包/類

public FileType getFileType(String filename) throws KettleJobException

{

try {

SftpATTRS attrs=c.stat(filename);

if (attrs == null)return FileType.IMAGINARY;

if ((attrs.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_PERMISSIONS) == 0)

throw new KettleJobException("Unknown permissions error");

if (attrs.isDir())

return FileType.FOLDER;

else

return FileType.FILE;

} catch (Exception e) {

throw new KettleJobException(e);

}

}

開發者ID:icholy,項目名稱:geokettle-2.0,代碼行數:18,

示例9: folderExists

​點讚 3

import com.jcraft.jsch.SftpATTRS; //導入方法依賴的package包/類

public boolean folderExists(String foldername)

{

boolean retval =false;

try {

SftpATTRS attrs=c.stat(foldername);

if (attrs == null) return false;

if ((attrs.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_PERMISSIONS) == 0)

throw new KettleJobException("Unknown permissions error");

retval=attrs.isDir();

} catch (Exception e) {

// Folder can not be found!

}

return retval;

}

開發者ID:icholy,項目名稱:geokettle-2.0,代碼行數:17,

示例10: folderExists

​點讚 3

import com.jcraft.jsch.SftpATTRS; //導入方法依賴的package包/類

public boolean folderExists(String foldername)

{

boolean retval =false;

try {

SftpATTRS attrs=c.stat(foldername);

if (attrs == null) return false;

if ((attrs.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_PERMISSIONS) == 0)

throw new KettleJobException("Unknown permissions error");

retval=attrs.isDir();

} catch (Exception e) {

// Folder can not be found!

}

return retval;

}

開發者ID:yintaoxue,項目名稱:read-open-source-code,代碼行數:17,

示例11: getFileType

​點讚 3

import com.jcraft.jsch.SftpATTRS; //導入方法依賴的package包/類

public FileType getFileType( String filename ) throws KettleJobException {

try {

SftpATTRS attrs = c.stat( filename );

if ( attrs == null ) {

return FileType.IMAGINARY;

}

if ( ( attrs.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_PERMISSIONS ) == 0 ) {

throw new KettleJobException( "Unknown permissions error" );

}

if ( attrs.isDir() ) {

return FileType.FOLDER;

} else {

return FileType.FILE;

}

} catch ( Exception e ) {

throw new KettleJobException( e );

}

}

開發者ID:pentaho,項目名稱:pentaho-kettle,代碼行數:21,

示例12: folderExists

​點讚 3

import com.jcraft.jsch.SftpATTRS; //導入方法依賴的package包/類

public boolean folderExists( String foldername ) {

boolean retval = false;

try {

SftpATTRS attrs = c.stat( foldername );

if ( attrs == null ) {

return false;

}

if ( ( attrs.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_PERMISSIONS ) == 0 ) {

throw new KettleJobException( "Unknown permissions error" );

}

retval = attrs.isDir();

} catch ( Exception e ) {

// Folder can not be found!

}

return retval;

}

開發者ID:pentaho,項目名稱:pentaho-kettle,代碼行數:19,

示例13: setFromAttrs

​點讚 2

import com.jcraft.jsch.SftpATTRS; //導入方法依賴的package包/類

private void setFromAttrs(FileEntry fileEntry, SftpATTRS attrs) {

fileEntry.isDirectory = attrs.isDir();

fileEntry.canRead = true; // currently not inferred from the

// permissions.

fileEntry.canWrite = true; // currently not inferred from the

// permissions.

fileEntry.lastModifiedTime = ((long) attrs.getMTime()) * 1000;

if (fileEntry.isDirectory)

fileEntry.sizeInBytes = 0;

else

fileEntry.sizeInBytes = attrs.getSize();

}

開發者ID:PhilippC,項目名稱:keepass2android,代碼行數:13,

示例14: isDir

​點讚 2

import com.jcraft.jsch.SftpATTRS; //導入方法依賴的package包/類

public boolean isDir(String targetDir) throws SftpException {

try {

SftpATTRS attrs = channelSftp.stat(targetDir);

return attrs.isDir();

} catch (SftpException sftpException) {

return false;

}

}

開發者ID:gchq,項目名稱:stroom-agent,代碼行數:9,

示例15: isDir

​點讚 2

import com.jcraft.jsch.SftpATTRS; //導入方法依賴的package包/類

private boolean isDir(String path) {

ChannelSftp sftp = getSftpChannel();

try {

SftpATTRS attrs = sftp.stat(path);

return attrs.isDir();

} catch (SftpException e) {

throw new SshException(e);

}

}

開發者ID:huiyu,項目名稱:ssh4j,代碼行數:10,

示例16: getFileStatus

​點讚 2

import com.jcraft.jsch.SftpATTRS; //導入方法依賴的package包/類

@Override

public FileStatus getFileStatus(Path path) throws IOException {

ChannelSftp channelSftp = null;

ChannelExec channelExec1 = null;

ChannelExec channelExec2 = null;

try {

channelSftp = fsHelper.getSftpChannel();

SftpATTRS sftpAttrs = channelSftp.stat(path.toString());

FsPermission permission = new FsPermission((short) sftpAttrs.getPermissions());

channelExec1 = fsHelper.getExecChannel("id " + sftpAttrs.getUId());

String userName = IOUtils.toString(channelExec1.getInputStream());

channelExec2 = fsHelper.getExecChannel("id " + sftpAttrs.getGId());

String groupName = IOUtils.toString(channelExec2.getInputStream());

FileStatus fs =

new FileStatus(sftpAttrs.getSize(), sftpAttrs.isDir(), 1, 0l, (long) sftpAttrs.getMTime(),

(long) sftpAttrs.getATime(), permission, StringUtils.trimToEmpty(userName),

StringUtils.trimToEmpty(groupName), path);

return fs;

} catch (SftpException e) {

throw new IOException(e);

} finally {

safeDisconnect(channelSftp);

safeDisconnect(channelExec1);

safeDisconnect(channelExec2);

}

}

開發者ID:Hanmourang,項目名稱:Gobblin,代碼行數:33,

示例17: remoteDirExists

​點讚 2

import com.jcraft.jsch.SftpATTRS; //導入方法依賴的package包/類

private boolean remoteDirExists(String remoteDir) {

try {

SftpATTRS stat = channel.stat(remoteDir);

return stat.isDir();

} catch (SftpException e) {

return false;

}

}

開發者ID:neowu,項目名稱:cmn-project,代碼行數:9,

示例18: mkdirs

​點讚 2

import com.jcraft.jsch.SftpATTRS; //導入方法依賴的package包/類

private void mkdirs(String directory, ChannelSftp c) throws SftpException {

try {

SftpATTRS att = c.stat(directory);

if (att != null && att.isDir()) {

return;

}

} catch (SftpException ex) {

if (directory.indexOf('/') != -1) {

mkdirs(directory.substring(0, directory.lastIndexOf('/')), c);

}

c.mkdir(directory);

}

}

開發者ID:apache,項目名稱:ant-ivy,代碼行數:14,

示例19: execute

​點讚 2

import com.jcraft.jsch.SftpATTRS; //導入方法依賴的package包/類

/**

* Carry out the transfer.

* @throws IOException on i/o errors

* @throws JSchException on errors detected by scp

*/

@Override

public void execute() throws IOException, JSchException {

final ChannelSftp channel = openSftpChannel();

try {

channel.connect();

try {

final SftpATTRS attrs = channel.stat(remoteFile);

if (attrs.isDir() && !remoteFile.endsWith("/")) {

remoteFile = remoteFile + "/";

}

} catch (final SftpException ee) {

// Ignored

}

getDir(channel, remoteFile, localFile);

} catch (final SftpException e) {

final JSchException schException =

new JSchException("Could not get '" + remoteFile + "' to '"

+ localFile + "' - " + e.toString());

schException.initCause(e);

throw schException;

} finally {

if (channel != null) {

channel.disconnect();

}

}

log("done\n");

}

開發者ID:apache,項目名稱:ant,代碼行數:33,

示例20: getFileStatus

​點讚 2

import com.jcraft.jsch.SftpATTRS; //導入方法依賴的package包/類

@Override

public FileStatus getFileStatus(Path path) throws IOException {

ChannelSftp channelSftp = null;

ChannelExec channelExec1 = null;

ChannelExec channelExec2 = null;

try {

channelSftp = this.fsHelper.getSftpChannel();

SftpATTRS sftpAttrs = channelSftp.stat(HadoopUtils.toUriPath(path));

FsPermission permission = new FsPermission((short) sftpAttrs.getPermissions());

channelExec1 = this.fsHelper.getExecChannel("id " + sftpAttrs.getUId());

String userName = IOUtils.toString(channelExec1.getInputStream());

channelExec2 = this.fsHelper.getExecChannel("id " + sftpAttrs.getGId());

String groupName = IOUtils.toString(channelExec2.getInputStream());

FileStatus fs =

new FileStatus(sftpAttrs.getSize(), sftpAttrs.isDir(), 1, 0l, sftpAttrs.getMTime(), sftpAttrs.getATime(),

permission, StringUtils.trimToEmpty(userName), StringUtils.trimToEmpty(groupName), path);

return fs;

} catch (SftpException e) {

throw new IOException(e);

} finally {

safeDisconnect(channelSftp);

safeDisconnect(channelExec1);

safeDisconnect(channelExec2);

}

}

開發者ID:apache,項目名稱:incubator-gobblin,代碼行數:31,

示例21: scanRecursive

​點讚 2

import com.jcraft.jsch.SftpATTRS; //導入方法依賴的package包/類

void scanRecursive(ChannelSftp channel, String path) throws SftpException, SQLException {

if (progressListener != null) progressListener.onNewDir(path);

List entries = channel.ls(path);

for (ChannelSftp.LsEntry entry : entries) {

if (".".equals(entry.getFilename()) || "..".equals(entry.getFilename()))

continue;

SftpATTRS attrs = entry.getAttrs();

if (attrs.isDir()) {

scanRecursive(channel, path + File.separator + entry.getFilename());

}

else {

String name = entry.getFilename().toLowerCase();

int extensionPos = name.indexOf(".mp3");

if (extensionPos == -1)

continue;

String base = name.substring(0, extensionPos);

Song song = new Song();

String fullPath = path + File.separator + name;

fullPathArg.setValue(fullPath);

if (songDao.query(songInDbQuery).isEmpty()) {

Log.v(TAG, "adding to db: " + fullPath);

song.setFullPath(fullPath);

song.setName(base);

songDao.create(song);

String wordsSource = path.toLowerCase() + File.separator + base;

Matcher matcher = wordPattern.matcher(wordsSource);

for (; matcher.find(); ) {

WordMatch word = new WordMatch();

String wordStr = matcher.group(1);

word.setWord(wordStr);

word.setSong(song);

wordDao.create(word);

}

}

else {

Log.v(TAG, "already in db: " + fullPath);

}

}

}

}

開發者ID:egueli,項目名稱:ETStreamHome,代碼行數:47,

注:本文中的com.jcraft.jsch.SftpATTRS.isDir方法示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值