package com.granveaud.mysql2h2converter.converter;

import com.granveaud.mysql2h2converter.parser.ParseException;
import com.granveaud.mysql2h2converter.parser.SQLParserManager;
import com.granveaud.mysql2h2converter.sql.Statement;

import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.Iterator;

public class Main {
    final static private Charset INPUT_CHARSET = Charset.forName("UTF-8");

    public static void main(String[] args) throws IOException, ParseException {
        if (args.length < 1) {
            System.err.println("Usage: input_file1 input_file2...");
            System.exit(1);
        }

        for (String str : args) {
            Iterator<Statement> sourceIterator = SQLParserManager.parseScript(new InputStreamReader(new FileInputStream(str), INPUT_CHARSET));

            // conversion and execution
            Iterator<Statement> it = H2Converter.convertScript(sourceIterator);
            while (it.hasNext()) {
                Statement st = it.next();

                // output to stdout
                System.out.println(st.toString() + ";");
            }
        }
    }
}

@@ -241,31 +241,17 @@
 java.io.
-FileInputStream
+*
 ;%0Aimport
@@ -260,19 +260,20 @@
 ava.
+n
 io.
-FileRead
+ByteBuff
 er;%0A
@@ -288,53 +288,18 @@
 ava.
-io.IOException;%0Aimport java.io.InputStreamRea
+nio.ByteOr
 der;
@@ -358,16 +358,54 @@
 terator;
+%0Aimport java.util.zip.GZIPInputStream;
 %0A%0Apublic
@@ -743,24 +743,133 @@
 r : args) %7B%0A
+            BufferedReader reader = new BufferedReader(new InputStreamReader(readFile(str), INPUT_CHARSET));%0A
             
@@ -938,70 +938,14 @@
 ipt(
-new InputStreamReader(new FileInputStream(str), INPUT_CHARSET)
+reader
 );%0A%0A
@@ -1245,24 +1245,24 @@
           %7D%0A
-
         %7D%0A  
@@ -1254,21 +1254,626 @@
  %7D%0A        %7D
+%0A%0A    %7D%0A%0A    public static InputStream readFile(String name) throws IOException %7B%0A        InputStream input = new BufferedInputStream(new FileInputStream(name));%0A        PushbackInputStream pb = new PushbackInputStream( input, 2 );%0A        byte %5B%5D magicbytes = new byte%5B2%5D;%0A        pb.read(magicbytes);%0A        pb.unread(magicbytes);%0A        ByteBuffer bb = ByteBuffer.wrap(magicbytes);%0A        bb.order(ByteOrder.LITTLE_ENDIAN);%0A        short magic = bb.getShort();%0A        if( magic == (short)GZIPInputStream.GZIP_MAGIC )%0A            return new GZIPInputStream( pb );%0A        else%0A            return pb;
 %0A    %7D%0A%7D%0A

Support reading input scripts that are gzipped