forked from simdjson/simdjson-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestUtils.java
More file actions
34 lines (26 loc) · 996 Bytes
/
TestUtils.java
File metadata and controls
34 lines (26 loc) · 996 Bytes
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
package org.simdjson;
import jdk.incubator.vector.ByteVector;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import static java.nio.charset.StandardCharsets.UTF_8;
class TestUtils {
static String padWithSpaces(String str) {
byte[] strBytes = toUtf8(str);
byte[] padded = new byte[strBytes.length + 64];
Arrays.fill(padded, (byte) ' ');
System.arraycopy(strBytes, 0, padded, 0, strBytes.length);
return new String(padded, UTF_8);
}
static ByteVector chunk(String str, int n) {
return ByteVector.fromArray(StructuralIndexer.BYTE_SPECIES, str.getBytes(UTF_8), n * StructuralIndexer.BYTE_SPECIES.vectorByteSize());
}
static byte[] toUtf8(String str) {
return str.getBytes(UTF_8);
}
static byte[] loadTestFile(String name) throws IOException {
try (InputStream is = TestUtils.class.getResourceAsStream(name)) {
return is.readAllBytes();
}
}
}