comparison app/src/main/java/ch/ethz/ssh2/packets/PacketChannelOpenFailure.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/PacketChannelOpenFailure.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
11 /**
12 * @author Christian Plattner
13 * @version $Id: PacketChannelOpenFailure.java 160 2014-05-01 14:30:26Z dkocher@sudo.ch $
14 */
15 public final class PacketChannelOpenFailure {
16
17 private final byte[] payload;
18
19 public PacketChannelOpenFailure(int recipientChannelID, int reasonCode, String description,
20 String languageTag) {
21 TypesWriter tw = new TypesWriter();
22 tw.writeByte(Packets.SSH_MSG_CHANNEL_OPEN_FAILURE);
23 tw.writeUINT32(recipientChannelID);
24 tw.writeUINT32(reasonCode);
25 tw.writeString(description);
26 tw.writeString(languageTag);
27 payload = tw.getBytes();
28 }
29
30 public PacketChannelOpenFailure(byte payload[]) throws IOException {
31 this.payload = payload;
32 TypesReader tr = new TypesReader(payload);
33 int packet_type = tr.readByte();
34
35 if (packet_type != Packets.SSH_MSG_CHANNEL_OPEN_FAILURE) {
36 throw new IOException(
37 "This is not a SSH_MSG_CHANNEL_OPEN_FAILURE! ("
38 + packet_type + ")"
39 );
40 }
41
42 int recipientChannelID = tr.readUINT32();
43 int reasonCode = tr.readUINT32();
44 String description = tr.readString();
45 String languageTag = tr.readString();
46
47 if (tr.remain() != 0) {
48 throw new PacketFormatException(String.format("Padding in %s", Packets.getMessageName(packet_type)));
49 }
50 }
51
52 public byte[] getPayload() {
53 return payload;
54 }
55 }