package fileIO; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import shared.KillSwitch; import shared.Shared; import shared.Timer; import shared.Tools; import structures.ListNum; /** * Written for testing a NERSC slowdown in multithreaded file reading. * The problem was sometimes sidestepped by eliminating "if(pushBack!=null){" and reimplementing pushback. * However, that does not address the cause, so is not an overall solution; the cause remains a mystery. * This class may safely be deleted. * * @author Brian Bushnell * */ public class QuickFile { public static void main(String[] args){ QuickFile tf=new QuickFile(args.length>0 ? args[0] : "stdin", true); long first=0, last=100; boolean speedtest=false; if(args.length>1){ if(args[1].equalsIgnoreCase("speedtest")){ speedtest=true; first=0; last=Long.MAX_VALUE; }else{ first=Integer.parseInt(args[1]); last=first+100; } } if(args.length>2){ last=Integer.parseInt(args[2]); } speedtest(tf, first, last, !speedtest); tf.close(); tf.reset(); tf.close(); } private static void speedtest(QuickFile tf, long first, long last, boolean reprint){ Timer t=new Timer(); long lines=0; long bytes=0; for(long i=0; i0) : bstart+", "+nlpos+", "+limit; bstart=nlpos+1; // System.out.println("F: bstart="+bstart+", bstop="+bstop+", nlpos="+nlpos+", returning='"+printNL(line)+"'"); return line; } final byte[] dummy=new byte[100]; private int fillBuffer(){ if(bstart0); // assert(bstop==buffer.length); int extra=bstop-bstart; for(int i=0; i=slasher || buffer[i]==tab); assert(buffer[i]!=slashn); } bstop=extra; // System.err.println(); // {//for debugging only // buffer=new byte[bufferlen]; // bstop=0; // bstart=0; // } }else{ bstop=0; } bstart=0; int len=bstop; int r=-1; while(len==bstop){//hit end of input without encountering a newline if(bstop==buffer.length){ // assert(false) : len+", "+bstop; buffer=KillSwitch.copyOf(buffer, buffer.length*2); } try { r=is.read(buffer, bstop, buffer.length-bstop); // byte[] x=new byte[buffer.length-bstop]; // r=is.read(x); // if(r>0){ // for(int i=0, j=bstop; i toByteLines(){ byte[] s=null; ArrayList list=new ArrayList(4096); for(s=nextLine(); s!=null; s=nextLine()){ list.add(s); } return list; } public final long countLines(){ byte[] s=null; long count=0; for(s=nextLine(); s!=null; s=nextLine()){count++;} reset(); return count; } public synchronized final ListNum nextList(){ byte[] line=nextLine(); if(line==null){return null;} ArrayList list=new ArrayList(200); list.add(line); for(int i=1; i<200; i++){ line=nextLine(); if(line==null){break;} list.add(line); } ListNum ln=new ListNum(list, nextID); nextID++; return ln; } public final boolean exists(){ return name().equals("stdin") || name().startsWith("stdin.") || name().startsWith("jar:") || new File(name()).exists(); //TODO Ugly and unsafe hack for files in jars } public final void pushBack(byte[] line){ assert(pushBack==null); pushBack=line; } public final String name(){return ff.name();} public final boolean allowSubprocess(){return ff.allowSubprocess();} public final FileFormat ff; public static boolean FORCE_MODE_BF1=false;//!(Shared.GENEPOOL || Shared.DENOVO || Shared.CORI || Shared.WINDOWS); public static boolean FORCE_MODE_BF2=false; public static boolean FORCE_MODE_BF3=false; protected final static byte slashr='\r', slashn='\n', carrot='>', plus='+', at='@';//, tab='\t'; long a=1; long b=2; long c=3; long d=4; byte[] p0=null; byte[] p1=null; byte[] p2=null; byte[] p3=null; private byte[] pushBack=null; private long nextID=0; private boolean open=false; private byte[] buffer=new byte[bufferlen]; private static final byte[] blankLine=new byte[0]; private int bstart=0, bstop=0; public InputStream is; public long lineNum=-1; public static boolean verbose=false; public static boolean BUFFERED=false; public static int bufferlen=16384; private boolean errorState=false; }