Usage Instructions

Converting Files

NekoConv simplifies the task of converting text files from one character encoding to another by leveraging the existing character decoders/encoders available in Java (1.1 or higher). This package includes:

Command Line Tool

The Convert program, found in the org.cyberneko.i18n.util package can be used to convert a file from one input encoding to another using the command line. For example, running the program with no arguments lists the usage instructions:

> java -cp nekoconv.jar org.cyberneko.i18n.util.Convert
usage: java org.cyberneko.i18n.util.Convert options

options:
  -i  | --input      Input file.
  -o  | --output     Output file.
  -ie | --inputenc   Input encoding.
  -oe | --outputenc  Output encoding.

  -h  | --help       Help.

input encodings:
  {see Available Conversions for list}

output encodings:
  {see Available Conversions for list}

When running the command line tool, all of the options (except for help) are required. In other words, you must specify the input file using -i, the encoding of the input file using -ie, the output file using -o, and the encoding of the output file using -oe. For example: (Note: The command line should be specified on a single line. It is listed on two lines below to improve readability.)

> java -cp nekoconv.jar org.cyberneko.i18n.util.Convert
       -i data/in/japanese.txt -ie UTF16 -o japanese_sjis -oe SJIS

In order to automate the process of converting multiple files at the same time, refer to the documentation of the Ant build task.

Graphical Frontend

A graphical frontent to the command line tool is also provided with NekoConv. At the time of this writing, the graphical frontend works fine but could be better. When I have more time, I'll improve it. Regardless, you can use this tool to convert files in a simple GUI fashion.

The graphical frontend is defined as the main class in the NekoConv Jar file. Therefore, typing the following command will launch the GUI application:

> java -jar nekoconv.jar

Alternatively, you can launch the graphical frontend by specifying the fully qualified Java class. For example:

> java -cp nekoconv.jar org.cyberneko.i18n.ui.Convert

Without command line parameters, the graphical frontend is displayed. With command line parameters, the GUI will not be displayed and works exactly like the command line version of the tool.

Ant Build Task

Perhaps the most useful tool supplied with NekoConv is the Ant build task. Coupled with Ant, NekoConv provides a convenient way to convert collections of files. In order to use NekoConv in your Ant build scripts, you must first define a new Ant task at the beginning of your script as shown:

<project default='all'>
 <taskdef name='nekoconv' classname='org.cyberneko.i18n.ant.Convert'/>
 ...
</project>

Once the NekoConv task has been defined, you can use the <nekoconv> element within your project targets just as you would with the built-in Ant tasks. For example:

 <target name='all'>
  <nekoconv todir='out' inputEncoding='UTF16' outputEncoding='SJIS'>
   <fileset dir='in' includes='**/*' excludes='**/exclude.*'/>
  </nekoconv>
 </target>

When executed, NekoConv will compare the timestamps of the original file with the transcoded file. If the output file does not exist or if the input file is newer than the output, then NekoConv will perform the conversion. This way, only new or modified files are converted each time the task is executed.

The NekoConv Ant task supports the following attributes:

todir
Specifies the output directory. This attribute is required unless the overwrite attribute is specified.
inputEncoding
The input encoding of the files to be read. This attribute is required.
outputEncoding
The output encoding of the files to write. This attribute is required.
overwrite
Specifies whether existing files should be overwritten. (Default is false.)
quiet
Specifies whether output is produced. (Default is true.)

The NekoConv Ant task supports the following child elements:

fileset
Specifies an Ant fileset. Multiple <fileset> tags can be used within a NekoConv task.
For information about how to use this element, refer to the Ant documentation.