001: /*
002: * SSHTools - Java SSH2 API
003: *
004: * Copyright (C) 2002-2003 Lee David Painter and Contributors.
005: *
006: * Contributions made by:
007: *
008: * Brett Smith
009: * Richard Pernavas
010: * Erwin Bolwidt
011: *
012: * This program is free software; you can redistribute it and/or
013: * modify it under the terms of the GNU General Public License
014: * as published by the Free Software Foundation; either version 2
015: * of the License, or (at your option) any later version.
016: *
017: * This program is distributed in the hope that it will be useful,
018: * but WITHOUT ANY WARRANTY; without even the implied warranty of
019: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
020: * GNU General Public License for more details.
021: *
022: * You should have received a copy of the GNU General Public License
023: * along with this program; if not, write to the Free Software
024: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
025: */
026: package com.sshtools.j2ssh.connection;
027:
028: import com.sshtools.j2ssh.io.ByteArrayReader;
029: import com.sshtools.j2ssh.io.ByteArrayWriter;
030: import com.sshtools.j2ssh.transport.InvalidMessageException;
031: import com.sshtools.j2ssh.transport.SshMessage;
032:
033: import java.io.IOException;
034:
035: /**
036: *
037: *
038: * @author $author$
039: * @version $Revision: 1.21 $
040: */
041: public class SshMsgChannelExtendedData extends SshMessage {
042: /** */
043: public final static int SSH_MSG_CHANNEL_EXTENDED_DATA = 95;
044:
045: /** */
046: public final static int SSH_EXTENDED_DATA_STDERR = 1;
047: private byte[] channelData;
048: private int dataTypeCode;
049: private long recipientChannel;
050:
051: /**
052: * Creates a new SshMsgChannelExtendedData object.
053: *
054: * @param recipientChannel
055: * @param dataTypeCode
056: * @param channelData
057: */
058: public SshMsgChannelExtendedData(long recipientChannel,
059: int dataTypeCode, byte[] channelData) {
060: super (SSH_MSG_CHANNEL_EXTENDED_DATA);
061: this .recipientChannel = recipientChannel;
062: this .dataTypeCode = dataTypeCode;
063: this .channelData = channelData;
064: }
065:
066: /**
067: * Creates a new SshMsgChannelExtendedData object.
068: */
069: public SshMsgChannelExtendedData() {
070: super (SSH_MSG_CHANNEL_EXTENDED_DATA);
071: }
072:
073: /**
074: *
075: *
076: * @return
077: */
078: public byte[] getChannelData() {
079: return channelData;
080: }
081:
082: /**
083: *
084: *
085: * @return
086: */
087: public int getDataTypeCode() {
088: return dataTypeCode;
089: }
090:
091: /**
092: *
093: *
094: * @return
095: */
096: public String getMessageName() {
097: return "SSH_MSG_CHANNEL_EXTENDED_DATA";
098: }
099:
100: /**
101: *
102: *
103: * @return
104: */
105: public long getRecipientChannel() {
106: return recipientChannel;
107: }
108:
109: /**
110: *
111: *
112: * @param baw
113: *
114: * @throws InvalidMessageException
115: */
116: protected void constructByteArray(ByteArrayWriter baw)
117: throws InvalidMessageException {
118: try {
119: baw.writeInt(recipientChannel);
120: baw.writeInt(dataTypeCode);
121:
122: if (channelData != null) {
123: baw.writeBinaryString(channelData);
124: } else {
125: baw.writeString("");
126: }
127: } catch (IOException ioe) {
128: throw new InvalidMessageException("Invalid message data");
129: }
130: }
131:
132: /**
133: *
134: *
135: * @param bar
136: *
137: * @throws InvalidMessageException
138: */
139: protected void constructMessage(ByteArrayReader bar)
140: throws InvalidMessageException {
141: try {
142: recipientChannel = bar.readInt();
143: dataTypeCode = (int) bar.readInt();
144:
145: if (bar.available() > 0) {
146: channelData = bar.readBinaryString();
147: }
148: } catch (IOException ioe) {
149: throw new InvalidMessageException("Invalid message data");
150: }
151: }
152: }
|