// Path: src/libra/common/sequence/Read.java
// public class Read {
//     
//     private static final Log LOG = LogFactory.getLog(Read.class);
//     
//     public static final char FASTA_READ_DESCRIPTION_IDENTIFIER = '>';
//     public static final char FASTQ_READ_DESCRIPTION_IDENTIFIER = '@';
//     public static final char FASTQ_READ_DESCRIPTION2_IDENTIFIER = '+';
//     
//     private String description;
//     private String quality;
//     private String description2;
//     private List<String> sequences = new ArrayList<String>();
//     
//     public Read() {
//     }
//     
//     public void setDescription(String description) {
//         this.description = description;
//     }
//     
//     public String getDescription() {
//         return this.description;
//     }
//     
//     public void setQuality(String quality) {
//         this.quality = quality;
//     }
//     
//     public String getQuality() {
//         return this.quality;
//     }
//     
//     public void setDescription2(String description2) {
//         this.description2 = description2;
//     }
//     
//     public String getDescription2() {
//         return this.description2;
//     }
//     
//     public void addSequence(String sequence) {
//         this.sequences.add(sequence);
//     }
//     
//     public List<String> getSequences() {
//         return Collections.unmodifiableList(sequences);
//     }
//     
//     public String getFullSequence() {
//         StringBuilder sb = new StringBuilder();
//         for(String sequence : this.sequences) {
//             sb.append(sequence.trim());
//         }
//         return sb.toString();
//     }
//     
//     public void parseFasta(List<String> lines) throws IOException {
//         clear();
//         
//         if(lines.size() < 2) {
//             throw new IOException("invalid fasta read format");
//         }
//         
//         int lineNo = 0;
//         //LOG.info("Parsing a FASTA read");
//         for(String line : lines) {
//             //LOG.info(line);
//             if(line.length() > 0) {
//                 if(lineNo == 0) {
//                     if(line.charAt(0) == FASTA_READ_DESCRIPTION_IDENTIFIER) {
//                         setDescription(line.trim());
//                     } else {
//                         throw new IOException("invalid fasta read description format - " + line);
//                     }
//                 } else {
//                     if(line.charAt(0) == FASTA_READ_DESCRIPTION_IDENTIFIER) {
//                         throw new IOException("invalid fasta read sequence format - " + line);
//                     } else {
//                         addSequence(line.trim());
//                     }
//                 }
//             }
//             
//             lineNo++;
//         }
//     }
//     
//     public void parseFastq(List<String> lines) throws IOException {
//         clear();
//         
//         if(lines.size() == 0) {
//             return;
//         }
//         
//         if(lines.size() != 4) {
//             String header = lines.get(0);
//             throw new IOException(String.format("invalid fastq read format - a read (%s) has %d lines", header, lines.size()));
//         }
//         
//         int lineNo = 0;
//         //LOG.info("Parsing a FASTQ read");
//         for(String line : lines) {
//             //LOG.info(line);
//             switch(lineNo) {
//                 case 0:
//                     {
//                         if(line.charAt(0) == FASTQ_READ_DESCRIPTION_IDENTIFIER) {
//                             setDescription(line.trim());
//                         } else {
//                             throw new IOException("invalid fastq read description format - " + line);
//                         }
//                     }
//                     break;
//                 case 1:
//                     {
//                         addSequence(line.trim());
//                     }
//                     break;
//                 case 2:
//                     {
//                         if(line.charAt(0) == FASTQ_READ_DESCRIPTION2_IDENTIFIER) {
//                             setDescription2(line.trim());
//                         } else {
//                             throw new IOException("invalid fastq read description2 format - " + line);
//                         }
//                     }
//                     break;
//                 case 3:
//                     {
//                         setQuality(line.trim());
//                     }
//                     break;
//             }
//             
//             lineNo++;
//         }
//     }
//     
//     public void parse(List<String> lines) throws IOException {
//         // check first line
//         String first = lines.get(0);
//         if(first.charAt(0) == FASTQ_READ_DESCRIPTION_IDENTIFIER) {
//             parseFastq(lines);
//             return;
//         } else if(first.charAt(0) == FASTA_READ_DESCRIPTION_IDENTIFIER) {
//             parseFasta(lines);
//             return;
//         }
//            
//         throw new IOException("invalid read format");
//     }
//     
//     public void clear() {
//         this.description = null;
//         this.quality = null;
//         this.description2 = null;
//         this.sequences.clear();
//     }
//     
//     public boolean isEmpty() {
//         return this.description == null;
//     }
// }


