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 public class LineDelimiter {
32
33
34
35 public static final LineDelimiter DEFAULT;
36
37 static {
38 ByteArrayOutputStream bout = new ByteArrayOutputStream();
39 PrintWriter out = new PrintWriter(bout);
40 out.println();
41 DEFAULT = new LineDelimiter(new String(bout.toByteArray()));
42 }
43
44
45
46
47
48
49
50 public static final LineDelimiter AUTO = new LineDelimiter("");
51
52
53
54
55 public static final LineDelimiter CRLF = new LineDelimiter("\r\n");
56
57
58
59
60 public static final LineDelimiter UNIX = new LineDelimiter("\n");
61
62
63
64
65 public static final LineDelimiter WINDOWS = CRLF;
66
67
68
69
70 public static final LineDelimiter MAC = new LineDelimiter("\r");
71
72
73
74
75
76 public static final LineDelimiter NUL = new LineDelimiter("\0");
77
78 private final String value;
79
80
81
82
83 public LineDelimiter(String value) {
84 if (value == null) {
85 throw new NullPointerException("delimiter");
86 }
87 this.value = value;
88 }
89
90
91
92
93 public String getValue() {
94 return value;
95 }
96
97 @Override
98 public int hashCode() {
99 return value.hashCode();
100 }
101
102 @Override
103 public boolean equals(Object o) {
104 if (!(o instanceof LineDelimiter)) {
105 return false;
106 }
107
108 LineDelimiter that = (LineDelimiter) o;
109 return this.value.equals(that.value);
110 }
111
112 @Override
113 public String toString() {
114 StringBuffer buf = new StringBuffer();
115 buf.append("delimiter:");
116 if (value.length() == 0) {
117 buf.append(" auto");
118 } else {
119 for (int i = 0; i < value.length(); i++) {
120 buf.append(" 0x");
121 buf.append(Integer.toHexString(value.charAt(i)));
122 }
123 }
124 return buf.toString();
125 }
126 }