Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
JUniversalChardetCharsetProvider |
|
| 2.0;2 |
1 | /* ***** BEGIN LICENSE BLOCK ***** | |
2 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | |
3 | * | |
4 | * The contents of this file are subject to the Mozilla Public License Version | |
5 | * 1.1 (the "License"); you may not use this file except in compliance with | |
6 | * the License. You may obtain a copy of the License at | |
7 | * http://www.mozilla.org/MPL/ | |
8 | * | |
9 | * Software distributed under the License is distributed on an "AS IS" basis, | |
10 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | |
11 | * for the specific language governing rights and limitations under the | |
12 | * License. | |
13 | * | |
14 | * The Original Code is mozilla.org code. | |
15 | * | |
16 | * The Initial Developer of the Original Code is | |
17 | * Netscape Communications Corporation. | |
18 | * Portions created by the Initial Developer are Copyright (C) 1998 | |
19 | * the Initial Developer. All Rights Reserved. | |
20 | * | |
21 | * Alternatively, the contents of this file may be used under the terms of | |
22 | * either of the GNU General Public License Version 2 or later (the "GPL"), | |
23 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), | |
24 | * in which case the provisions of the GPL or the LGPL are applicable instead | |
25 | * of those above. If you wish to allow use of your version of this file only | |
26 | * under the terms of either the GPL or the LGPL, and not to allow others to | |
27 | * use your version of this file under the terms of the MPL, indicate your | |
28 | * decision by deleting the provisions above and replace them with the notice | |
29 | * and other provisions required by the GPL or the LGPL. If you do not delete | |
30 | * the provisions above, a recipient may use your version of this file under | |
31 | * the terms of any one of the MPL, the GPL or the LGPL. | |
32 | * | |
33 | * ***** END LICENSE BLOCK ***** */ | |
34 | package net.sf.jmatchparser.util.charset.juniversalchardet; | |
35 | ||
36 | import java.nio.charset.Charset; | |
37 | import java.nio.charset.spi.CharsetProvider; | |
38 | import java.util.Arrays; | |
39 | import java.util.Iterator; | |
40 | ||
41 | /** | |
42 | * Charset provider that provides a convenience charset that uses <a | |
43 | * href="http://juniversalchardet.googlecode.com/">jUniversalChardet</a> to dynamically detect | |
44 | * the charset it uses for decoding. | |
45 | * | |
46 | * <p> | |
47 | * The name of this charset is "<tt>jUniversalChardet</tt>". | |
48 | * | |
49 | * <p> | |
50 | * This class is loaded automatically via SPI when it is in the class path. | |
51 | * | |
52 | * <h2>Character sets that can be detected</h2> | |
53 | * | |
54 | * <ul> | |
55 | * <li>UTF-8</li> | |
56 | * <li>Shift_JIS</li> | |
57 | * <li>EUC-JP</li> | |
58 | * <li>ISO-2022-JP</li> | |
59 | * <li>EUC-KR</li> | |
60 | * <li>ISO-2022-KR</li> | |
61 | * <li>Big5</li> | |
62 | * <li>x-euc-tw</li> | |
63 | * <li>GB2312</li> | |
64 | * <li>GB18030</li> | |
65 | * <li>ISO-2022-CN</li> | |
66 | * <li>HZ-GB-2312 <i>(not supported by Java by default)</i></li> | |
67 | * <li>ISO-8859-5</li> | |
68 | * <li>KOI8-R</li> | |
69 | * <li>windows-1251</li> | |
70 | * <li>MacCyrillic</li> | |
71 | * <li>IBM866</li> | |
72 | * <li>IBM855</li> | |
73 | * <li>ISO-8859-7</li> | |
74 | * <li>windows-1253</li> | |
75 | * <li>ISO-8859-8</li> | |
76 | * <li>windows-1255</li> | |
77 | * <li>windows-1252</li> | |
78 | * <li>UTF-16BE</li> | |
79 | * <li>UTF-16LE</li> | |
80 | * <li>UTF-32BE</li> | |
81 | * <li>UTF-32LE</li> | |
82 | * <li>X-ISO-10646-UCS-4-3412 <i>(not supported by Java by default)</i></li> | |
83 | * <li>X-ISO-10646-UCS-4-2143 <i>(not supported by Java by default)</i></li> | |
84 | * </ul> | |
85 | */ | |
86 | 67 | public class JUniversalChardetCharsetProvider extends CharsetProvider { |
87 | ||
88 | @Override | |
89 | public Charset charsetForName(String charsetName) { | |
90 | 67 | if (charsetName.equals(JUniversalChardetCharset.NAME)) |
91 | 66 | return JUniversalChardetCharset.getInstance(); |
92 | 1 | return null; |
93 | } | |
94 | ||
95 | @Override | |
96 | public Iterator<Charset> charsets() { | |
97 | 0 | return Arrays.asList(new Charset[] {JUniversalChardetCharset.getInstance()}).iterator(); |
98 | } | |
99 | } |