package fileIO; import java.io.IOException; import java.io.InputStream; import java.util.Arrays; import shared.KillSwitch; import shared.Shared; import shared.Timer; import shared.Tools; /** * @author Brian Bushnell * */ public final class ByteFile1 extends ByteFile { public static void main(String[] args){ ByteFile1 tf=new ByteFile1(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){ if(args[2].equalsIgnoreCase("simd")){ Shared.SIMD=true; }else { last=Integer.parseInt(args[2]); } } speedtest(tf, first, last, !speedtest); tf.close(); tf.reset(); tf.close(); // tf.reset(); // byte[] b=tf.nextLine(); // System.err.println(new String(b)); // tf.pushBack(b); // b=tf.nextLine(); // System.err.println(new String(b)); // tf.bstart+=2; // tf.pushBack(b); // b=tf.nextLine(); // System.err.println(new String(b)); // b=tf.nextLine(); // System.err.println(new String(b)); // b=tf.nextLine(); // System.err.println(new String(b)); // b=tf.nextLine(); // System.err.println(new String(b)); } private static void speedtest(ByteFile1 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 static final String printNL(byte[] b){ StringBuilder sb=new StringBuilder(); for(int i=0; i0); // 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; ibuffer.length){ //This could get big if pushback is used often, //unless special steps are taken to prevent it, like leaving extra space for pushbacks. buffer=Arrays.copyOf(buffer, buffer.length*2); } Tools.shiftRight(buffer, rShift); for(int i=0; i