Skip to content

Commit 04179be

Browse files
committed
新增:可用的CharSet打印
1 parent 8bb6632 commit 04179be

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package org.javacore.nio;
2+
3+
import java.nio.charset.Charset;
4+
import java.util.Iterator;
5+
import java.util.SortedMap;
6+
7+
/*
8+
* Copyright [2015] [Jeff Lee]
9+
*
10+
* Licensed under the Apache License, Version 2.0 (the "License");
11+
* you may not use this file except in compliance with the License.
12+
* You may obtain a copy of the License at
13+
*
14+
* http://www.apache.org/licenses/LICENSE-2.0
15+
*
16+
* Unless required by applicable law or agreed to in writing, software
17+
* distributed under the License is distributed on an "AS IS" BASIS,
18+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
* See the License for the specific language governing permissions and
20+
* limitations under the License.
21+
*/
22+
23+
/**
24+
* @author Jeff Lee
25+
* @since 2015-10-11 19:51:10
26+
* 可用的CharSet打印
27+
*/
28+
public class AvailableCharSets {
29+
public static void main(String[] args) {
30+
// charset对象的有序映射
31+
SortedMap<String,Charset> charSets =
32+
Charset.availableCharsets();
33+
// 获取key的迭代器
34+
Iterator<String> iterator = charSets.keySet().iterator();
35+
while (iterator.hasNext()) {
36+
String csName = iterator.next();
37+
System.out.print(csName);
38+
// 获取别名的Charset集合的迭代器
39+
Iterator aliases =
40+
charSets.get(csName).aliases().iterator();
41+
if (aliases.hasNext())
42+
System.out.print(": ");
43+
while (aliases.hasNext()) {
44+
System.out.print(aliases.next());
45+
if (aliases.hasNext())
46+
System.out.print(",");
47+
}
48+
System.out.println();
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)