Libraryless. Click here for Pure Java version (2228L/14K).
1 | static long indexOfBytesInFile(File f, byte[] data) ctex { |
2 | int b, l = l(data); |
3 | CircularByteBuffer buf = new(l); |
4 | temp BufferedInputStream in = bufferedFileInputStream(f); |
5 | long counter = 0; |
6 | bigLoop: while ((b = in.read()) >= 0) { |
7 | buf.add((byte) b); |
8 | ++counter; |
9 | if (buf.size() >= l) { |
10 | long start = counter-l; |
11 | for i to l: { |
12 | if (buf.get(start+i) != data[i]) |
13 | continue bigLoop; |
14 | } |
15 | ret start; |
16 | } |
17 | } |
18 | ret -1; |
19 | } |
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: | 221 / 294 |
Version history: | 4 change(s) |
Referenced in: | [show references] |