import java.io.*; import java.util.*; /** * Convert between some standard eight bit character encodings. * This one is a version of Encoder.java that compiles with gcj. */ public class LilEncoder { static Map encoding = new HashMap(); /** * @param argv optional specificate of input and output encodings. * The default input is your machine's default encoding. * The default output is UTF-8 * Some common encodings are ASCII, UTF8, ISO8859_1, Cp1252 (Windows-1252), and MacRoman. * You can abbreviate these as ascii, utf, iso, win, and mac respectively. */ public static void main( String argv[] ) throws Exception { encoding.put( "ascii", "ASCII" ); encoding.put( "iso", "ISO8859_1" ); encoding.put( "iso8859", "ISO8859_1" ); encoding.put( "iso-8859-1", "ISO8859_1" ); encoding.put( "iso8859_1", "ISO8859_1" ); encoding.put( "iso_8859_1", "ISO8859_1" ); encoding.put( "latin-1", "ISO8859_1" ); encoding.put( "utf", "UTF8" ); encoding.put( "utf8", "UTF8" ); encoding.put( "utf-8", "UTF8" ); encoding.put( "win", "Cp1252" ); encoding.put( "windows-1252", "Cp1252" ); encoding.put( "mac", "MacRoman" ); encoding.put( "macosroman", "MacRoman" ); String codeIn = (new InputStreamReader(System.in)).getEncoding(); String codeOut = "UTF8"; if ( 0 < argv.length ) { if ( encoding.containsKey( argv[0] ) ) { codeIn = encoding.get( argv[0] ).toString().toLowerCase(); } else { codeIn = argv[0]; } } if ( 2 == argv.length ) { if ( encoding.containsKey( argv[1] ) ) { codeOut = encoding.get( argv[1] ).toString().toLowerCase(); } else { codeOut = argv[1]; } } Reader in = new InputStreamReader( System.in, codeIn ); Writer out = new OutputStreamWriter( System.out, codeOut ); int c = in.read(); while ( -1 != c ) { out.write( c ); c = in.read(); } out.close(); } }