/* * DisposeUtf.java * * Copyright (C) 2003 Miika Nurminen * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; import java.io.PrintStream; import java.io.IOException; /** * Corrects XML declaration from UTF-8 to ISO-8859-1. * File (or its actual encoding) is left untouched. * Operates on standard input / output. * * Alternate way: use GNU IMAP utility to convert file's actual encoding to * UTF-8 (as stated in the declaration): * iconv -f ISO-8859-1 -t UTF-8 * * @author Miika Nurminen * @version 0.1 - 2003-09-04 */ public class DisposeUtf { /** Creates a new instance of StdinTest */ public DisposeUtf() { } public void performTrasform(InputStream in, PrintStream out) throws java.io.IOException { BufferedReader b = new BufferedReader(new InputStreamReader(in)); String s = b.readLine(); String t=""; if (s==null) throw new java.io.IOException("No input!"); if ((s.equalsIgnoreCase("")) || (s.equalsIgnoreCase(t))) { s=t; } else throw new java.io.IOException("Cannot parse input! try java DisposeUtf -h for help."); while(s!=null) { out.println(s); s=b.readLine(); } } /** * @param args the command line arguments */ public static void main(String[] args) { FileArgumentScheme m = new FileArgumentScheme(args); try { if (m.helpWanted()) { System.out.println("\nCorrects XML declaration from UTF-8 to ISO-8859-1."); System.out.println("File (or its actual encoding) is left untouched."); System.out.println("Operates on standard input / output or given filenames.\n"); System.out.println("Usage examples:"); System.out.println(" cat input.xml | java DisposeUtf > output.xml"); System.out.println(" java DisposeUtf -i input.xml -o output.xml\n"); return; } m.openStreams(); DisposeUtf u = new DisposeUtf(); u.performTrasform(m.getInput(),m.getOutput()); } catch (IOException e) { ErrorLib.errorReport(e); } try { m.getInput().close(); m.getOutput().close(); } catch (IOException e) { ErrorLib.errorReport(e); } } }