MCPcopy Create free account
hub / github.com/annmuor/jnode / createIndex

Method createIndex

jnode-core/src/jnode/ndl/NodelistScanner.java:59–124  ·  view source on GitHub ↗
(InputStream stream, long lastModified)

Source from the content-addressed store, hash-verified

57 }
58
59 public NodelistIndex createIndex(InputStream stream, long lastModified) {
60 NodelistIndex index = null;
61 List<FtnNdlAddress> address = new ArrayList<>();
62 try {
63 BufferedReader br = new BufferedReader(
64 new InputStreamReader(stream));
65 String line;
66 String zone = "";
67 String net = "";
68 String region = "";
69 Pattern pZone = Pattern.compile("^Zone,(\\d+),.*");
70 Pattern pNet = Pattern.compile("^Host,(\\d+),.*");
71 Pattern pReg = Pattern.compile("^Region,(\\d+),.*");
72 Pattern pNode = Pattern
73 .compile("^(Hub|Hold|Pvt|Down|)?,(\\d+),[^,]+,[^,]+,[^,]+,.*");
74 while ((line = br.readLine()) != null) {
75 Matcher mZone = pZone.matcher(line);
76 Matcher mNet = pNet.matcher(line);
77 Matcher mReg = pReg.matcher(line);
78 Matcher mNode = pNode.matcher(line);
79 String ftn = "";
80 Status status = Status.NORMAL;
81 if (mZone.matches()) {
82 zone = mZone.group(1);
83 net = zone;
84 ftn = zone + ":" + net + "/0";
85 } else if (mReg.matches()) {
86 region = mReg.group(1);
87 ftn = zone + ":" + region + "/0";
88 net = region;
89 } else if (mNet.matches()) {
90 net = mNet.group(1);
91 ftn = zone + ":" + net + "/0";
92 status = Status.HOST;
93 } else if (mNode.matches()) {
94 ftn = zone + ":" + net + "/" + mNode.group(2);
95 if (mNode.group(1).equalsIgnoreCase("hold")) {
96 status = Status.HOLD;
97 } else if (mNode.group(1).equalsIgnoreCase("down")) {
98 status = Status.DOWN;
99 } else if (mNode.group(1).equalsIgnoreCase("pvt")) {
100 status = Status.PVT;
101 } else if (mNode.group(1).equalsIgnoreCase("hub")) {
102 status = Status.HUB;
103 }
104 }
105 if (ftn.length() > 0) {
106 try {
107 FtnNdlAddress node = new FtnNdlAddress(ftn, status);
108 node.setLine(line);
109 address.add(node);
110 } catch (NumberFormatException e) {
111 //
112 }
113 }
114 }
115 br.close();
116 index = new NodelistIndex(address.toArray(new FtnNdlAddress[0]),

Callers 2

createNdlIndexFileMethod · 0.95
testNodelistMethod · 0.80

Calls 4

setLineMethod · 0.95
l4Method · 0.80
l2Method · 0.80
addMethod · 0.45

Tested by 1

testNodelistMethod · 0.64