| 1 |
/* |
| 2 |
* Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0, |
| 3 |
* and the EPL 1.0 (https://h2database.com/html/license.html). |
| 4 |
* Initial Developer: H2 Group |
| 5 |
*/ |
| 6 |
package org.h2.build.doc; |
| 7 |
|
| 8 |
import java.io.IOException; |
| 9 |
import java.io.InputStream; |
| 10 |
import java.io.OutputStream; |
| 11 |
import java.nio.charset.StandardCharsets; |
| 12 |
import java.util.Locale; |
| 13 |
|
| 14 |
import org.h2.build.indexer.HtmlConverter; |
| 15 |
import org.h2.store.fs.FileUtils; |
| 16 |
import org.h2.util.IOUtils; |
| 17 |
import org.h2.util.StringUtils; |
| 18 |
|
| 19 |
/** |
| 20 |
* Converts a HTML or Unicode encoded file to UTF-8. |
| 21 |
*/ |
| 22 |
public class FileConverter { |
| 23 |
|
| 24 |
private String inFile = "~/temp/in.txt"; |
| 25 |
private String outFile = "~/temp/out.txt"; |
| 26 |
|
| 27 |
/** |
| 28 |
* This method is called when executing this application from the command |
| 29 |
* line. |
| 30 |
* |
| 31 |
* @param args the command line parameters |
| 32 |
*/ |
| 33 |
public static void main(String... args) throws Exception { |
| 34 |
new FileConverter().run(args); |
| 35 |
} |
| 36 |
|
| 37 |
private void run(String... args) throws Exception { |
| 38 |
for (int i = 0; i < args.length; i++) { |
| 39 |
if (args[i].equals("-in")) { |
| 40 |
inFile = args[++i]; |
| 41 |
} else if (args[i].equals("-out")) { |
| 42 |
outFile = args[++i]; |
| 43 |
} |
| 44 |
} |
| 45 |
String languageCode = Locale.KOREA.getLanguage(); |
| 46 |
String language = new Locale(languageCode) |
| 47 |
.getDisplayLanguage(new Locale(languageCode)); |
| 48 |
System.out.println(language); |
| 49 |
System.out.println(StringUtils.javaEncode(language)); |
| 50 |
convert(); |
| 51 |
} |
| 52 |
|
| 53 |
private void convert() throws IOException { |
| 54 |
InputStream in = FileUtils.newInputStream(inFile); |
| 55 |
byte[] bytes = IOUtils.readBytesAndClose(in, -1); |
| 56 |
String s = new String(bytes, StandardCharsets.UTF_8); |
| 57 |
String s2 = HtmlConverter.convertHtmlToString(s); |
| 58 |
String s3 = StringUtils.javaDecode(s2); |
| 59 |
byte[] result = s3.getBytes(StandardCharsets.UTF_8); |
| 60 |
OutputStream out = FileUtils.newOutputStream(outFile, false); |
| 61 |
out.write(result); |
| 62 |
out.close(); |
| 63 |
} |
| 64 |
|
| 65 |
} |