// Path: halvade_upload_tool/src/be/ugent/intec/halvade/uploader/Logger.java
// public class Logger {
//     /*
//      * levels of debugging
//      * 0: INFO
//      * 1: DEBUG
//      * 2: EXCEPTION
//      * 3:ALL
//      */
//     private static int LEVEL = 0;
//     private static final int EXCEPTION = 2;
//     private static final int DEBUG = 1;
//     private static final int INFO = 0;
//     
//     
//     // TODO use configuration set LEVEL
//     public static void SETLEVEL(int NEWLEVEL) {
//         LEVEL = NEWLEVEL;
//     }
//     
//     public static void EXCEPTION(Exception ex){
//         System.err.println("[EXCEPTION] " + ex.getLocalizedMessage());
//         ex.printStackTrace();
//     }
//     
//     public static void THROWABLE(Throwable ex){
//         System.err.println("[EXCEPTION] " + ex.getLocalizedMessage());
//         ex.printStackTrace();
//     }
//     
//     public static void DEBUG(String message) {
//         if(LEVEL >= DEBUG)
//             System.err.println("[" + Timer.getGlobalTime() + " - DEBUG] " + message);
//     }
//     
//     public static void INFO(String message) {
//         if(LEVEL >= INFO)
//             System.err.println("[INFO] " + message);
//     }
//     
//     public static void DEBUG(String message, int level) {
//         if(LEVEL >= level)
//             System.err.println("[" + Timer.getGlobalTime() + " - DEBUG] " + message);
//     }
// }


import be.ugent.intec.halvade.uploader.Logger;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.zip.GZIPInputStream;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.tools.bzip2.CBZip2InputStream;
                return new BufferedReader(new InputStreamReader(hdfsIn));
            
        } else {
            if(file.endsWith(".gz")) {
                GZIPInputStream gzip = new GZIPInputStream(new FileInputStream(file), BUFFERSIZE); 
                return new BufferedReader(new InputStreamReader(gzip));
            } else if(file.endsWith(".bz2")) {
                CBZip2InputStream bzip2 = new CBZip2InputStream(new FileInputStream(file));
                return new BufferedReader(new InputStreamReader(bzip2));
            } else if(file.equals("-")) {
                return new BufferedReader(new InputStreamReader(System.in));
            }else 
                return new BufferedReader(new FileReader(file));   
        }
    }  

    @Override
    protected void finalize() throws Throwable {
        super.finalize(); //To change body of generated methods, choose Tools | Templates.
//        Logger.INFO("Finished: " + toStr);
    }
    
    public synchronized boolean getNextBlock(ReadBlock block) {
        block.reset();
        try {
            while(addNextRead(block) == 0) {
            }
            // if addnext is -1 then close this!
            count += block.size / LINES_PER_READ;
        } catch (IOException ex) {
// Path: halvade_upload_tool/src/be/ugent/intec/halvade/uploader/Logger.java
// public class Logger {
//     /*
//      * levels of debugging
//      * 0: INFO
//      * 1: DEBUG
//      * 2: EXCEPTION
//      * 3:ALL
//      */
//     private static int LEVEL = 0;
//     private static final int EXCEPTION = 2;
//     private static final int DEBUG = 1;
//     private static final int INFO = 0;
//     
//     
//     // TODO use configuration set LEVEL
//     public static void SETLEVEL(int NEWLEVEL) {
//         LEVEL = NEWLEVEL;
//     }
//     
//     public static void EXCEPTION(Exception ex){
//         System.err.println("[EXCEPTION] " + ex.getLocalizedMessage());
//         ex.printStackTrace();
//     }
//     
//     public static void THROWABLE(Throwable ex){
//         System.err.println("[EXCEPTION] " + ex.getLocalizedMessage());
//         ex.printStackTrace();
//     }
//     
//     public static void DEBUG(String message) {
//         if(LEVEL >= DEBUG)
//             System.err.println("[" + Timer.getGlobalTime() + " - DEBUG] " + message);
//     }
//     
//     public static void INFO(String message) {
//         if(LEVEL >= INFO)
//             System.err.println("[INFO] " + message);
//     }
//     
//     public static void DEBUG(String message, int level) {
//         if(LEVEL >= level)
//             System.err.println("[" + Timer.getGlobalTime() + " - DEBUG] " + message);
//     }
// }


// Path: halvade_upload_tool/src/be/ugent/intec/halvade/uploader/input/BaseFileReader.java
import be.ugent.intec.halvade.uploader.Logger;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.zip.GZIPInputStream;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.tools.bzip2.CBZip2InputStream;

                return new BufferedReader(new InputStreamReader(hdfsIn));
            
        } else {
            if(file.endsWith(".gz")) {
                GZIPInputStream gzip = new GZIPInputStream(new FileInputStream(file), BUFFERSIZE); 
                return new BufferedReader(new InputStreamReader(gzip));
            } else if(file.endsWith(".bz2")) {
                CBZip2InputStream bzip2 = new CBZip2InputStream(new FileInputStream(file));
                return new BufferedReader(new InputStreamReader(bzip2));
            } else if(file.equals("-")) {
                return new BufferedReader(new InputStreamReader(System.in));
            }else 
                return new BufferedReader(new FileReader(file));   
        }
    }  

    @Override
    protected void finalize() throws Throwable {
        super.finalize(); //To change body of generated methods, choose Tools | Templates.
//        Logger.INFO("Finished: " + toStr);
    }
    
    public synchronized boolean getNextBlock(ReadBlock block) {
        block.reset();
        try {
            while(addNextRead(block) == 0) {
            }
            // if addnext is -1 then close this!
            count += block.size / LINES_PER_READ;
        } catch (IOException ex) {
            Logger.INFO("error occured: " + ex.getMessage());