forked from simdjson/simdjson-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlockReader.java
More file actions
49 lines (38 loc) · 1.05 KB
/
BlockReader.java
File metadata and controls
49 lines (38 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package org.simdjson;
import java.util.Arrays;
class BlockReader {
private static final byte SPACE = 0x20;
private final int stepSize;
private final byte[] lastBlock;
private final byte[] spaces;
private byte[] buffer;
private int len;
private int idx = 0;
private int lenMinusStep;
BlockReader(int stepSize) {
this.stepSize = stepSize;
this.lastBlock = new byte[stepSize];
this.spaces = new byte[stepSize];
Arrays.fill(spaces, SPACE);
}
void reset(byte[] buffer, int len) {
this.idx = 0;
this.len = len;
this.buffer = buffer;
this.lenMinusStep = len < stepSize ? 0 : len - stepSize;
}
boolean hasFullBlock() {
return idx < lenMinusStep;
}
byte[] remainder() {
System.arraycopy(spaces, 0, lastBlock, 0, lastBlock.length);
System.arraycopy(buffer, idx, lastBlock, 0, len - idx);
return lastBlock;
}
void advance() {
idx += stepSize;
}
int getBlockIndex() {
return idx;
}
}