org.apache.sshd.common.util.buffer.Buffer.putString()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(186)

本文整理了Java中org.apache.sshd.common.util.buffer.Buffer.putString()方法的一些代码示例,展示了Buffer.putString()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer.putString()方法的具体详情如下:
包路径:org.apache.sshd.common.util.buffer.Buffer
类名称:Buffer
方法名:putString

Buffer.putString介绍

[英]Encodes the Objects#toString(Object,String) value of each member
[中]对每个成员的Objects#toString(Object,String)值进行编码

代码示例

代码示例来源:origin: org.apache.sshd/sshd-common

public void putString(String string) {
  putString(string, StandardCharsets.UTF_8);
}

代码示例来源:origin: org.apache.sshd/sshd-core

@Override
public IoWriteFuture sendDebugMessage(boolean display, Object msg, String lang) throws IOException {
  String text = Objects.toString(msg, "");
  lang = (lang == null) ? "" : lang;
  Buffer buffer = createBuffer(SshConstants.SSH_MSG_DEBUG,
      text.length() + lang.length() + Integer.SIZE /* a few extras */);
  buffer.putBoolean(display);
  buffer.putString(text);
  buffer.putString(lang);
  return writePacket(buffer);
}

代码示例来源:origin: org.apache.sshd/sshd-osgi

@Override
public IoWriteFuture sendDebugMessage(boolean display, Object msg, String lang) throws IOException {
  String text = Objects.toString(msg, "");
  lang = (lang == null) ? "" : lang;
  Buffer buffer = createBuffer(SshConstants.SSH_MSG_DEBUG,
    text.length() + lang.length() + Integer.SIZE /* a few extras */);
  buffer.putBoolean(display);
  buffer.putString(text);
  buffer.putString(lang);
  return writePacket(buffer);
}

代码示例来源:origin: org.apache.sshd/sshd-core

public <B extends Buffer> B append(B buffer) {
  buffer.putString(getInteractionName());
  buffer.putString(getInteractionInstruction());
  buffer.putString(getLanguageTag());
  List<PromptEntry> entries = getPrompts();
  int numEntries = GenericUtils.size(entries);
  buffer.putInt(numEntries);
  for (int index = 0; index < numEntries; index++) {
    PromptEntry e = entries.get(index);
    e.append(buffer);
  }
  return buffer;
}

代码示例来源:origin: org.apache.sshd/sshd-osgi

public <B extends Buffer> B append(B buffer) {
  buffer.putString(getInteractionName());
  buffer.putString(getInteractionInstruction());
  buffer.putString(getLanguageTag());
  List<PromptEntry> entries = getPrompts();
  int numEntries = GenericUtils.size(entries);
  buffer.putInt(numEntries);
  for (int index = 0; index < numEntries; index++) {
    PromptEntry e = entries.get(index);
    e.append(buffer);
  }
  return buffer;
}

代码示例来源:origin: org.apache.sshd/sshd-sftp

protected void sendStatus(Buffer buffer, int id, int substatus, String msg, String lang) throws IOException {
  if (log.isDebugEnabled()) {
    log.debug("doSendStatus({})[id={}] SSH_FXP_STATUS (substatus={}, lang={}, msg={})",
         getServerSession(), id, SftpConstants.getStatusName(substatus), lang, msg);
  }
  buffer.putByte((byte) SftpConstants.SSH_FXP_STATUS);
  buffer.putInt(id);
  buffer.putInt(substatus);
  buffer.putString(msg);
  buffer.putString(lang);
  send(buffer);
}

代码示例来源:origin: org.apache.sshd/sshd-sftp

@Override
  public void copyFile(String src, String dst, boolean overwriteDestination) throws IOException {
    Buffer buffer = getCommandBuffer(Integer.BYTES + GenericUtils.length(src)
        + Integer.BYTES + GenericUtils.length(dst)
        + 1 /* override destination */);
    buffer.putString(src);
    buffer.putString(dst);
    buffer.putBoolean(overwriteDestination);
    sendAndCheckExtendedCommandStatus(buffer);
  }
}

