1 20 package org.apache.mina.filter.codec.textline; 21 22 import java.io.ByteArrayOutputStream ; 23 import java.io.PrintWriter ; 24 25 32 public class LineDelimiter { 33 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 51 public static final LineDelimiter AUTO = new LineDelimiter(""); 52 53 56 public static final LineDelimiter UNIX = new LineDelimiter("\n"); 57 58 61 public static final LineDelimiter WINDOWS = new LineDelimiter("\r\n"); 62 63 66 public static final LineDelimiter MAC = new LineDelimiter("\r"); 67 68 private final String value; 69 70 73 public LineDelimiter(String value) { 74 if (value == null) { 75 throw new NullPointerException ("delimiter"); 76 } 77 this.value = value; 78 } 79 80 83 public String getValue() { 84 return value; 85 } 86 87 public int hashCode() { 88 return value.hashCode(); 89 } 90 91 public boolean equals(Object o) { 92 if (!(o instanceof LineDelimiter)) { 93 return false; 94 } 95 96 LineDelimiter that = (LineDelimiter) o; 97 return this.value.equals(that.value); 98 } 99 100 public String toString() { 101 StringBuffer buf = new StringBuffer (); 102 buf.append("delimiter:"); 103 if (value.length() == 0) { 104 buf.append(" auto"); 105 } else { 106 for (int i = 0; i < value.length(); i++) { 107 buf.append(" 0x"); 108 buf.append(Integer.toHexString(value.charAt(i))); 109 } 110 } 111 return buf.toString(); 112 } 113 } 114 | Popular Tags |