// copyright (c) Hiroyuki Murata 1997. // free to use, distribute or modify. import java.io.*; public class Ue2Utf { static String usage = " Unicode-escape to UTF-8 Converter for JDK 1.0.2.\n" + " Usage:\n" + " 1) Replace all \'\\\'s in Japanese native file with \'\\\\\'s.\n" + " 2) Use J2Uc (or native2ascii) to generate \"inputfile\".\n" + " 3) java Ue2Utf inputfile outputfile\n" ; static final int MAXLEN = 1024; static char[] buf = new char[MAXLEN]; static public void main(String[] args) { if (args.length < 2) { System.out.print(usage); System.exit(0); } try { DataInputStream dis = new DataInputStream ( new BufferedInputStream( new FileInputStream(args[0]) ) ); DataOutputStream dos = new DataOutputStream ( new BufferedOutputStream( new FileOutputStream(args[1]) ) ); char[] unibuf = new char[4]; char c1, c2=0; int column = 0; try { for (;;) { c1 = c2; c2 = (char)dis.readUnsignedByte(); if (column >= MAXLEN) { System.err.println("too long line!"); System.exit(1); } if (c1=='\\' && c2=='u') { for (int i=0; i<4; i++) unibuf[i] = (char)dis.readUnsignedByte(); buf[column-1] = (char)Integer.parseInt( new String(unibuf), 16 ); } else if (c1=='\\' && c2=='\\') { c2 = 0; } else { buf[column++] = c2; } if (c2=='\n') { String line = new String(buf, 0, column); dos.writeUTF(line); //System.out.print(line); column = 0; } } } catch (EOFException e) { dos.close(); dis.close(); } } catch (FileNotFoundException e) { System.err.println("file " + args[0] + " not found."); } catch (IOException e) { e.printStackTrace(); } } }