comparison src/ch/ethz/ssh2/packets/TypesWriter.java @ 307:071eccdff8ea ganymed

fix java formatting
author Carl Byington <carl@five-ten-sg.com>
date Wed, 30 Jul 2014 14:16:58 -0700
parents 91a31873c42a
children
comparison
equal deleted inserted replaced
305:d2b303406d63 307:071eccdff8ea
41 public void getBytes(byte dst[]) { 41 public void getBytes(byte dst[]) {
42 System.arraycopy(arr, 0, dst, 0, pos); 42 System.arraycopy(arr, 0, dst, 0, pos);
43 } 43 }
44 44
45 public void writeUINT32(int val, int off) { 45 public void writeUINT32(int val, int off) {
46 if((off + 4) > arr.length) { 46 if ((off + 4) > arr.length) {
47 resize(off + 32); 47 resize(off + 32);
48 } 48 }
49 49
50 arr[off++] = (byte) (val >> 24); 50 arr[off++] = (byte)(val >> 24);
51 arr[off++] = (byte) (val >> 16); 51 arr[off++] = (byte)(val >> 16);
52 arr[off++] = (byte) (val >> 8); 52 arr[off++] = (byte)(val >> 8);
53 arr[off++] = (byte) val; 53 arr[off++] = (byte) val;
54 } 54 }
55 55
56 public void writeUINT32(int val) { 56 public void writeUINT32(int val) {
57 writeUINT32(val, pos); 57 writeUINT32(val, pos);
58 pos += 4; 58 pos += 4;
59 } 59 }
60 60
61 public void writeUINT64(long val) { 61 public void writeUINT64(long val) {
62 if((pos + 8) > arr.length) { 62 if ((pos + 8) > arr.length) {
63 resize(arr.length + 32); 63 resize(arr.length + 32);
64 } 64 }
65 65
66 arr[pos++] = (byte) (val >> 56); 66 arr[pos++] = (byte)(val >> 56);
67 arr[pos++] = (byte) (val >> 48); 67 arr[pos++] = (byte)(val >> 48);
68 arr[pos++] = (byte) (val >> 40); 68 arr[pos++] = (byte)(val >> 40);
69 arr[pos++] = (byte) (val >> 32); 69 arr[pos++] = (byte)(val >> 32);
70 arr[pos++] = (byte) (val >> 24); 70 arr[pos++] = (byte)(val >> 24);
71 arr[pos++] = (byte) (val >> 16); 71 arr[pos++] = (byte)(val >> 16);
72 arr[pos++] = (byte) (val >> 8); 72 arr[pos++] = (byte)(val >> 8);
73 arr[pos++] = (byte) val; 73 arr[pos++] = (byte) val;
74 } 74 }
75 75
76 public void writeBoolean(boolean v) { 76 public void writeBoolean(boolean v) {
77 if((pos + 1) > arr.length) { 77 if ((pos + 1) > arr.length) {
78 resize(arr.length + 32); 78 resize(arr.length + 32);
79 } 79 }
80 80
81 arr[pos++] = v ? (byte) 1 : (byte) 0; 81 arr[pos++] = v ? (byte) 1 : (byte) 0;
82 } 82 }
83 83
84 public void writeByte(int v, int off) { 84 public void writeByte(int v, int off) {
85 if((off + 1) > arr.length) { 85 if ((off + 1) > arr.length) {
86 resize(off + 32); 86 resize(off + 32);
87 } 87 }
88 88
89 arr[off] = (byte) v; 89 arr[off] = (byte) v;
90 } 90 }
95 } 95 }
96 96
97 public void writeMPInt(BigInteger b) { 97 public void writeMPInt(BigInteger b) {
98 byte raw[] = b.toByteArray(); 98 byte raw[] = b.toByteArray();
99 99
100 if((raw.length == 1) && (raw[0] == 0)) { 100 if ((raw.length == 1) && (raw[0] == 0)) {
101 writeUINT32(0); /* String with zero bytes of data */ 101 writeUINT32(0); /* String with zero bytes of data */
102 } 102 }
103 else { 103 else {
104 writeString(raw, 0, raw.length); 104 writeString(raw, 0, raw.length);
105 } 105 }
108 public void writeBytes(byte[] buff) { 108 public void writeBytes(byte[] buff) {
109 writeBytes(buff, 0, buff.length); 109 writeBytes(buff, 0, buff.length);
110 } 110 }
111 111
112 public void writeBytes(byte[] buff, int off, int len) { 112 public void writeBytes(byte[] buff, int off, int len) {
113 if((pos + len) > arr.length) { 113 if ((pos + len) > arr.length) {
114 resize(arr.length + len + 32); 114 resize(arr.length + len + 32);
115 } 115 }
116 116
117 System.arraycopy(buff, off, arr, pos, len); 117 System.arraycopy(buff, off, arr, pos, len);
118 pos += len; 118 pos += len;
123 writeBytes(buff, off, len); 123 writeBytes(buff, off, len);
124 } 124 }
125 125
126 public void writeString(String v) { 126 public void writeString(String v) {
127 byte[] b = StringEncoder.GetBytes(v); 127 byte[] b = StringEncoder.GetBytes(v);
128
129 writeUINT32(b.length); 128 writeUINT32(b.length);
130 writeBytes(b, 0, b.length); 129 writeBytes(b, 0, b.length);
131 } 130 }
132 131
133 public void writeString(String v, String charsetName) throws UnsupportedEncodingException { 132 public void writeString(String v, String charsetName) throws UnsupportedEncodingException {
134 byte[] b = (charsetName == null) ? StringEncoder.GetBytes(v) : v.getBytes(charsetName); 133 byte[] b = (charsetName == null) ? StringEncoder.GetBytes(v) : v.getBytes(charsetName);
135
136 writeUINT32(b.length); 134 writeUINT32(b.length);
137 writeBytes(b, 0, b.length); 135 writeBytes(b, 0, b.length);
138 } 136 }
139 137
140 public void writeNameList(String v[]) { 138 public void writeNameList(String v[]) {
141 StringBuilder sb = new StringBuilder(); 139 StringBuilder sb = new StringBuilder();
142 for(int i = 0; i < v.length; i++) { 140
143 if(i > 0) { 141 for (int i = 0; i < v.length; i++) {
142 if (i > 0) {
144 sb.append(','); 143 sb.append(',');
145 } 144 }
145
146 sb.append(v[i]); 146 sb.append(v[i]);
147 } 147 }
148
148 writeString(sb.toString()); 149 writeString(sb.toString());
149 } 150 }
150 } 151 }