// 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
// protected static BufferedReader getReader(boolean readFromDistributedStorage, String file) throws FileNotFoundException, IOException {
//     InputStream hdfsIn;
//     if(readFromDistributedStorage) {
//         Path pt =new Path(file);
//         FileSystem fs = FileSystem.get(pt.toUri(), new Configuration());
//         hdfsIn = fs.open(pt);
//         // read the stream in the correct format!
//         if(file.endsWith(".gz")) {
//             GZIPInputStream gzip = new GZIPInputStream(hdfsIn, BUFFERSIZE); 
//             return new BufferedReader(new InputStreamReader(gzip));
//         } else if(file.endsWith(".bz2")) {
//             CBZip2InputStream bzip2 = new CBZip2InputStream(hdfsIn);
//             return new BufferedReader(new InputStreamReader(bzip2));
//         } else 
//             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));   
//     }
// }  


import be.ugent.intec.halvade.uploader.Logger;
import static be.ugent.intec.halvade.uploader.input.BaseFileReader.getReader;
import java.io.BufferedReader;
import java.io.IOException;
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package be.ugent.intec.halvade.uploader.input;


/**
 *
 * @author ddecap
 */
public class SingleFastQReader extends BaseFileReader {
    protected BufferedReader readerA;
    protected ReadBlock block;
    protected int readsFactor;
    

    public SingleFastQReader(boolean fromHDFS, String fileA, boolean interleaved) throws IOException {
        super(true);
        readerA = getReader(fromHDFS, fileA);
        this.isInterleaved = interleaved;
        if(isInterleaved) 
            readsFactor = 2;
        else 
            readsFactor = 1;
        toStr = fileA;
// 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
// protected static BufferedReader getReader(boolean readFromDistributedStorage, String file) throws FileNotFoundException, IOException {
//     InputStream hdfsIn;
//     if(readFromDistributedStorage) {
//         Path pt =new Path(file);
//         FileSystem fs = FileSystem.get(pt.toUri(), new Configuration());
//         hdfsIn = fs.open(pt);
//         // read the stream in the correct format!
//         if(file.endsWith(".gz")) {
//             GZIPInputStream gzip = new GZIPInputStream(hdfsIn, BUFFERSIZE); 
//             return new BufferedReader(new InputStreamReader(gzip));
//         } else if(file.endsWith(".bz2")) {
//             CBZip2InputStream bzip2 = new CBZip2InputStream(hdfsIn);
//             return new BufferedReader(new InputStreamReader(bzip2));
//         } else 
//             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));   
//     }
// }  


// Path: halvade_upload_tool/src/be/ugent/intec/halvade/uploader/input/SingleFastQReader.java
import be.ugent.intec.halvade.uploader.Logger;
import static be.ugent.intec.halvade.uploader.input.BaseFileReader.getReader;
import java.io.BufferedReader;
import java.io.IOException;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package be.ugent.intec.halvade.uploader.input;


/**
 *
 * @author ddecap
 */
public class SingleFastQReader extends BaseFileReader {
    protected BufferedReader readerA;
    protected ReadBlock block;
    protected int readsFactor;
    

    public SingleFastQReader(boolean fromHDFS, String fileA, boolean interleaved) throws IOException {
        super(true);
        readerA = getReader(fromHDFS, fileA);
        this.isInterleaved = interleaved;
        if(isInterleaved) 
            readsFactor = 2;
        else 
            readsFactor = 1;
        toStr = fileA;
        Logger.DEBUG("Single: " + toStr + (isInterleaved ? " interleaved" : ""));