1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.mina.filter.codec.textline;
21
22 import java.io.ByteArrayOutputStream;
23 import java.io.PrintWriter;
24
25
26
27
28
29
30
31
32 public class LineDelimiter {
33
34
35
36 public static final LineDelimiter DEFAULT;
37
38 static {
39 ByteArrayOutputStream bout = new ByteArrayOutputStream();
40 PrintWriter out = new PrintWriter(bout);
41 out.println();
42 DEFAULT = new LineDelimiter(new String(bout.toByteArray()));
43 }
44
45
46
47
48
49
50
51 public static final LineDelimiter AUTO = new LineDelimiter("");
52
53
54
55
56 public static final LineDelimiter UNIX = new LineDelimiter("\n");
57
58
59
60
61 public static final LineDelimiter WINDOWS = new LineDelimiter("\r\n");
62
63
64
65
66 public static final LineDelimiter MAC = new LineDelimiter("\r");
67
68
69
70
71
72 public static final LineDelimiter NUL = new LineDelimiter("\0");
73
74 private final String value;
75
76
77
78
79 public LineDelimiter(String value) {
80 if (value == null) {
81 throw new NullPointerException("delimiter");
82 }
83 this.value = value;
84 }
85
86
87
88
89 public String getValue() {
90 return value;
91 }
92
93 @Override
94 public int hashCode() {
95 return value.hashCode();
96 }
97
98 @Override
99 public boolean equals(Object o) {
100 if (!(o instanceof LineDelimiter)) {
101 return false;
102 }
103
104 LineDelimiter that = (LineDelimiter) o;
105 return this.value.equals(that.value);
106 }
107
108 @Override
109 public String toString() {
110 StringBuffer buf = new StringBuffer();
111 buf.append("delimiter:");
112 if (value.length() == 0) {
113 buf.append(" auto");
114 } else {
115 for (int i = 0; i < value.length(); i++) {
116 buf.append(" 0x");
117 buf.append(Integer.toHexString(value.charAt(i)));
118 }
119 }
120 return buf.toString();
121 }
122 }