code: private long seek(Run<?, ?> run) throws IOException {
          class RingBuffer {
              long[] lastNlines = new long[n];
              int ptr=0;
  
              RingBuffer() {
                  for (int i=0; i<n; i++)
                      lastNlines[i] = -1;
              }
  
              void add(long pos) {
                  lastNlines[ptr] = pos;
                  ptr = (ptr+1)%lastNlines.length;
              }
  
              long get() {
                  long v = lastNlines[ptr];
                  if (v<0)    return lastNlines[0];   // didn't even wrap around
                  return v;
              }
          }
          RingBuffer rb = new RingBuffer();
  
          try (InputStream in = run.getLogInputStream()) {
              byte[] buf = new byte[4096];
              int len;
              byte prev=0;
              long pos=0;
              boolean prevIsNL = false;
              while ((len=in.read(buf))>=0) {
                  for (int i=0; i<len; i++) {
                      byte ch = buf[i];
                      boolean isNL = ch=='\r' || ch=='\n';
                      if (!isNL && prevIsNL)  rb.add(pos);
                      if (isNL && prevIsNL && !(prev=='\r' && ch=='\n'))  rb.add(pos);
                      pos++;
                      prev = ch;
                      prevIsNL = isNL;
                  }
              }
  
              return rb.get();
          }
      }
docs: Find the byte offset in the log input stream that marks "last N lines".