Skip to content

Instantly share code, notes, and snippets.

@aNNiMON
Created January 6, 2014 14:34
Show Gist options
  • Save aNNiMON/8283596 to your computer and use it in GitHub Desktop.
Save aNNiMON/8283596 to your computer and use it in GitHub Desktop.
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.Charset;
/**
* Create codepage files for supported encodings.
* @author aNNiMON
*/
public class CodepageCreator {
private static final String FOLDER_NAME = "codepages";
public static void main(String[] args) {
new CodepageCreator().process();
}
private Charset charset;
public void process() {
createCodepageFolder();
for (String encodingName : Charset.availableCharsets().keySet()) {
charset = Charset.forName(encodingName);
saveCodepage(encodingName);
}
}
private void createCodepageFolder() {
File dir = new File(FOLDER_NAME);
dir.mkdir();
}
private void saveCodepage(String name) {
try {
String path = FOLDER_NAME + File.separator + name + ".cp";
File out = new File(path);
out.createNewFile();
FileOutputStream fos = new FileOutputStream(out);
DataOutputStream dos = new DataOutputStream(fos);
writeChars(dos, 0x80, 0xff);
dos.flush();
dos.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
private void writeChars(DataOutputStream dos, int from, int to) throws IOException {
for (int index = from; index <= to; index++) {
String charStr = new String(new byte[] {(byte) index}, charset);
dos.writeChar(charStr.charAt(0));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment