KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > schlichtherle > nio > charset > spi > CharsetProvider


1 /*
2  * CharsetProvider.java
3  *
4  * Created on 13. Dezember 2005, 16:39
5  */

6 /*
7  * Copyright 2005 Schlichtherle IT Services
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */

21
22 package de.schlichtherle.nio.charset.spi;
23
24 import de.schlichtherle.nio.charset.IBM437Charset;
25
26 import java.nio.charset.Charset JavaDoc;
27 import java.util.Arrays JavaDoc;
28 import java.util.Collection JavaDoc;
29 import java.util.Collections JavaDoc;
30 import java.util.HashMap JavaDoc;
31 import java.util.Iterator JavaDoc;
32 import java.util.Map JavaDoc;
33
34 /**
35  * A charset provider that only provides the <code>IBM437</code> character set,
36  * also known as <code>CP437</code>.
37  *
38  * @author Christian Schlichtherle
39  * @version @version@
40  */

41 public class CharsetProvider extends java.nio.charset.spi.CharsetProvider JavaDoc {
42     
43     private static final Map JavaDoc name2charset;
44     private static final Collection JavaDoc charsets;
45     
46     static {
47         charsets = Collections.unmodifiableCollection(
48                 Arrays.asList(new Charset[] { new IBM437Charset() }));
49         
50         name2charset = new HashMap JavaDoc();
51         for (Iterator JavaDoc i = charsets.iterator(); i.hasNext(); ) {
52             final Charset cs = (Charset) i.next();
53             name2charset.put(cs.name().toLowerCase(), cs);
54             for (Iterator JavaDoc j = cs.aliases().iterator(); j.hasNext(); )
55                 name2charset.put(((String JavaDoc) j.next()).toLowerCase(), cs);
56         }
57     }
58     
59     public Charset charsetForName(String JavaDoc charset) {
60         return (Charset) name2charset.get(charset.toLowerCase());
61     }
62     
63     public Iterator JavaDoc charsets() {
64         return charsets.iterator();
65     }
66 }
67
Popular Tags