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.22 $
040: */
041: public class SshMsgChannelData extends SshMessage {
042: /** */
043: public final static int SSH_MSG_CHANNEL_DATA = 94;
044:
045: // The channel data
046: private byte[] channelData;
047:
048: // The recipient channel id
049: private long recipientChannel;
050:
051: /**
052: * Creates a new SshMsgChannelData object.
053: *
054: * @param recipientChannel
055: * @param channelData
056: */
057: public SshMsgChannelData(long recipientChannel, byte[] channelData) {
058: super (SSH_MSG_CHANNEL_DATA);
059: this .recipientChannel = recipientChannel;
060: this .channelData = channelData;
061: }
062:
063: /**
064: * Creates a new SshMsgChannelData object.
065: */
066: public SshMsgChannelData() {
067: super (SSH_MSG_CHANNEL_DATA);
068: }
069:
070: /**
071: *
072: *
073: * @return
074: */
075: public byte[] getChannelData() {
076: return channelData;
077: }
078:
079: /**
080: *
081: *
082: * @return
083: */
084: public long getChannelDataLength() {
085: return channelData.length;
086: }
087:
088: /**
089: *
090: *
091: * @return
092: */
093: public String getMessageName() {
094: return "SSH_MSG_CHANNEL_DATA";
095: }
096:
097: /**
098: *
099: *
100: * @return
101: */
102: public long getRecipientChannel() {
103: return recipientChannel;
104: }
105:
106: /**
107: *
108: *
109: * @param baw
110: *
111: * @throws InvalidMessageException
112: */
113: protected void constructByteArray(ByteArrayWriter baw)
114: throws InvalidMessageException {
115: try {
116: baw.writeInt(recipientChannel);
117:
118: if (channelData != null) {
119: baw.writeBinaryString(channelData);
120: } else {
121: baw.writeInt(0);
122: }
123: } catch (IOException ioe) {
124: throw new InvalidMessageException("Invalid message data");
125: }
126: }
127:
128: /**
129: *
130: *
131: * @param bar
132: *
133: * @throws InvalidMessageException
134: */
135: protected void constructMessage(ByteArrayReader bar)
136: throws InvalidMessageException {
137: try {
138: recipientChannel = bar.readInt();
139:
140: if (bar.available() > 0) {
141: channelData = bar.readBinaryString();
142: }
143: } catch (IOException ioe) {
144: throw new InvalidMessageException("Invalid message data");
145: }
146: }
147: }
|