package stream; import java.util.ArrayList; import fileIO.FileFormat; import fileIO.ReadWrite; import structures.ListNum; public abstract class ReadInputStream { public static final ArrayList toReads(String fname, int defaultFormat, long maxReads){ if(fname==null){return null;} FileFormat ff=FileFormat.testInput(fname, defaultFormat, null, false, true); return toReads(ff, maxReads); } public static final Read[] toReadArray(FileFormat ff, long maxReads){ ArrayList list=toReads(ff, maxReads); return list==null ? null : list.toArray(new Read[0]); } public static final ArrayList toReads(FileFormat ff, long maxReads){ ArrayList list=new ArrayList(); /* Start an input stream */ ConcurrentReadInputStream cris=ConcurrentReadInputStream.getReadInputStream(maxReads, false, ff, null); cris.start(); //4567 ListNum ln=cris.nextList(); ArrayList reads=(ln!=null ? ln.list : null); /* Iterate through read lists from the input stream */ while(ln!=null && reads!=null && reads.size()>0){//ln!=null prevents a compiler potential null access warning list.addAll(reads); /* Dispose of the old list and fetch a new one */ cris.returnList(ln); ln=cris.nextList(); reads=(ln!=null ? ln.list : null); } /* Cleanup */ cris.returnList(ln); ReadWrite.closeStream(cris); return list; } public abstract Read next(); // public final ArrayList fetchAll(){ // ArrayList out=new ArrayList(); // for(ArrayList list=nextList(); list!=null && list.size()>0; list=nextList()){ // out.addAll(list); // } // close(); // return out; // } public abstract ArrayList nextList(); public abstract boolean hasMore(); public abstract void restart(); /** Returns true if there was an error, false otherwise */ public abstract boolean close(); public abstract boolean paired(); protected static final ArrayList toList(Read[] array){ if(array==null || array.length==0){return null;} ArrayList list=new ArrayList(array.length); for(int i=0; i