import java.io.IOException;
import java.io.InputStream;
import libra.common.sequence.Read;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
    @Override
    public long readRead(Read read) throws IOException {
        long bytesConsumed = 0;
        long readSize = 0;
        read.clear();
        
        if(!this.finished) {
            readSize = super.skipIncompleteRead();
            bytesConsumed += readSize;
            this.totalBytesRead += readSize;
            if(this.totalBytesRead >= this.splitLength) {
                // actual read starts after the split
                // no content in this block
                this.finished = true;
                return bytesConsumed;
            }

            readSize = super.readRead(read);
            if(readSize <= 0) {
                //EOF
                this.finished = true;
                return bytesConsumed;
            }
            
            bytesConsumed += readSize;
            this.totalBytesRead += readSize;
            if(this.totalBytesRead >= this.splitLength) {
                this.finished = true;
            }
        }
// Path: src/libra/common/sequence/Read.java
// public class Read {
//     
//     private static final Log LOG = LogFactory.getLog(Read.class);
//     
//     public static final char FASTA_READ_DESCRIPTION_IDENTIFIER = '>';
//     public static final char FASTQ_READ_DESCRIPTION_IDENTIFIER = '@';
//     public static final char FASTQ_READ_DESCRIPTION2_IDENTIFIER = '+';
//     
//     private String description;
//     private String quality;
//     private String description2;
//     private List<String> sequences = new ArrayList<String>();
//     
//     public Read() {
//     }
//     
//     public void setDescription(String description) {
//         this.description = description;
//     }
//     
//     public String getDescription() {
//         return this.description;
//     }
//     
//     public void setQuality(String quality) {
//         this.quality = quality;
//     }
//     
//     public String getQuality() {
//         return this.quality;
//     }
//     
//     public void setDescription2(String description2) {
//         this.description2 = description2;
//     }
//     
//     public String getDescription2() {
//         return this.description2;
//     }
//     
//     public void addSequence(String sequence) {
//         this.sequences.add(sequence);
//     }
//     
//     public List<String> getSequences() {
//         return Collections.unmodifiableList(sequences);
//     }
//     
//     public String getFullSequence() {
//         StringBuilder sb = new StringBuilder();
//         for(String sequence : this.sequences) {
//             sb.append(sequence.trim());
//         }
//         return sb.toString();
//     }
//     
//     public void parseFasta(List<String> lines) throws IOException {
//         clear();
//         
//         if(lines.size() < 2) {
//             throw new IOException("invalid fasta read format");
//         }
//         
//         int lineNo = 0;
//         //LOG.info("Parsing a FASTA read");
//         for(String line : lines) {
//             //LOG.info(line);
//             if(line.length() > 0) {
//                 if(lineNo == 0) {
//                     if(line.charAt(0) == FASTA_READ_DESCRIPTION_IDENTIFIER) {
//                         setDescription(line.trim());
//                     } else {
//                         throw new IOException("invalid fasta read description format - " + line);
//                     }
//                 } else {
//                     if(line.charAt(0) == FASTA_READ_DESCRIPTION_IDENTIFIER) {
//                         throw new IOException("invalid fasta read sequence format - " + line);
//                     } else {
//                         addSequence(line.trim());
//                     }
//                 }
//             }
//             
//             lineNo++;
//         }
//     }
//     
//     public void parseFastq(List<String> lines) throws IOException {
//         clear();
//         
//         if(lines.size() == 0) {
//             return;
//         }
//         
//         if(lines.size() != 4) {
//             String header = lines.get(0);
//             throw new IOException(String.format("invalid fastq read format - a read (%s) has %d lines", header, lines.size()));
//         }
//         
//         int lineNo = 0;
//         //LOG.info("Parsing a FASTQ read");
//         for(String line : lines) {
//             //LOG.info(line);
//             switch(lineNo) {
//                 case 0:
//                     {
//                         if(line.charAt(0) == FASTQ_READ_DESCRIPTION_IDENTIFIER) {
//                             setDescription(line.trim());
//                         } else {
//                             throw new IOException("invalid fastq read description format - " + line);
//                         }
//                     }
//                     break;
//                 case 1:
//                     {
//                         addSequence(line.trim());
//                     }
//                     break;
//                 case 2:
//                     {
//                         if(line.charAt(0) == FASTQ_READ_DESCRIPTION2_IDENTIFIER) {
//                             setDescription2(line.trim());
//                         } else {
//                             throw new IOException("invalid fastq read description2 format - " + line);
//                         }
//                     }
//                     break;
//                 case 3:
//                     {
//                         setQuality(line.trim());
//                     }
//                     break;
//             }
//             
//             lineNo++;
//         }
//     }
//     
//     public void parse(List<String> lines) throws IOException {
//         // check first line
//         String first = lines.get(0);
//         if(first.charAt(0) == FASTQ_READ_DESCRIPTION_IDENTIFIER) {
//             parseFastq(lines);
//             return;
//         } else if(first.charAt(0) == FASTA_READ_DESCRIPTION_IDENTIFIER) {
//             parseFasta(lines);
//             return;
//         }
//            
//         throw new IOException("invalid read format");
//     }
//     
//     public void clear() {
//         this.description = null;
//         this.quality = null;
//         this.description2 = null;
//         this.sequences.clear();
//     }
//     
//     public boolean isEmpty() {
//         return this.description == null;
//     }
// }


// Path: src/libra/common/hadoop/io/reader/sequence/UncompressedSplitReadReader.java
import java.io.IOException;
import java.io.InputStream;
import libra.common.sequence.Read;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;

    @Override
    public long readRead(Read read) throws IOException {
        long bytesConsumed = 0;
        long readSize = 0;
        read.clear();
        
        if(!this.finished) {
            readSize = super.skipIncompleteRead();
            bytesConsumed += readSize;
            this.totalBytesRead += readSize;
            if(this.totalBytesRead >= this.splitLength) {
                // actual read starts after the split
                // no content in this block
                this.finished = true;
                return bytesConsumed;
            }

            readSize = super.readRead(read);
            if(readSize <= 0) {
                //EOF
                this.finished = true;
                return bytesConsumed;
            }
            
            bytesConsumed += readSize;
            this.totalBytesRead += readSize;
            if(this.totalBytesRead >= this.splitLength) {
                this.finished = true;
            }
        }
        return bytesConsumed;