Пример #1
0
  /**
   * @param channel
   * @param extendedType
   * @param data
   * @throws IOException
   */
  public synchronized void sendChannelExtData(Channel channel, int extendedType, byte[] data)
      throws IOException {
    channel.getRemoteWindow().consumeWindowSpace(data.length);

    int sent = 0;
    int block;
    int remaining;
    long max;
    byte[] buffer;
    ChannelDataWindow window = channel.getRemoteWindow();

    while (sent < data.length) {
      remaining = data.length - sent;
      max =
          ((window.getWindowSpace() < channel.getRemotePacketSize())
                  && (window.getWindowSpace() > 0))
              ? window.getWindowSpace()
              : channel.getRemotePacketSize();
      block = (max < remaining) ? (int) max : remaining;
      channel.remoteWindow.consumeWindowSpace(block);
      buffer = new byte[block];
      System.arraycopy(data, sent, buffer, 0, block);

      SshMsgChannelExtendedData msg =
          new SshMsgChannelExtendedData(channel.getRemoteChannelId(), extendedType, buffer);
      transport.sendMessage(msg, this);

      /*                if (type != null) {
          channel.sendChannelExtData(type.intValue(), buffer);
      } else {
          channel.sendChannelData(buffer);
      }*/
      sent += block;
    }
  }
Пример #2
0
  /**
   * @param channel
   * @param data
   * @throws IOException
   */
  public synchronized void sendChannelData(Channel channel, byte[] data) throws IOException {
    synchronized (channel.getState()) {
      if (log.isDebugEnabled()) {
        log.debug(
            "Sending "
                + String.valueOf(data.length)
                + " bytes for channel id "
                + String.valueOf(channel.getLocalChannelId()));
      }

      int sent = 0;
      int block;
      int remaining;
      long max;
      byte[] buffer;
      ChannelDataWindow window = channel.getRemoteWindow();

      while (sent < data.length) {
        remaining = data.length - sent;
        max =
            ((window.getWindowSpace() < channel.getRemotePacketSize())
                    && (window.getWindowSpace() > 0))
                ? window.getWindowSpace()
                : channel.getRemotePacketSize();
        block = (max < remaining) ? (int) max : remaining;
        channel.remoteWindow.consumeWindowSpace(block);
        buffer = new byte[block];
        System.arraycopy(data, sent, buffer, 0, block);

        SshMsgChannelData msg = new SshMsgChannelData(channel.getRemoteChannelId(), buffer);
        transport.sendMessage(msg, this);

        /*                if (type != null) {
        channel.sendChannelExtData(type.intValue(), buffer);
                   } else {
                       channel.sendChannelData(buffer);
                   }*/
        sent += block;
      }
    }
  }