Example usage for com.google.common.io CharSource wrap

List of usage examples for com.google.common.io CharSource wrap

Introduction

In this page you can find the example usage for com.google.common.io CharSource wrap.

Prototype

public static CharSource wrap(CharSequence charSequence) 

Source Link

Document

Returns a view of the given character sequence as a CharSource .

Usage

From source file:com.google.javascript.jscomp.deps.TranspilingClosureBundler.java

@Override
public void appendTo(Appendable out, DependencyInfo info, CharSource content) throws IOException {
    if (needToBundleEs6Runtime) {
        // Piggyback on the first call to transformInput to include the ES6 runtime as well.
        super.appendTo(out, SimpleDependencyInfo.EMPTY, CharSource.wrap(es6Runtime));
        needToBundleEs6Runtime = false;
    }//from www.ja  v a  2  s.  c o  m
    super.appendTo(out, info, content);
}

From source file:org.lenskit.data.dao.file.TextEntitySource.java

/**
 * Set a string from which to read entities.
 */
public void setSource(CharSequence text) {
    source = CharSource.wrap(text);
    sourceURL = null;
}

From source file:com.opengamma.strata.collect.io.CharSources.java

/**
 * Obtains an instance of {@link CharSource} from a text variable, specified as a {@link String} object.
 *
 * @param content  the text to create a {@link CharSource} for
 * @return  a new instance of {@link CharSource} with UTF-8 for charset
 *//*  www  . j  a  v  a2  s  .  co  m*/
public static CharSource ofContent(String content) {
    return CharSource.wrap(content);
}

From source file:org.onosproject.drivers.odtn.InfineraOpenConfigDeviceDiscovery.java

private List<PortDescription> discoverPorts() throws ConfigurationException, IOException {
    DeviceId did = data().deviceId();//from   ww w . j  ava  2 s.c o m
    NetconfSession ns = Optional.ofNullable(handler().get(NetconfController.class))
            .map(c -> c.getNetconfDevice(did)).map(NetconfDevice::getSession)
            .orElseThrow(() -> new IllegalStateException("No NetconfSession found for " + did));

    // TODO convert this method into non-blocking form?

    String reply = ns.asyncGet().join().toString();

    // workaround until asyncGet().join() start failing exceptionally
    String data = null;
    if (reply.startsWith("<data")) {
        data = reply;
    }

    if (data == null) {
        log.error("No valid response found from {}:\n{}", did, reply);
        return ImmutableList.of();
    }

    XMLConfiguration cfg = new XMLConfiguration();
    cfg.load(CharSource.wrap(data).openStream());

    return discoverPorts(cfg);
}

From source file:com.facebook.buck.util.string.MoreStrings.java

public static ImmutableList<String> lines(String data) throws IOException {
    return CharSource.wrap(data).readLines();
}

From source file:com.opengamma.strata.collect.io.CharSources.java

/**
 * Obtains an instance of {@link CharSource} from a text variable, specified as a byte array.
 * /* ww w  .j  a v a  2s  .c o  m*/
 * @param content  the text to create a {@link CharSource} for
 * @return  a new instance of {@link CharSource} with UTF-8 for charset
 */
public static CharSource ofContent(byte[] content) {
    return CharSource.wrap(new String(content, Charsets.UTF_8));
}

From source file:org.locationtech.geogig.cli.test.functional.general.GlobalState.java

public static List<String> runAndParseCommand(boolean failFast, String... command) throws Exception {
    runCommand(failFast, command);//from  www  .j a  v  a2s.c  om
    CharSource reader = CharSource.wrap(stdOut.toString(Charsets.UTF_8.name()));
    ImmutableList<String> lines = reader.readLines();
    return lines;
}

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();/*from  www. ja va 2 s.  c  om*/
        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.locationtech.geogig.cli.test.functional.CLIContext.java

public List<String> runAndParseCommand(boolean failFast, String... command) throws Exception {
    runCommand(failFast, command);/*from w ww. j  a v  a 2  s .  com*/
    CharSource reader = CharSource.wrap(stdOut.toString(Charsets.UTF_8.name()));
    ImmutableList<String> lines = reader.readLines();
    return lines;
}

From source file:com.opengamma.strata.collect.io.CharSources.java

/**
 * Obtains an instance of {@link CharSource} from a text variable, specified as a byte array.
 * This also takes in a specific character set, as a {@link Charset}.
 * //w w  w .ja  v a 2  s  .  c  om
 * @param content  the text to create a {@link CharSource} for
 * @param charset  the charset to build the new CharSource based on
 * @return  a new instance of {@link CharSource}
 */
public static CharSource ofContent(byte[] content, Charset charset) {
    return CharSource.wrap(new String(content, charset));
}