Home | History | Annotate | Download | only in packets
      1 /*
      2  * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
      3  * Please refer to the LICENSE.txt for licensing details.
      4  */
      5 package ch.ethz.ssh2.packets;
      6 
      7 import java.io.IOException;
      8 
      9 /**
     10  * PacketChannelWindowAdjust.
     11  *
     12  * @author Christian Plattner
     13  * @version 2.50, 03/15/10
     14  */
     15 public class PacketChannelWindowAdjust
     16 {
     17 	byte[] payload;
     18 
     19 	public int recipientChannelID;
     20 	public int windowChange;
     21 
     22 	public PacketChannelWindowAdjust(int recipientChannelID, int windowChange)
     23 	{
     24 		this.recipientChannelID = recipientChannelID;
     25 		this.windowChange = windowChange;
     26 	}
     27 
     28 	public PacketChannelWindowAdjust(byte payload[], int off, int len) throws IOException
     29 	{
     30 		this.payload = new byte[len];
     31 		System.arraycopy(payload, off, this.payload, 0, len);
     32 
     33 		TypesReader tr = new TypesReader(payload, off, len);
     34 
     35 		int packet_type = tr.readByte();
     36 
     37 		if (packet_type != Packets.SSH_MSG_CHANNEL_WINDOW_ADJUST)
     38 			throw new IOException(
     39 					"This is not a SSH_MSG_CHANNEL_WINDOW_ADJUST! ("
     40 							+ packet_type + ")");
     41 
     42 		recipientChannelID = tr.readUINT32();
     43 		windowChange = tr.readUINT32();
     44 
     45 		if (tr.remain() != 0)
     46 			throw new IOException("Padding in SSH_MSG_CHANNEL_WINDOW_ADJUST packet!");
     47 	}
     48 
     49 	public byte[] getPayload()
     50 	{
     51 		if (payload == null)
     52 		{
     53 			TypesWriter tw = new TypesWriter();
     54 			tw.writeByte(Packets.SSH_MSG_CHANNEL_WINDOW_ADJUST);
     55 			tw.writeUINT32(recipientChannelID);
     56 			tw.writeUINT32(windowChange);
     57 			payload = tw.getBytes();
     58 		}
     59 		return payload;
     60 	}
     61 }
     62