List of usage examples for com.google.common.io CharSource concat
public static CharSource concat(CharSource... sources)
From source file:org.glowroot.local.ui.TraceExportHttpService.java
private static CharSource render(TraceExport traceExport) throws IOException { String htmlStartTag = "<html>"; String exportCssPlaceholder = "<link rel=\"stylesheet\" href=\"styles/export.css\">"; String exportJsPlaceholder = "<script src=\"scripts/export.js\"></script>"; String tracePlaceholder = "<script type=\"text/json\" id=\"traceJson\"></script>"; String entriesPlaceholder = "<script type=\"text/json\" id=\"entriesJson\"></script>"; String profilePlaceholder = "<script type=\"text/json\" id=\"profileJson\"></script>"; String templateContent = asCharSource("trace-export.html").read(); Pattern pattern = Pattern .compile("(" + htmlStartTag + "|" + exportCssPlaceholder + "|" + exportJsPlaceholder + "|" + tracePlaceholder + "|" + entriesPlaceholder + "|" + profilePlaceholder + ")"); Matcher matcher = pattern.matcher(templateContent); int curr = 0; List<CharSource> charSources = Lists.newArrayList(); while (matcher.find()) { charSources.add(CharSource.wrap(templateContent.substring(curr, matcher.start()))); curr = matcher.end();//w w w .j a va 2 s. c o m String match = matcher.group(); if (match.equals(htmlStartTag)) { // Need to add "Mark of the Web" for IE, otherwise IE won't run javascript // see http://msdn.microsoft.com/en-us/library/ms537628(v=vs.85).aspx charSources.add(CharSource.wrap("<!-- saved from url=(0014)about:internet -->\r\n<html>")); } else if (match.equals(exportCssPlaceholder)) { charSources.add(CharSource.wrap("<style>")); charSources.add(asCharSource("styles/export.css")); charSources.add(CharSource.wrap("</style>")); } else if (match.equals(exportJsPlaceholder)) { charSources.add(CharSource.wrap("<script>")); charSources.add(asCharSource("scripts/export.js")); charSources.add(CharSource.wrap("</script>")); } else if (match.equals(tracePlaceholder)) { charSources.add(CharSource.wrap("<script type=\"text/json\" id=\"traceJson\">")); charSources.add(CharSource.wrap(traceExport.traceJson())); charSources.add(CharSource.wrap("</script>")); } else if (match.equals(entriesPlaceholder)) { charSources.add(CharSource.wrap("<script type=\"text/json\" id=\"entriesJson\">")); CharSource entries = traceExport.entries(); if (entries != null) { charSources.add(entries); } charSources.add(CharSource.wrap("</script>")); } else if (match.equals(profilePlaceholder)) { charSources.add(CharSource.wrap("<script type=\"text/json\" id=\"profileJson\">")); CharSource profile = traceExport.profile(); if (profile != null) { charSources.add(profile); } charSources.add(CharSource.wrap("</script>")); } else { logger.error("unexpected match: {}", match); } } charSources.add(CharSource.wrap(templateContent.substring(curr))); return CharSource.concat(charSources); }
From source file:org.apache.aurora.common.args.apt.Configuration.java
private static Configuration load(int nextIndex, List<URL> configs) throws ConfigurationException, IOException { CharSource input = CharSource.concat(Iterables.transform(configs, URL_TO_SOURCE)); try (Reader reader = input.openStream()) { return CharStreams.readLines(reader, new ConfigurationParser(nextIndex)); }//w w w . jav a 2s . c o m }