FileDocCategorySizeDatePackage
Recoder.javaAPI DocExample1517Tue Feb 14 16:19:14 GMT 2006None

Recoder

public class Recoder extends Object

Fields Summary
Constructors Summary
Methods Summary
private static voidconvert(java.nio.charset.Charset inputEncoding, java.nio.charset.Charset outputEncoding, java.io.InputStream inStream, java.io.OutputStream outStream)

    
    ReadableByteChannel in = Channels.newChannel(inStream);
    WritableByteChannel out = Channels.newChannel(outStream);
 
    for (ByteBuffer inBuffer = ByteBuffer.allocate(4096);
         in.read(inBuffer) != -1;
         inBuffer.clear()) {
       
      inBuffer.flip();
      CharBuffer cBuffer = inputEncoding.decode(inBuffer);
      ByteBuffer outBuffer = outputEncoding.encode(cBuffer);
      while (outBuffer.hasRemaining()) out.write(outBuffer);
    }
  
public static voidmain(java.lang.String[] args)

    
    if (args.length != 2) {
       System.err.println(
         "Usage: java Recoder inputEncoding outputEncoding <inFile >outFile");
       return;
    }
    
    try {
      Charset inputEncoding = Charset.forName(args[0]);
      Charset outputEncoding = Charset.forName(args[1]);
      convert(inputEncoding, outputEncoding, System.in, System.out);
    }
    catch (UnsupportedCharsetException ex) {
      System.err.println(ex.getCharsetName() + " is not supported by this VM.");
    }
    catch (IllegalCharsetNameException  ex) {
      System.err.println(
        "Usage: java Recoder inputEncoding outputEncoding <inFile >outFile");
    }
    catch (IOException ex) {
      System.err.println(ex.getMessage());
    }