comparison app/src/main/java/ch/ethz/ssh2/packets/PacketChannelOpenConfirmation.java @ 438:d29cce60f393

migrate from Eclipse to Android Studio
author Carl Byington <carl@five-ten-sg.com>
date Thu, 03 Dec 2015 11:23:55 -0800
parents src/ch/ethz/ssh2/packets/PacketChannelOpenConfirmation.java@071eccdff8ea
children
comparison
equal deleted inserted replaced
437:208b31032318 438:d29cce60f393
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 import ch.ethz.ssh2.PacketFormatException;
10 import ch.ethz.ssh2.PacketTypeException;
11
12 /**
13 * @author Christian Plattner
14 * @version $Id: PacketChannelOpenConfirmation.java 160 2014-05-01 14:30:26Z dkocher@sudo.ch $
15 */
16 public final class PacketChannelOpenConfirmation {
17
18 private final byte[] payload;
19
20 private final int recipientChannelID;
21 private final int senderChannelID;
22 private final int initialWindowSize;
23 private final int maxPacketSize;
24
25 public PacketChannelOpenConfirmation(int recipientChannelID, int senderChannelID, int initialWindowSize,
26 int maxPacketSize) {
27 this.recipientChannelID = recipientChannelID;
28 this.senderChannelID = senderChannelID;
29 this.initialWindowSize = initialWindowSize;
30 this.maxPacketSize = maxPacketSize;
31 TypesWriter tw = new TypesWriter();
32 tw.writeByte(Packets.SSH_MSG_CHANNEL_OPEN_CONFIRMATION);
33 tw.writeUINT32(recipientChannelID);
34 tw.writeUINT32(senderChannelID);
35 tw.writeUINT32(initialWindowSize);
36 tw.writeUINT32(maxPacketSize);
37 payload = tw.getBytes();
38 }
39
40 public PacketChannelOpenConfirmation(byte payload[]) throws IOException {
41 this.payload = payload;
42 TypesReader tr = new TypesReader(payload);
43 int packet_type = tr.readByte();
44
45 if (packet_type != Packets.SSH_MSG_CHANNEL_OPEN_CONFIRMATION) {
46 throw new PacketTypeException(packet_type);
47 }
48
49 recipientChannelID = tr.readUINT32();
50 senderChannelID = tr.readUINT32();
51 initialWindowSize = tr.readUINT32();
52 maxPacketSize = tr.readUINT32();
53
54 if (tr.remain() != 0) {
55 throw new PacketFormatException(String.format("Padding in %s", Packets.getMessageName(packet_type)));
56 }
57 }
58
59 public int getRecipientChannelID() {
60 return recipientChannelID;
61 }
62
63 public int getSenderChannelID() {
64 return senderChannelID;
65 }
66
67 public int getInitialWindowSize() {
68 return initialWindowSize;
69 }
70
71 public int getMaxPacketSize() {
72 return maxPacketSize;
73 }
74
75 public byte[] getPayload() {
76 return payload;
77 }
78 }