Clover Coverage Report - Commons Codec
Coverage timestamp: Fri May 9 2008 10:49:04 EST
../../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
90   310   36   6.43
40   160   0.4   14
14     2.57  
1    
 
  QCodec       Line # 47 90 36 100% 1.0
 
  (24)
 
1    /*
2    * Copyright 2001-2006 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10    * Unless required by applicable law or agreed to in writing, software
11    * distributed under the License is distributed on an "AS IS" BASIS,
12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    * See the License for the specific language governing permissions and
14    * limitations under the License.
15    */
16   
17    package org.apache.commons.codec.net;
18   
19    import java.io.UnsupportedEncodingException;
20    import java.util.BitSet;
21   
22    import org.apache.commons.codec.DecoderException;
23    import org.apache.commons.codec.EncoderException;
24    import org.apache.commons.codec.StringDecoder;
25    import org.apache.commons.codec.StringEncoder;
26   
27    /**
28    * <p>
29    * Similar to the Quoted-Printable content-transfer-encoding defined in <a
30    * href="http://www.ietf.org/rfc/rfc1521.txt">RFC 1521</a> and designed to allow text containing mostly ASCII
31    * characters to be decipherable on an ASCII terminal without decoding.
32    * </p>
33    *
34    * <p>
35    * <a href="http://www.ietf.org/rfc/rfc1522.txt">RFC 1522</a> describes techniques to allow the encoding of non-ASCII
36    * text in various portions of a RFC 822 [2] message header, in a manner which is unlikely to confuse existing message
37    * handling software.
38    * </p>
39    *
40    * @see <a href="http://www.ietf.org/rfc/rfc1522.txt">MIME (Multipurpose Internet Mail Extensions) Part Two: Message
41    * Header Extensions for Non-ASCII Text</a>
42    *
43    * @author Apache Software Foundation
44    * @since 1.3
45    * @version $Id: QCodec.java 437232 2006-08-26 21:27:08Z ggregory $
46    */
 
47    public class QCodec extends RFC1522Codec implements StringEncoder, StringDecoder {
48    /**
49    * The default charset used for string decoding and encoding.
50    */
51    private String charset = CharacterEncodingNames.UTF8;
52   
53    /**
54    * BitSet of printable characters as defined in RFC 1522.
55    */
56    private static final BitSet PRINTABLE_CHARS = new BitSet(256);
57    // Static initializer for printable chars collection
 
58  2 toggle static {
59    // alpha characters
60  2 PRINTABLE_CHARS.set(' ');
61  2 PRINTABLE_CHARS.set('!');
62  2 PRINTABLE_CHARS.set('"');
63  2 PRINTABLE_CHARS.set('#');
64  2 PRINTABLE_CHARS.set('$');
65  2 PRINTABLE_CHARS.set('%');
66  2 PRINTABLE_CHARS.set('&');
67  2 PRINTABLE_CHARS.set('\'');
68  2 PRINTABLE_CHARS.set('(');
69  2 PRINTABLE_CHARS.set(')');
70  2 PRINTABLE_CHARS.set('*');
71  2 PRINTABLE_CHARS.set('+');
72  2 PRINTABLE_CHARS.set(',');
73  2 PRINTABLE_CHARS.set('-');
74  2 PRINTABLE_CHARS.set('.');
75  2 PRINTABLE_CHARS.set('/');
76  22 for (int i = '0'; i <= '9'; i++) {
77  20 PRINTABLE_CHARS.set(i);
78    }
79  2 PRINTABLE_CHARS.set(':');
80  2 PRINTABLE_CHARS.set(';');
81  2 PRINTABLE_CHARS.set('<');
82  2 PRINTABLE_CHARS.set('>');
83  2 PRINTABLE_CHARS.set('@');
84  54 for (int i = 'A'; i <= 'Z'; i++) {
85  52 PRINTABLE_CHARS.set(i);
86    }
87  2 PRINTABLE_CHARS.set('[');
88  2 PRINTABLE_CHARS.set('\\');
89  2 PRINTABLE_CHARS.set(']');
90  2 PRINTABLE_CHARS.set('^');
91  2 PRINTABLE_CHARS.set('`');
92  54 for (int i = 'a'; i <= 'z'; i++) {
93  52 PRINTABLE_CHARS.set(i);
94    }
95  2 PRINTABLE_CHARS.set('{');
96  2 PRINTABLE_CHARS.set('|');
97  2 PRINTABLE_CHARS.set('}');
98  2 PRINTABLE_CHARS.set('~');
99    }
100   
101    private static byte BLANK = 32;
102   
103    private static byte UNDERSCORE = 95;
104   
105    private boolean encodeBlanks = false;
106   
107    /**
108    * Default constructor.
109    */
 
110  20 toggle public QCodec() {
111  20 super();
112    }
113   
114