当前位置: 首页>>代码示例>>Java>>正文


Java KnownHosts.addHostkey方法代码示例

本文整理汇总了Java中com.trilead.ssh2.KnownHosts.addHostkey方法的典型用法代码示例。如果您正苦于以下问题:Java KnownHosts.addHostkey方法的具体用法?Java KnownHosts.addHostkey怎么用?Java KnownHosts.addHostkey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.trilead.ssh2.KnownHosts的用法示例。


在下文中一共展示了KnownHosts.addHostkey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getKnownHosts

import com.trilead.ssh2.KnownHosts; //导入方法依赖的package包/类
/**
 * Build list of known hosts for Trilead library.
 * @return
 */
public KnownHosts getKnownHosts() {
	KnownHosts known = new KnownHosts();

	Cursor c = mDb.query(TABLE_HOSTS + " LEFT OUTER JOIN " + TABLE_KNOWNHOSTS
					+ " ON " + TABLE_HOSTS + "._id = "
					+ TABLE_KNOWNHOSTS + "." + FIELD_KNOWNHOSTS_HOSTID,
			new String[] {FIELD_HOST_HOSTNAME, FIELD_HOST_PORT, FIELD_KNOWNHOSTS_HOSTKEYALGO,
					FIELD_KNOWNHOSTS_HOSTKEY},
			null, null, null, null, null);

	if (c != null) {
		int COL_HOSTNAME = c.getColumnIndexOrThrow(FIELD_HOST_HOSTNAME),
				COL_PORT = c.getColumnIndexOrThrow(FIELD_HOST_PORT),
				COL_HOSTKEYALGO = c.getColumnIndexOrThrow(FIELD_KNOWNHOSTS_HOSTKEYALGO),
				COL_HOSTKEY = c.getColumnIndexOrThrow(FIELD_KNOWNHOSTS_HOSTKEY);

		while (c.moveToNext()) {
			String hostname = c.getString(COL_HOSTNAME);
			String hostkeyalgo = c.getString(COL_HOSTKEYALGO);
			int port = c.getInt(COL_PORT);
			byte[] hostkey = c.getBlob(COL_HOSTKEY);

			if (hostkeyalgo == null || hostkeyalgo.length() == 0) continue;
			if (hostkey == null || hostkey.length == 0) continue;

			try {
				known.addHostkey(new String[] {String.format(Locale.US, "%s:%d", hostname, port)},
						hostkeyalgo, hostkey);
			} catch (Exception e) {
				Log.e(TAG, "Problem while adding a known host from database", e);
			}
		}

		c.close();
	}

	return known;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:43,代码来源:HostDatabase.java

示例2: getKnownHosts

import com.trilead.ssh2.KnownHosts; //导入方法依赖的package包/类
/**
 * Build list of known hosts for Trilead library.
 * @return
 */
public KnownHosts getKnownHosts() {
	KnownHosts known = new KnownHosts();

	synchronized (dbLock) {
		SQLiteDatabase db = this.getReadableDatabase();
		Cursor c = db.query(TABLE_HOSTS, new String[] { FIELD_HOST_HOSTNAME,
				FIELD_HOST_PORT, FIELD_HOST_HOSTKEYALGO, FIELD_HOST_HOSTKEY },
				null, null, null, null, null);

		if (c != null) {
			int COL_HOSTNAME = c.getColumnIndexOrThrow(FIELD_HOST_HOSTNAME),
				COL_PORT = c.getColumnIndexOrThrow(FIELD_HOST_PORT),
				COL_HOSTKEYALGO = c.getColumnIndexOrThrow(FIELD_HOST_HOSTKEYALGO),
				COL_HOSTKEY = c.getColumnIndexOrThrow(FIELD_HOST_HOSTKEY);

			while (c.moveToNext()) {
				String hostname = c.getString(COL_HOSTNAME),
					hostkeyalgo = c.getString(COL_HOSTKEYALGO);
				int port = c.getInt(COL_PORT);
				byte[] hostkey = c.getBlob(COL_HOSTKEY);

				if (hostkeyalgo == null || hostkeyalgo.length() == 0) continue;
				if (hostkey == null || hostkey.length == 0) continue;

				try {
					known.addHostkey(new String[] { String.format("%s:%d", hostname, port) }, hostkeyalgo, hostkey);
				} catch(Exception e) {
					Log.e(TAG, "Problem while adding a known host from database", e);
				}
			}

			c.close();
		}
	}

	return known;
}
 
开发者ID:dragonlinux,项目名称:connectbot,代码行数:42,代码来源:HostDatabase.java


注:本文中的com.trilead.ssh2.KnownHosts.addHostkey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。