forked from ScottOaks/JavaPerformanceTuning
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractParsingTest.java
More file actions
47 lines (40 loc) · 1.43 KB
/
Copy pathAbstractParsingTest.java
File metadata and controls
47 lines (40 loc) · 1.43 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
/*
* Copyright (c) 2013,2014 Scott Oaks. All rights reserved.
*/
package net.sdo;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
public abstract class AbstractParsingTest {
public static String ITEM_ID = "ItemID";
protected boolean isItemID = false;
protected byte[] data;
protected int targetItemCount;
private ArrayList<String> itemIDs;
protected void engineInit(RunParams rp) throws IOException {}
protected abstract void engineRun(InputStream is) throws IOException;
protected boolean addItemId(String s) {
itemIDs.add(s);
if (itemIDs.size() == targetItemCount) {
return true;
}
return false;
}
public void init(RunParams rp) throws IOException {
targetItemCount = rp.getTargetItemCount();
data = rp.getInput();
engineInit(rp);
}
public void run() throws IOException {
itemIDs = new ArrayList<String>((targetItemCount == Integer.MAX_VALUE) ? 128 : targetItemCount);
isItemID = false;
engineRun(new ByteArrayInputStream(data));
if (targetItemCount != Integer.MAX_VALUE && targetItemCount != itemIDs.size()) {
throw new IOException("Unexpected count in document, found " + itemIDs.size());
}
if (System.getProperty("debugParse") != null) {
System.out.println(itemIDs);
}
}
}