1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty5.handler.codec.string;
17
18 import io.netty5.buffer.BufferUtil;
19 import io.netty5.util.CharsetUtil;
20 import io.netty5.util.internal.StringUtil;
21
22 import static java.util.Objects.requireNonNull;
23
24
25
26
27 public final class LineSeparator {
28
29
30
31
32 public static final LineSeparator DEFAULT = new LineSeparator(StringUtil.NEWLINE);
33
34
35
36
37 public static final LineSeparator UNIX = new LineSeparator("\n");
38
39
40
41
42 public static final LineSeparator WINDOWS = new LineSeparator("\r\n");
43
44 private final String value;
45
46
47
48
49 public LineSeparator(String lineSeparator) {
50 this.value = requireNonNull(lineSeparator, "lineSeparator");
51 }
52
53
54
55
56 public String value() {
57 return value;
58 }
59
60 @Override
61 public boolean equals(Object o) {
62 if (this == o) {
63 return true;
64 }
65 if (!(o instanceof LineSeparator)) {
66 return false;
67 }
68 LineSeparator that = (LineSeparator) o;
69 return value != null ? value.equals(that.value) : that.value == null;
70 }
71
72 @Override
73 public int hashCode() {
74 return value != null ? value.hashCode() : 0;
75 }
76
77
78
79
80 @Override
81 public String toString() {
82 return BufferUtil.hexDump(value.getBytes(CharsetUtil.UTF_8));
83 }
84 }