Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

19
LINES

< > BotCompany Repo | #1026627 // indexOfBytesInFile [naive search algorithm]

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (2228L/14K).

static long indexOfBytesInFile(File f, byte[] data) ctex {
  int b, l = l(data);
  CircularByteBuffer buf = new(l);
  temp BufferedInputStream in = bufferedFileInputStream(f);
  long counter = 0;
  bigLoop: while ((b = in.read()) >= 0) {
    buf.add((byte) b);
    ++counter;
    if (buf.size() >= l) {
      long start = counter-l;
      for i to l: {
        if (buf.get(start+i) != data[i])
          continue bigLoop;
      }
      ret start;
    }
  }
  ret -1;
}

Author comment

Began life as a copy of #1026625

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1026627
Snippet name: indexOfBytesInFile [naive search algorithm]
Eternal ID of this version: #1026627/5
Text MD5: 51fe3b51247bee5cfc4a14bdec0beec7
Transpilation MD5: 3a3ca814d16425149ba245dab12e7910
Author: stefan
Category: javax / io
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-01-16 22:33:12
Source code size: 486 bytes / 19 lines
Pitched / IR pitched: No / No
Views / Downloads: 220 / 292
Version history: 4 change(s)
Referenced in: [show references]