-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAvailableCharsets.java
More file actions
63 lines (48 loc) · 1.57 KB
/
AvailableCharsets.java
File metadata and controls
63 lines (48 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package io;
import java.nio.*;
import java.nio.channels.*;
import java.nio.charset.*;
import java.io.*;
import java.util.*;
/**
* RUN:
* javac io/AvailableCharsets.java && java io.AvailableCharsets
*
* OUTPUT:
*
*/
public class AvailableCharsets {
public static void main(String[] args) throws Exception {
FileChannel fc = new FileOutputStream("AvailableCharsets.txt").getChannel();
ByteBuffer buffer = ByteBuffer.allocate(450);
SortedMap<String, Charset> charSets = Charset.availableCharsets();
Iterator<String> it = charSets.keySet().iterator();
while (it.hasNext())
{
String csName = it.next();
System.out.print(csName);
StringBuilder sb = new StringBuilder();
sb.append(csName);
Iterator aliases = charSets.get(csName).aliases().iterator();
if (aliases.hasNext()) {
System.out.print(": ");
sb.append(": ");
}
while (aliases.hasNext()) {
Object obj = aliases.next();
System.out.print(obj);
sb.append((String)obj);
if (aliases.hasNext()) {
System.out.print(", ");
sb.append(", ");
}
}
System.out.println();
sb.append("\n");
buffer.asCharBuffer().put(sb.toString());
fc.write(buffer);
buffer.clear();
}
fc.close();
}
}