KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > axis > components > encoding > UTF16Encoder


1 /*
2
3  * Copyright 2001-2004 The Apache Software Foundation.
4
5  *
6
7  * Licensed under the Apache License, Version 2.0 (the "License");
8
9  * you may not use this file except in compliance with the License.
10
11  * You may obtain a copy of the License at
12
13  *
14
15  * http://www.apache.org/licenses/LICENSE-2.0
16
17  *
18
19  * Unless required by applicable law or agreed to in writing, software
20
21  * distributed under the License is distributed on an "AS IS" BASIS,
22
23  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
25  * See the License for the specific language governing permissions and
26
27  * limitations under the License.
28
29  */

30
31 package org.jboss.axis.components.encoding;
32
33
34 /**
35  * UTF-16 Encoder.
36  *
37  * @author <a HREF="mailto:jens@void.fm">Jens Schumann</a>
38  * @see <a HREF="http://encoding.org">encoding.org</a>
39  * @see <a HREF="http://czyborra.com/utf/#UTF-16">UTF 16 explained</a>
40  */

41
42 class UTF16Encoder extends AbstractXMLEncoder
43 {
44
45    public String JavaDoc getEncoding()
46    {
47
48       return XMLEncoderFactory.ENCODING_UTF_16;
49
50    }
51
52
53    public boolean needsEncoding(char c)
54    {
55
56       return c > 0xFFFF;
57
58    }
59
60
61    public void appendEncoded(EncodedByteArray out, char c)
62    {
63
64       if (c > 0xFFFF)
65       {
66
67          out.append((0xD7C0 + (c >> 10)));
68
69          out.append((0xDC00 | c & 0x3FF));
70
71       }
72
73    }
74
75 }
76
77
Popular Tags