代码示例来源:origin: org.apache.sshd/sshd-sftp

protected List<OpenSSHExtension> appendOpenSSHExtensions(Buffer buffer) {
  List<OpenSSHExtension> extList = resolveOpenSSHExtensions(getServerSession());
  if (GenericUtils.isEmpty(extList)) {
    return extList;
  }
  for (OpenSSHExtension ext : extList) {
    buffer.putString(ext.getName());
    buffer.putString(ext.getVersion());
  }
  return extList;
}

代码示例来源:origin: org.apache.sshd/sshd-sftp

protected void sendHandle(Buffer buffer, int id, String handle) throws IOException {
  buffer.putByte((byte) SftpConstants.SSH_FXP_HANDLE);
  buffer.putInt(id);
  buffer.putString(handle);
  send(buffer);
}

代码示例来源:origin: org.apache.sshd/sshd-core

public <B extends Buffer> B append(B buffer) {
  buffer.putString(getPrompt());
  buffer.putBoolean(isEcho());
  return buffer;
}

代码示例来源:origin: org.apache.sshd/sshd-sftp

/**
 * @param extraSize Extra size - besides the extension name
 * @return A {@link Buffer} with the extension name set
 */
protected Buffer getCommandBuffer(int extraSize) {
  String opcode = getName();
  Buffer buffer = new ByteArrayBuffer(Integer.BYTES + GenericUtils.length(opcode) + extraSize + Byte.SIZE, false);
  buffer.putString(opcode);
  return buffer;
}

代码示例来源:origin: org.apache.sshd/sshd-osgi

public <B extends Buffer> B append(B buffer) {
  buffer.putString(getPrompt());
  buffer.putBoolean(isEcho());
  return buffer;
}

代码示例来源:origin: org.apache.sshd/sshd-osgi

protected IoWriteFuture sendChannelOpenFailure(Buffer buffer, int sender, int reasonCode, String message, String lang) throws IOException {
  if (log.isDebugEnabled()) {
    log.debug("sendChannelOpenFailure({}) sender={}, reason={}, lang={}, message='{}'",
       this, sender, SshConstants.getOpenErrorCodeName(reasonCode), lang, message);
  }
  AbstractSession session = getSession();
  Buffer buf = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_OPEN_FAILURE,
    Long.SIZE + GenericUtils.length(message) + GenericUtils.length(lang));
  buf.putInt(sender);
  buf.putInt(reasonCode);
  buf.putString(message);
  buf.putString(lang);
  return session.writePacket(buf);
}

代码示例来源:origin: org.apache.sshd/sshd-core

protected IoWriteFuture sendChannelOpenFailure(Buffer buffer, int sender, int reasonCode, String message, String lang) throws IOException {
  if (log.isDebugEnabled()) {
    log.debug("sendChannelOpenFailure({}) sender={}, reason={}, lang={}, message='{}'",
         this, sender, SshConstants.getOpenErrorCodeName(reasonCode), lang, message);
  }
  AbstractSession session = getSession();
  Buffer buf = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_OPEN_FAILURE,
      Long.SIZE + GenericUtils.length(message) + GenericUtils.length(lang));
  buf.putInt(sender);
  buf.putInt(reasonCode);
  buf.putString(message);
  buf.putString(lang);
  return session.writePacket(buf);
}

代码示例来源:origin: org.apache.sshd/sshd-sftp

@Override
  public SpaceAvailableExtensionInfo available(String path) throws IOException {
    Buffer buffer = getCommandBuffer(path);
    buffer.putString(path);
    buffer = checkExtendedReplyBuffer(receive(sendExtendedCommand(buffer)));

    if (buffer == null) {
      throw new StreamCorruptedException("Missing extended reply data");
    }

    return new SpaceAvailableExtensionInfo(buffer);
  }
}

代码示例来源:origin: org.apache.sshd/sshd-core

