1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.waarp.ftp.core.command;
21
22 import org.waarp.common.exception.InvalidArgumentException;
23
24 import java.nio.charset.Charset;
25
26
27
28
29 public class FtpArgumentCode {
30
31 private FtpArgumentCode() {
32 }
33
34
35
36
37
38
39 public enum TransferType {
40
41
42
43 ASCII('A', "ASCII"),
44
45
46
47 EBCDIC('E', "ebcdic-cp-us"),
48
49
50
51
52 IMAGE('I'),
53
54
55
56 LENGTH('L');
57
58
59
60 public final char type;
61
62
63
64
65 public final Charset charset;
66
67 TransferType(final char type) {
68 this.type = type;
69 charset = Charset.defaultCharset();
70 }
71
72 TransferType(final char type, final String charsetName) {
73 this.type = type;
74 charset = Charset.forName(charsetName);
75 }
76 }
77
78
79
80
81
82
83 public enum TransferSubType {
84
85
86
87 NONPRINT('N'),
88
89
90
91 TELNET('T'),
92
93
94
95 CARRIAGE('C');
96
97
98
99 public final char subtype;
100
101 TransferSubType(final char subtype) {
102 this.subtype = subtype;
103 }
104 }
105
106
107
108
109
110
111 public enum TransferStructure {
112
113
114
115 FILE('F'),
116
117
118
119 RECORD('R'),
120
121
122
123 PAGE('P');
124
125
126
127 public final char structure;
128
129 TransferStructure(final char structure) {
130 this.structure = structure;
131 }
132 }
133
134
135
136
137
138
139 public enum TransferMode {
140
141
142
143 STREAM('S'),
144
145
146
147 BLOCK('B'),
148
149
150
151 COMPRESSED('C'),
152
153
154
155 ZLIB('Z');
156
157
158
159
160 public final char mode;
161
162 TransferMode(final char mode) {
163 this.mode = mode;
164 }
165 }
166
167
168
169
170
171
172
173
174
175
176 public static TransferType getTransferType(final char type)
177 throws InvalidArgumentException {
178 switch (type) {
179 case 'A':
180 case 'a':
181 return TransferType.ASCII;
182 case 'E':
183 case 'e':
184 return TransferType.EBCDIC;
185 case 'I':
186 case 'i':
187 return TransferType.IMAGE;
188 case 'L':
189 case 'l':
190 return TransferType.LENGTH;
191 default:
192 throw new InvalidArgumentException(
193 "Argument for TransferType is not allowed: " + type);
194 }
195 }
196
197
198
199
200
201
202
203
204
205
206
207 public static TransferSubType getTransferSubType(final char subType)
208 throws InvalidArgumentException {
209 switch (subType) {
210 case 'C':
211 case 'c':
212 return TransferSubType.CARRIAGE;
213 case 'N':
214 case 'n':
215 return TransferSubType.NONPRINT;
216 case 'T':
217 case 't':
218 return TransferSubType.TELNET;
219 default:
220 throw new InvalidArgumentException(
221 "Argument for TransferSubType is not allowed: " + subType);
222 }
223 }
224
225
226
227
228
229
230
231
232
233
234
235 public static TransferStructure getTransferStructure(final char structure)
236 throws InvalidArgumentException {
237 switch (structure) {
238 case 'P':
239 case 'p':
240 return TransferStructure.PAGE;
241 case 'F':
242 case 'f':
243 return TransferStructure.FILE;
244 case 'R':
245 case 'r':
246 return TransferStructure.RECORD;
247 default:
248 throw new InvalidArgumentException(
249 "Argument for TransferStructure is not allowed: " + structure);
250 }
251 }
252
253
254
255
256
257
258
259
260
261
262 public static TransferMode getTransferMode(final char mode)
263 throws InvalidArgumentException {
264 switch (mode) {
265 case 'B':
266 case 'b':
267 return TransferMode.BLOCK;
268 case 'C':
269 case 'c':
270 return TransferMode.COMPRESSED;
271 case 'Z':
272 case 'z':
273 return TransferMode.ZLIB;
274 case 'S':
275 case 's':
276 return TransferMode.STREAM;
277 default:
278 throw new InvalidArgumentException(
279 "Argument for TransferMode is not allowed: " + mode);
280 }
281 }
282 }