MCPcopy Create free account
hub / github.com/Fedict/dcattools / parse

Method parse

tools/src/main/java/be/gov/data/tools/LinkChecker.java:114–155  ·  view source on GitHub ↗

Parse CSV file with URLs. Last column of the row should be the URL.

()

Source from the content-addressed store, hash-verified

112 * Last column of the row should be the URL.
113 */
114 private static void parse() {
115 String file = getProperty("urlfile");
116 String outfile = getProperty("outfile");
117
118 int skiplines = Integer.parseInt(getProperty("skiplines"));
119 List<String> okcodes = Arrays.asList(getProperty("httpok").split(","));
120
121 try ( BufferedReader r = Files.newBufferedReader(Paths.get(file));
122 BufferedWriter w = Files.newBufferedWriter(Paths.get(outfile));) {
123
124 logger.info("Loading urls from {}, skipping {} lines", file, skiplines);
125
126 String line = r.readLine();
127
128 // skip header line(s)
129 for(int i = 0; (i < skiplines) && (line != null); i++) {
130 line = r.readLine();
131 }
132
133 int urlOK = 0;
134 int urlBad = 0;
135 int code = -1;
136
137 while(line != null) {
138 // SPARQL CSV writer always uses "," as separator
139 String s[] = line.split(",");
140 code = checkURL(s[s.length-1]);
141 if (okcodes.contains(Integer.toString(code))) {
142 urlOK++;
143 } else {
144 urlBad++;
145 w.write(code + ";" + line);
146 w.newLine();
147 }
148 line = r.readLine();
149 }
150 logger.info("Checked {} urls: {} ok, {} not ok",
151 urlOK + urlBad, urlOK, urlBad);
152 } catch (IOException ex) {
153 logger.error("Error loading file", ex);
154 }
155 }
156
157 /**
158 * Main program

Callers 4

mainMethod · 0.95
mainMethod · 0.45
cacheMethod · 0.45
translateMethod · 0.45

Calls 3

getPropertyMethod · 0.95
checkURLMethod · 0.95
writeMethod · 0.80

Tested by

no test coverage detected