1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.codec.socksx.v5;
17
18 import static io.netty.util.internal.ObjectUtil.checkNonEmpty;
19
20 import io.netty.handler.codec.DecoderResult;
21 import io.netty.util.internal.ObjectUtil;
22 import io.netty.util.internal.StringUtil;
23
24 import java.util.ArrayList;
25 import java.util.Collections;
26 import java.util.List;
27
28
29
30
31 public class DefaultSocks5InitialRequest extends AbstractSocks5Message implements Socks5InitialRequest {
32
33 private final List<Socks5AuthMethod> authMethods;
34
35 public DefaultSocks5InitialRequest(Socks5AuthMethod... authMethods) {
36 ObjectUtil.checkNotNull(authMethods, "authMethods");
37
38 List<Socks5AuthMethod> list = new ArrayList<Socks5AuthMethod>(authMethods.length);
39 for (Socks5AuthMethod m: authMethods) {
40 if (m == null) {
41 break;
42 }
43 list.add(m);
44 }
45
46 this.authMethods = Collections.unmodifiableList(checkNonEmpty(list, "list"));
47 }
48
49 public DefaultSocks5InitialRequest(Iterable<Socks5AuthMethod> authMethods) {
50 ObjectUtil.checkNotNull(authMethods, "authSchemes");
51
52 List<Socks5AuthMethod> list = new ArrayList<Socks5AuthMethod>();
53 for (Socks5AuthMethod m: authMethods) {
54 if (m == null) {
55 break;
56 }
57 list.add(m);
58 }
59
60 this.authMethods = Collections.unmodifiableList(checkNonEmpty(list, "list"));
61 }
62
63 @Override
64 public List<Socks5AuthMethod> authMethods() {
65 return authMethods;
66 }
67
68 @Override
69 public String toString() {
70 StringBuilder buf = new StringBuilder(StringUtil.simpleClassName(this));
71
72 DecoderResult decoderResult = decoderResult();
73 if (!decoderResult.isSuccess()) {
74 buf.append("(decoderResult: ");
75 buf.append(decoderResult);
76 buf.append(", authMethods: ");
77 } else {
78 buf.append("(authMethods: ");
79 }
80 buf.append(authMethods());
81 buf.append(')');
82
83 return buf.toString();
84 }
85 }