List of usage examples for com.fasterxml.jackson.databind JsonNode get
public JsonNode get(String paramString)
From source file:software.uncharted.Reindex.java
public static void main(String[] args) throws IOException { // Get all images JsonNode response = HTTPUtil.getJSON("http://localhost:3030/images/all"); final ObjectMapper mapper = new ObjectMapper(); // Create a list of post requests List<JsonNode> indexRequestBodies = JSONUtil.getStringList(response, "files").stream() .map(file -> "http://localhost:3030/image/" + file).map(url -> "{\"url\":\"" + url + "\"}") .map(json -> {//w w w . j a va2 s. c om try { return mapper.readTree(json); } catch (IOException e) { } return null; }).filter(Objects::nonNull).collect(Collectors.toList()); // Reindex each for (JsonNode body : indexRequestBodies) { System.out.println("Indexing " + body.get("url").asText()); HTTPUtil.post("http://localhost:8080/index", body); } }
From source file:com.datis.kafka.stream.PageViewUntypedDemo.java
public static void main(String[] args) throws Exception { Properties props = new Properties(); props.put(StreamsConfig.APPLICATION_ID_CONFIG, "streams-pageview-untyped"); props.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092"); props.put(StreamsConfig.ZOOKEEPER_CONNECT_CONFIG, "localhost:2181"); props.put(StreamsConfig.TIMESTAMP_EXTRACTOR_CLASS_CONFIG, JsonTimestampExtractor.class); // setting offset reset to earliest so that we can re-run the demo code with the same pre-loaded data props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); KStreamBuilder builder = new KStreamBuilder(); final Serializer<JsonNode> jsonSerializer = new JsonSerializer(); final Deserializer<JsonNode> jsonDeserializer = new JsonDeserializer(); final Serde<JsonNode> jsonSerde = Serdes.serdeFrom(jsonSerializer, jsonDeserializer); KStream<String, JsonNode> views = builder.stream(Serdes.String(), jsonSerde, "streams-pageview-input"); KTable<String, JsonNode> users = builder.table(Serdes.String(), jsonSerde, "streams-userprofile-input"); KTable<String, String> userRegions = users.mapValues(new ValueMapper<JsonNode, String>() { @Override//w ww .j av a 2 s .c om public String apply(JsonNode record) { return record.get("region").textValue(); } }); KStream<JsonNode, JsonNode> regionCount = views .leftJoin(userRegions, new ValueJoiner<JsonNode, String, JsonNode>() { @Override public JsonNode apply(JsonNode view, String region) { ObjectNode jNode = JsonNodeFactory.instance.objectNode(); return jNode.put("user", view.get("user").textValue()) .put("page", view.get("page").textValue()) .put("region", region == null ? "UNKNOWN" : region); } }).map(new KeyValueMapper<String, JsonNode, KeyValue<String, JsonNode>>() { @Override public KeyValue<String, JsonNode> apply(String user, JsonNode viewRegion) { return new KeyValue<>(viewRegion.get("region").textValue(), viewRegion); } }) .countByKey(TimeWindows.of("GeoPageViewsWindow", 7 * 24 * 60 * 60 * 1000L).advanceBy(1000), Serdes.String()) // TODO: we can merge ths toStream().map(...) with a single toStream(...) .toStream().map(new KeyValueMapper<Windowed<String>, Long, KeyValue<JsonNode, JsonNode>>() { @Override public KeyValue<JsonNode, JsonNode> apply(Windowed<String> key, Long value) { ObjectNode keyNode = JsonNodeFactory.instance.objectNode(); keyNode.put("window-start", key.window().start()).put("region", key.key()); ObjectNode valueNode = JsonNodeFactory.instance.objectNode(); valueNode.put("count", value); return new KeyValue<>((JsonNode) keyNode, (JsonNode) valueNode); } }); // write to the result topic regionCount.to(jsonSerde, jsonSerde, "streams-pageviewstats-untyped-output"); KafkaStreams streams = new KafkaStreams(builder, props); streams.start(); // usually the stream application would be running forever, // in this example we just let it run for some time and stop since the input data is finite. Thread.sleep(5000L); streams.close(); }
From source file:com.jeeffy.test.streams.pageview.PageViewUntypedDemo.java
public static void main(String[] args) throws Exception { Properties props = new Properties(); props.put(StreamsConfig.APPLICATION_ID_CONFIG, "streams-pageview-untyped"); props.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092"); props.put(StreamsConfig.ZOOKEEPER_CONNECT_CONFIG, "localhost:2181"); props.put(StreamsConfig.TIMESTAMP_EXTRACTOR_CLASS_CONFIG, JsonTimestampExtractor.class); // setting offset reset to earliest so that we can re-run the demo code with the same pre-loaded data props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); KStreamBuilder builder = new KStreamBuilder(); final Serializer<JsonNode> jsonSerializer = new JsonSerializer(); final Deserializer<JsonNode> jsonDeserializer = new JsonDeserializer(); final Serde<JsonNode> jsonSerde = Serdes.serdeFrom(jsonSerializer, jsonDeserializer); KStream<String, JsonNode> views = builder.stream(Serdes.String(), jsonSerde, "streams-pageview-input"); KTable<String, JsonNode> users = builder.table(Serdes.String(), jsonSerde, "streams-userprofile-input", "streams-userprofile-store-name"); KTable<String, String> userRegions = users.mapValues(new ValueMapper<JsonNode, String>() { @Override/*from w ww . ja v a 2 s.com*/ public String apply(JsonNode record) { return record.get("region").textValue(); } }); KStream<JsonNode, JsonNode> regionCount = views .leftJoin(userRegions, new ValueJoiner<JsonNode, String, JsonNode>() { @Override public JsonNode apply(JsonNode view, String region) { ObjectNode jNode = JsonNodeFactory.instance.objectNode(); return jNode.put("user", view.get("user").textValue()) .put("page", view.get("page").textValue()) .put("region", region == null ? "UNKNOWN" : region); } }).map(new KeyValueMapper<String, JsonNode, KeyValue<String, JsonNode>>() { @Override public KeyValue<String, JsonNode> apply(String user, JsonNode viewRegion) { return new KeyValue<>(viewRegion.get("region").textValue(), viewRegion); } }).groupByKey(Serdes.String(), jsonSerde) .count(TimeWindows.of(7 * 24 * 60 * 60 * 1000L).advanceBy(1000), "RollingSevenDaysOfPageViewsByRegion") // TODO: we can merge ths toStream().map(...) with a single toStream(...) .toStream().map(new KeyValueMapper<Windowed<String>, Long, KeyValue<JsonNode, JsonNode>>() { @Override public KeyValue<JsonNode, JsonNode> apply(Windowed<String> key, Long value) { ObjectNode keyNode = JsonNodeFactory.instance.objectNode(); keyNode.put("window-start", key.window().start()).put("region", key.key()); ObjectNode valueNode = JsonNodeFactory.instance.objectNode(); valueNode.put("count", value); return new KeyValue<>((JsonNode) keyNode, (JsonNode) valueNode); } }); // write to the result topic regionCount.to(jsonSerde, jsonSerde, "streams-pageviewstats-untyped-output"); KafkaStreams streams = new KafkaStreams(builder, props); streams.start(); // usually the stream application would be running forever, // in this example we just let it run for some time and stop since the input data is finite. Thread.sleep(5000L); streams.close(); }
From source file:org.eel.kitchen.jsonschema.MiniPerfTest2.java
public static void main(final String... args) throws IOException, JsonSchemaException { final JsonNode googleAPI = JsonLoader.fromResource("/other/google-json-api.json"); final Map<String, JsonNode> schemas = JacksonUtils.nodeToMap(googleAPI.get("schemas")); final JsonSchemaFactory factory = JsonSchemaFactory.defaultFactory(); final JsonSchema schema = factory.fromURI("resource:/schema-draftv3.json"); long begin, current; begin = System.currentTimeMillis(); doValidate(schemas, schema, -1);/*from w w w . j a v a2s . c o m*/ current = System.currentTimeMillis(); System.out.println("Initial validation :" + (current - begin) + " ms"); begin = System.currentTimeMillis(); for (int i = 0; i < 500; i++) { doValidate(schemas, schema, i); if (i % 20 == 0) { current = System.currentTimeMillis(); System.out.println(String.format("Iteration %d (in %d ms)", i, current - begin)); } } final long end = System.currentTimeMillis(); System.out.println("END -- time in ms: " + (end - begin)); System.exit(0); }
From source file:org.glowroot.benchmark.ResultFormatter.java
public static void main(String[] args) throws IOException { File resultFile = new File(args[0]); Scores scores = new Scores(); double baselineStartupTime = -1; double glowrootStartupTime = -1; ObjectMapper mapper = new ObjectMapper(); String content = Files.toString(resultFile, Charsets.UTF_8); content = content.replaceAll("\n", " "); ArrayNode results = (ArrayNode) mapper.readTree(content); for (JsonNode result : results) { String benchmark = result.get("benchmark").asText(); benchmark = benchmark.substring(0, benchmark.lastIndexOf('.')); ObjectNode primaryMetric = (ObjectNode) result.get("primaryMetric"); double score = primaryMetric.get("score").asDouble(); if (benchmark.equals(StartupBenchmark.class.getName())) { baselineStartupTime = score; continue; } else if (benchmark.equals(StartupWithGlowrootBenchmark.class.getName())) { glowrootStartupTime = score; continue; }//from w w w .j a v a 2 s . co m ObjectNode scorePercentiles = (ObjectNode) primaryMetric.get("scorePercentiles"); double score50 = scorePercentiles.get("50.0").asDouble(); double score95 = scorePercentiles.get("95.0").asDouble(); double score99 = scorePercentiles.get("99.0").asDouble(); double score999 = scorePercentiles.get("99.9").asDouble(); double score9999 = scorePercentiles.get("99.99").asDouble(); double allocatedBytes = getAllocatedBytes(result); if (benchmark.equals(ServletBenchmark.class.getName())) { scores.baselineResponseTimeAvg = score; scores.baselineResponseTime50 = score50; scores.baselineResponseTime95 = score95; scores.baselineResponseTime99 = score99; scores.baselineResponseTime999 = score999; scores.baselineResponseTime9999 = score9999; scores.baselineAllocatedBytes = allocatedBytes; } else if (benchmark.equals(ServletWithGlowrootBenchmark.class.getName())) { scores.glowrootResponseTimeAvg = score; scores.glowrootResponseTime50 = score50; scores.glowrootResponseTime95 = score95; scores.glowrootResponseTime99 = score99; scores.glowrootResponseTime999 = score999; scores.glowrootResponseTime9999 = score9999; scores.glowrootAllocatedBytes = allocatedBytes; } else { throw new AssertionError(benchmark); } } System.out.println(); printScores(scores); if (baselineStartupTime != -1) { System.out.println("STARTUP"); System.out.format("%25s%14s%14s%n", "", "baseline", "glowroot"); printLine("Startup time (avg)", "ms", baselineStartupTime, glowrootStartupTime); } System.out.println(); }
From source file:com.github.fge.jsonschema.NewAPIPerfTest.java
public static void main(final String... args) throws IOException, ProcessingException { final JsonNode googleAPI = JsonLoader.fromResource("/other/google-json-api.json"); final Map<String, JsonNode> googleSchemas = JacksonUtils.asMap(googleAPI.get("schemas")); long begin, current; begin = System.currentTimeMillis(); doValidate(googleSchemas, -1);/*from w ww . j a va 2 s . co m*/ current = System.currentTimeMillis(); System.out.println("Initial validation :" + (current - begin) + " ms"); begin = System.currentTimeMillis(); for (int i = 0; i < 500; i++) { doValidate(googleSchemas, i); if (i % 20 == 0) { current = System.currentTimeMillis(); System.out.println(String.format("Iteration %d (in %d ms)", i, current - begin)); } } final long end = System.currentTimeMillis(); System.out.println("END -- time in ms: " + (end - begin)); System.exit(0); }
From source file:au.org.ands.vocabs.toolkit.db.PopulateAccessPoints.java
/** * Main program./*from ww w . j a va 2 s . co m*/ * @param args Command-line arguments */ public static void main(final String[] args) { // Create prefixes that both end with a slash, so that // they can be substituted for each other. String sparqlPrefix = sparqlPrefixProperty; if (!sparqlPrefix.endsWith("/")) { sparqlPrefix += "/"; } String sesamePrefix = sesamePrefixProperty; if (!sesamePrefix.endsWith("/")) { sesamePrefix += "/"; } sesamePrefix += "repositories/"; System.out.println("sparqlPrefix: " + sparqlPrefix); System.out.println("sesamePrefix: " + sesamePrefix); List<Version> versions = VersionUtils.getAllVersions(); for (Version version : versions) { System.out.println(version.getId()); System.out.println(version.getTitle()); String data = version.getData(); System.out.println(data); JsonNode dataJson = TaskUtils.jsonStringToTree(data); JsonNode accessPoints = dataJson.get("access_points"); if (accessPoints != null) { System.out.println(accessPoints); System.out.println(accessPoints.size()); for (JsonNode accessPoint : accessPoints) { System.out.println(accessPoint); AccessPoint ap = new AccessPoint(); ap.setVersionId(version.getId()); String type = accessPoint.get("type").asText(); JsonObjectBuilder jobPortal = Json.createObjectBuilder(); JsonObjectBuilder jobToolkit = Json.createObjectBuilder(); String uri; switch (type) { case AccessPoint.FILE_TYPE: ap.setType(type); // Get the path from the original access point. String filePath = accessPoint.get("uri").asText(); // Save the last component of the path to use // in the portal URI. String downloadFilename = Paths.get(filePath).getFileName().toString(); if (!filePath.startsWith("/")) { // Relative path that we need to fix up manually. filePath = "FIXME " + filePath; } jobToolkit.add("path", filePath); ap.setPortalData(""); ap.setToolkitData(jobToolkit.build().toString()); // Persist what we have ... AccessPointUtils.saveAccessPoint(ap); // ... so that now we can get access to the // ID of the persisted object with ap2.getId(). String format; if (downloadFilename.endsWith(".trig")) { // Force TriG. This is needed for some legacy // cases where the filename is ".trig" but // the format has been incorrectly recorded // as RDF/XML. format = "TriG"; } else { format = accessPoint.get("format").asText(); } jobPortal.add("format", format); jobPortal.add("uri", downloadPrefixProperty + ap.getId() + "/" + downloadFilename); ap.setPortalData(jobPortal.build().toString()); AccessPointUtils.updateAccessPoint(ap); break; case AccessPoint.API_SPARQL_TYPE: ap.setType(type); uri = accessPoint.get("uri").asText(); jobPortal.add("uri", uri); if (uri.startsWith(sparqlPrefix)) { // One of ours, so also add a sesameDownload // endpoint. AccessPoint ap2 = new AccessPoint(); ap2.setVersionId(version.getId()); ap2.setType(AccessPoint.SESAME_DOWNLOAD_TYPE); ap2.setPortalData(""); ap2.setToolkitData(""); // Persist what we have ... AccessPointUtils.saveAccessPoint(ap2); // ... so that now we can get access to the // ID of the persisted object with ap2.getId(). JsonObjectBuilder job2Portal = Json.createObjectBuilder(); JsonObjectBuilder job2Toolkit = Json.createObjectBuilder(); job2Portal.add("uri", downloadPrefixProperty + ap2.getId() + "/" + Download.downloadFilename(ap2, "")); job2Toolkit.add("uri", uri.replaceFirst(sparqlPrefix, sesamePrefix)); ap2.setPortalData(job2Portal.build().toString()); ap2.setToolkitData(job2Toolkit.build().toString()); AccessPointUtils.updateAccessPoint(ap2); jobPortal.add("source", AccessPoint.SYSTEM_SOURCE); } else { jobPortal.add("source", AccessPoint.USER_SOURCE); } ap.setPortalData(jobPortal.build().toString()); ap.setToolkitData(jobToolkit.build().toString()); AccessPointUtils.saveAccessPoint(ap); break; case AccessPoint.WEBPAGE_TYPE: uri = accessPoint.get("uri").asText(); if (uri.endsWith("concept/topConcepts")) { ap.setType(AccessPoint.SISSVOC_TYPE); jobPortal.add("source", AccessPoint.SYSTEM_SOURCE); jobPortal.add("uri", uri.replaceFirst("/concept/topConcepts$", "")); } else { ap.setType(type); jobPortal.add("uri", uri); } ap.setPortalData(jobPortal.build().toString()); ap.setToolkitData(jobToolkit.build().toString()); AccessPointUtils.saveAccessPoint(ap); break; default: } System.out.println("type is: " + ap.getType()); System.out.println("portal_data: " + ap.getPortalData()); System.out.println("toolkit_data: " + ap.getToolkitData()); } } } }
From source file:au.org.ands.vocabs.toolkit.db.TestJsonParsing.java
/** Main program. * @param args Command-line arguments.//ww w .j a va 2 s . co m */ public static void main(final String[] args) { String jsonString = "[{\"type\": \"HARVEST\",\"provider_type\":" + " \"PoolParty\",\"project_id\":" + " \"1DCE1494-A022-0001-FFBD-12DE19E01FEB\"}," + "{\"type\": \"TRANSFORM\"},{\"type\": \"IMPORT\"}]"; JsonNode root = TaskUtils.jsonStringToTree(jsonString); if (root == null) { System.out.println("Got null."); } else { System.out.println("Got instance of:" + root.getClass().toString()); if (!(root instanceof ArrayNode)) { System.out.println("Didn't get an array."); } else { for (JsonNode node : (ArrayNode) root) { System.out.println("Got element: " + node.toString()); if (!(node instanceof ObjectNode)) { System.out.println("Didn't get an object."); } else { System.out.println("task type: " + node.get("type")); } } } } }
From source file:com.mapr.PurchaseLog.java
public static void main(String[] args) throws IOException { Options opts = new Options(); CmdLineParser parser = new CmdLineParser(opts); try {/*from w w w . ja va 2 s .c om*/ parser.parseArgument(args); } catch (CmdLineException e) { System.err.println("Usage: -count <number>G|M|K [ -users number ] log-file user-profiles"); return; } Joiner withTab = Joiner.on("\t"); // first generate lots of user definitions SchemaSampler users = new SchemaSampler( Resources.asCharSource(Resources.getResource("user-schema.txt"), Charsets.UTF_8).read()); File userFile = File.createTempFile("user", "tsv"); BufferedWriter out = Files.newBufferedWriter(userFile.toPath(), Charsets.UTF_8); for (int i = 0; i < opts.users; i++) { out.write(withTab.join(users.sample())); out.newLine(); } out.close(); // now generate a session for each user Splitter onTabs = Splitter.on("\t"); Splitter onComma = Splitter.on(","); Random gen = new Random(); SchemaSampler intermediate = new SchemaSampler( Resources.asCharSource(Resources.getResource("hit_step.txt"), Charsets.UTF_8).read()); final int COUNTRY = users.getFieldNames().indexOf("country"); final int CAMPAIGN = intermediate.getFieldNames().indexOf("campaign_list"); final int SEARCH_TERMS = intermediate.getFieldNames().indexOf("search_keywords"); Preconditions.checkState(COUNTRY >= 0, "Need country field in user schema"); Preconditions.checkState(CAMPAIGN >= 0, "Need campaign_list field in step schema"); Preconditions.checkState(SEARCH_TERMS >= 0, "Need search_keywords field in step schema"); out = Files.newBufferedWriter(new File(opts.out).toPath(), Charsets.UTF_8); for (String line : Files.readAllLines(userFile.toPath(), Charsets.UTF_8)) { long t = (long) (TimeUnit.MILLISECONDS.convert(30, TimeUnit.DAYS) * gen.nextDouble()); List<String> user = Lists.newArrayList(onTabs.split(line)); // pick session length int n = (int) Math.floor(-30 * Math.log(gen.nextDouble())); for (int i = 0; i < n; i++) { // time on page int dt = (int) Math.floor(-20000 * Math.log(gen.nextDouble())); t += dt; // hit specific values JsonNode step = intermediate.sample(); // check for purchase double p = 0.01; List<String> campaigns = Lists.newArrayList(onComma.split(step.get("campaign_list").asText())); List<String> keywords = Lists.newArrayList(onComma.split(step.get("search_keywords").asText())); if ((user.get(COUNTRY).equals("us") && campaigns.contains("5")) || (user.get(COUNTRY).equals("jp") && campaigns.contains("7")) || keywords.contains("homer") || keywords.contains("simpson")) { p = 0.5; } String events = gen.nextDouble() < p ? "1" : "-"; out.write(Long.toString(t)); out.write("\t"); out.write(line); out.write("\t"); out.write(withTab.join(step)); out.write("\t"); out.write(events); out.write("\n"); } } out.close(); }
From source file:com.ibm.watson.catalyst.corpus.tfidf.ApplyTemplate.java
public static void main(String[] args) { System.out.println("Loading Corpus."); JsonNode root; TermCorpus c;/*from ww w .ja va 2 s . c o m*/ JsonNode documents; try (InputStream in = new FileInputStream(new File("tfidf-health-1.json"))) { root = MAPPER.readTree(in); documents = root.get("documents"); TermCorpusBuilder cb = new TermCorpusBuilder(); cb.setDocumentCombiner(0, 0); cb.setJson(new File("health-corpus.json")); c = cb.build(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); return; } catch (JsonProcessingException e) { // TODO Auto-generated catch block e.printStackTrace(); return; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return; } System.out.println("Corpus loaded."); List<TemplateMatch> matches = new ArrayList<TemplateMatch>(); Iterator<TermDocument> documentIterator = c.getDocuments().iterator(); int index = 0; for (JsonNode document : documents) { Pattern p1 = Template.getTemplatePattern(document, "\\b(an? |the )?(\\w+ ){0,4}", "( \\w+)?(?= is (an?|one|the)\\b)"); if (p1.toString().equals("\\b(an? |the )?(\\w+ ){0,4}()( \\w+)?(?= is (an?|one|the)\\b)")) continue; Pattern p2 = Template.getTemplatePattern(document, "^(\\w+ ){0,2}", "( \\w+){0,1}?(?=( can| may)? causes?\\b)"); Pattern p3 = Template.getTemplatePattern(document, "(?<=the use of )(\\w+ ){0,3}", "( \\w+| ){0,2}?(?=( (and|does|in|for|can|is|as|to|of)\\b|\\.))"); Pattern p4 = Template.getTemplatePattern(document, "^(\\w+ ){0,3}", "( \\w+){0,1}(?=( can| may) leads? to\\b)"); Pattern p5 = Template.getTemplatePattern(document, "(?<=\\bthe risk of )(\\w+ ){0,3}", "( (disease|stroke|attack|cancer))?\\b"); Pattern p6 = Template.getTemplatePattern(document, "(\\w{3,} ){0,3}", "( (disease|stroke|attack|cancer))?(?= is caused by\\b)"); Pattern p7 = Template.getTemplatePattern(document, "(?<= is caused by )(\\w+ ){0,10}", ""); Pattern p8 = Template.getTemplatePattern(document, "\\b", "( \\w{4,})(?= can be used)"); Pattern p9 = Template.getTemplatePattern(document, "(?<= can be used )(\\w+ ){0,10}", "\\b"); TermDocument d = documentIterator.next(); DocumentMatcher dm = new DocumentMatcher(d); matches.addAll(dm.getParagraphMatches(p1, "What is ", "?")); matches.addAll(dm.getParagraphMatches(p2, "What does ", " cause?")); matches.addAll(dm.getParagraphMatches(p3, "How is ", " used?")); matches.addAll(dm.getParagraphMatches(p4, "What can ", " lead to?")); matches.addAll(dm.getParagraphMatches(p5, "What impacts the risk of ", "?")); matches.addAll(dm.getParagraphMatches(p6, "What causes ", "?")); matches.addAll(dm.getParagraphMatches(p7, "What is caused by ", "?")); matches.addAll(dm.getParagraphMatches(p8, "How can ", " be used?")); matches.addAll(dm.getParagraphMatches(p9, "What can be used ", "?")); System.out.print("Progress: " + ((100 * ++index) / documents.size()) + "%\r"); } System.out.println(); List<TemplateMatch> condensedMatches = new ArrayList<TemplateMatch>(); for (TemplateMatch match : matches) { for (TemplateMatch baseMatch : condensedMatches) { if (match.sameQuestion(baseMatch)) { baseMatch.addAnswers(match); break; } } condensedMatches.add(match); } try (BufferedWriter bw = new BufferedWriter(new FileWriter("health-questions.txt"))) { for (TemplateMatch match : condensedMatches) { bw.write(match.toString()); } bw.write("\n"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("Done and generated: " + condensedMatches.size()); }