當前位置: 首頁>>代碼示例>>Java>>正文


Java SftpATTRS.getSize方法代碼示例

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


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

示例1: createStatInfo

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,代碼來源:SftpSupport.java

示例2: getFileStatus

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,代碼來源:SFTPFileSystem.java

示例3: SFTPFile2

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,代碼來源:SFTPFile2.java

示例4: LsEntry2EncFSFileInfo

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,代碼來源:FileProvider6.java

示例5: resolveResource

import com.jcraft.jsch.SftpATTRS; //導入方法依賴的package包/類
/**
 * This method is similar to getResource, except that the returned resource is fully initialized
 * (resolved in the sftp repository), and that the given string is a full remote path
 *
 * @param path
 *            the full remote path in the repository of the resource
 * @return a fully initialized resource, able to answer to all its methods without needing any
 *         further connection
 */
@SuppressWarnings("unchecked")
public Resource resolveResource(String path) {
    try {
        List<LsEntry> r = getSftpChannel(path).ls(getPath(path));
        if (r != null) {
            SftpATTRS attrs = r.get(0).getAttrs();
            return new BasicResource(path, true, attrs.getSize(),
                        attrs.getMTime() * MILLIS_PER_SECOND, false);
        }
    } catch (Exception e) {
        Message.debug("Error while resolving resource " + path, e);
        // silent fail, return nonexistent resource
    }

    return new BasicResource(path, false, 0, 0, false);
}
 
開發者ID:apache,項目名稱:ant-ivy,代碼行數:26,代碼來源:SFTPRepository.java

示例6: toMetaData

import com.jcraft.jsch.SftpATTRS; //導入方法依賴的package包/類
private ExternalResourceMetaData toMetaData(URI uri, SftpATTRS attributes) {
    long lastModified = -1;
    long contentLength = -1;

    if ((attributes.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_ACMODTIME) != 0) {
        lastModified = attributes.getMTime() * 1000;
    }
    if ((attributes.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_SIZE) != 0) {
        contentLength = attributes.getSize();
    }

    return new DefaultExternalResourceMetaData(uri, lastModified, contentLength);
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:14,代碼來源:SftpResourceAccessor.java

示例7: setFromAttrs

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,代碼來源:SftpStorage.java

示例8: getFileStatus

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,代碼來源:SftpLightWeightFileSystem.java

示例9: toMetaData

import com.jcraft.jsch.SftpATTRS; //導入方法依賴的package包/類
private ExternalResourceMetaData toMetaData(URI uri, SftpATTRS attributes) {
    long lastModified = -1;
    long contentLength = -1;

    if ((attributes.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_ACMODTIME) != 0) {
        lastModified = attributes.getMTime() * 1000;
    }
    if ((attributes.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_SIZE) != 0) {
        contentLength = attributes.getSize();
    }

    return new DefaultExternalResourceMetaData(uri, lastModified, contentLength, null, null);
}
 
開發者ID:Pushjet,項目名稱:Pushjet-Android,代碼行數:14,代碼來源:SftpResourceAccessor.java

示例10: getFileStatus

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,代碼來源:SftpLightWeightFileSystem.java

示例11: getAttribute

import com.jcraft.jsch.SftpATTRS; //導入方法依賴的package包/類
public Attribute getAttribute(VFSNode node, SftpATTRS attrs, String name, boolean isDir, boolean update)
        throws VrsException
{

    // Optimization: only update if a SftpAttribute AND an update is
    // requested:
    if (name == null)
        return null;

    // initialize attributes if not yet fetched!
    if (attrs == null)
    {
        attrs = this.getSftpAttrs(node.getPath());
    }

    // get attributes from same holder:

    if (name.compareTo(ATTR_MODIFICATION_TIME) == 0)
    {
        return AttributeUtil.createDateFromMilliesSinceEpoch(name, getModificationTime(attrs));
    }
    else if (name.compareTo(ATTR_LASTACCESS_TIME) == 0)
    {
        return new Attribute(AttributeType.DATETIME, name, getAccessTime(attrs));
    }
    else if (name.compareTo(ATTR_FILE_SIZE) == 0)
    {
        return new Attribute(name, attrs.getSize());
    }
    else if (name.compareTo(ATTR_UNIX_USERID) == 0)
    {
        return new Attribute(name, attrs.getUId());
    }
    else if (name.compareTo(ATTR_UNIX_GROUPID) == 0)
    {
        return new Attribute(name, attrs.getGId());
    }
    else if (name.compareTo(ATTR_UNIX_FILE_MODE) == 0)
    {
        // note sftp attributes return higher value the (8)07777 (isdir and
        // islink)
        return new Attribute(name, "0" + Integer.toOctalString(attrs.getPermissions() % 07777));
    }

    return null;
}
 
開發者ID:NLeSC,項目名稱:vbrowser,代碼行數:47,代碼來源:SftpFileSystem.java

示例12: getLength

import com.jcraft.jsch.SftpATTRS; //導入方法依賴的package包/類
public long getLength(SftpATTRS attrs)
{
    return attrs.getSize();
}
 
開發者ID:NLeSC,項目名稱:vbrowser,代碼行數:5,代碼來源:SftpFileSystem.java


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