missing class
authorbdemsky <bdemsky>
Sun, 18 Oct 2009 09:56:13 +0000 (09:56 +0000)
committerbdemsky <bdemsky>
Sun, 18 Oct 2009 09:56:13 +0000 (09:56 +0000)
Robust/src/Benchmarks/SingleTM/Yada/bytereader.java [new file with mode: 0644]

diff --git a/Robust/src/Benchmarks/SingleTM/Yada/bytereader.java b/Robust/src/Benchmarks/SingleTM/Yada/bytereader.java
new file mode 100644 (file)
index 0000000..60f4f2f
--- /dev/null
@@ -0,0 +1,86 @@
+public class bytereader {
+  FileInputStream fis;
+  byte[] buffer;
+  int lastlocation;
+  int pos;
+  byte[] tmp;
+
+  public bytereader(FileInputStream fis) {
+    this.fis=fis;
+    this.buffer=new byte[1024];
+    this.tmp=new byte[200];
+    lastlocation=0;
+    pos=0;
+  }
+  
+  public void jumptonextline() {
+    while(true) {
+      for(;pos<lastlocation;pos++) {
+       if (buffer[pos]=='\n') {
+         pos++;
+         return;
+       }
+      }
+      if (pos==lastlocation) {
+       readnewdata();
+      }
+    }
+  }
+
+  private void readnewdata() {
+    pos=0;
+    lastlocation=fis.read(buffer);
+  }
+
+  byte[] curbuffer;
+  int start;
+  int end;
+
+  private void skipline() {
+    if (buffer[pos]=='#')
+      jumptonextline();
+  }
+
+  public int getInt() {
+    getBytes();
+    String str=new String(curbuffer, start, end-start);
+    return Integer.parseInt(str);
+  }
+
+  public double getDouble() {
+    getBytes();
+    String str=new String(curbuffer, start, end-start);
+    return Double.parseDouble(str);
+  }
+
+  private void getBytes() {
+    start=pos;
+    for(;pos<lastlocation;pos++) {
+      if (buffer[pos]==' '||
+         buffer[pos]=='\n') {
+       end=pos;
+       pos++;
+       skipline();
+       curbuffer=buffer;
+       return;
+      }
+    }
+    curbuffer=tmp;
+    for(int i=start;i<lastlocation;i++) {
+      tmp[i-start]=buffer[i];
+    }
+    readnewdata();
+    start=lastlocation-start;
+    for(;true;pos++) {
+      if (buffer[pos]==' '||
+         buffer[pos]=='\n') {
+       pos++;
+       skipline();
+       return;
+      }
+      tmp[pos+start]=buffer[pos];
+    }
+    end=pos+start;
+  }
+
+}
\ No newline at end of file