@Override
public void addIdentity(KeyPair kp, String comment) throws IOException {
  Buffer buffer = createBuffer(SshAgentConstants.SSH2_AGENTC_ADD_IDENTITY);
  buffer.putKeyPair(kp);
  buffer.putString(comment);
  if (log.isDebugEnabled()) {
    log.debug("addIdentity({})[{}]: {}", KeyUtils.getKeyType(kp), comment, KeyUtils.getFingerPrint(kp.getPublic()));
  }
  buffer = request(prepare(buffer));
  int available = buffer.available();
  int response = (available >= 1) ? buffer.getUByte() : -1;
  if ((available != 1) || (response != SshAgentConstants.SSH_AGENT_SUCCESS)) {
    throw new SshException("Bad addIdentity response (" + SshAgentConstants.getCommandMessageName(response) + ") - available=" + available);
  }
}

代码示例来源:origin: org.apache.sshd/sshd-osgi

@Override
public void addIdentity(KeyPair kp, String comment) throws IOException {
  Buffer buffer = createBuffer(SshAgentConstants.SSH2_AGENTC_ADD_IDENTITY);
  buffer.putKeyPair(kp);
  buffer.putString(comment);
  if (log.isDebugEnabled()) {
    log.debug("addIdentity({})[{}]: {}", KeyUtils.getKeyType(kp), comment, KeyUtils.getFingerPrint(kp.getPublic()));
  }
  buffer = request(prepare(buffer));
  int available = buffer.available();
  int response = (available >= 1) ? buffer.getUByte() : -1;
  if ((available != 1) || (response != SshAgentConstants.SSH_AGENT_SUCCESS)) {
    throw new SshException("Bad addIdentity response (" + SshAgentConstants.getCommandMessageName(response) + ") - available=" + available);
  }
}

代码示例来源:origin: org.apache.sshd/sshd-sftp

public static <B extends Buffer> B writeAclEntry(B buffer, AclEntry acl) {
  Objects.requireNonNull(acl, "No ACL");
  AclEntryType type = acl.type();
  int aclType = encodeAclEntryType(type);
  ValidateUtils.checkTrue(aclType >= 0, "Unknown ACL type: %s", type);
  buffer.putInt(aclType);
  buffer.putInt(encodeAclFlags(acl.flags()));
  buffer.putInt(encodeAclMask(acl.permissions()));
  Principal user = acl.principal();
  buffer.putString(user.getName());
  return buffer;
}

代码示例来源:origin: org.apache.sshd/sshd-osgi

public static <B extends Buffer> B putRawEDDSAPublicKey(B buffer, PublicKey key) {
  ValidateUtils.checkTrue(SecurityUtils.isEDDSACurveSupported(), SecurityUtils.EDDSA + " not supported");
  EdDSAPublicKey edKey = ValidateUtils.checkInstanceOf(key, EdDSAPublicKey.class, "Not an EDDSA public key: %s", key);
  byte[] seed = Ed25519PublicKeyDecoder.getSeedValue(edKey);
  ValidateUtils.checkNotNull(seed, "No seed extracted from key: %s", edKey.getA());
  buffer.putString(KeyPairProvider.SSH_ED25519);
  buffer.putBytes(seed);
  return buffer;
}

代码示例来源:origin: org.apache.sshd/sshd-common

public static <B extends Buffer> B putRawEDDSAPublicKey(B buffer, PublicKey key) {
  ValidateUtils.checkTrue(SecurityUtils.isEDDSACurveSupported(), SecurityUtils.EDDSA + " not supported");
  EdDSAPublicKey edKey = ValidateUtils.checkInstanceOf(key, EdDSAPublicKey.class, "Not an EDDSA public key: %s", key);
  byte[] seed = Ed25519PublicKeyDecoder.getSeedValue(edKey);
  ValidateUtils.checkNotNull(seed, "No seed extracted from key: %s", edKey.getA());
  buffer.putString(KeyPairProvider.SSH_ED25519);
  buffer.putBytes(seed);
  return buffer;
}

相关文章