Example usage for com.google.common.io Resources readLines

List of usage examples for com.google.common.io Resources readLines

Introduction

In this page you can find the example usage for com.google.common.io Resources readLines.

Prototype

public static List<String> readLines(URL url, Charset charset) throws IOException 

Source Link

Document

Reads all of the lines from a URL.

Usage

From source file:io.hops.hopsworks.common.util.IoUtils.java

public static List<String> readLinesFromWeb(String url) throws IOException {
    URL fileUrl = new URL(url);
    return Resources.readLines(fileUrl, Charsets.UTF_8);
}

From source file:app.QuickStartApplication.java

private static String readLines(final String resourceName) {
    try {/*w w w. j a  v a2 s  .  co  m*/
        List<String> readLines = Resources.readLines(Resources.getResource(QuickStartApplication.class, resourceName), Charset.defaultCharset());
        final String aboutText = Joiner.on("${symbol_escape}n").join(readLines);
        return aboutText;
    } catch (IOException e) {
        return "This is Quick Start";
    }
}

From source file:domainapp.webapp.DomainApplication.java

private static String readLines(final Class<?> contextClass, final String resourceName) {
    try {//from   w  w w  .j  ava 2s.c  o  m
        List<String> readLines = Resources.readLines(Resources.getResource(contextClass, resourceName),
                Charset.defaultCharset());
        final String aboutText = Joiner.on("\n").join(readLines);
        return aboutText;
    } catch (IOException e) {
        return "This is a simple app";
    }
}

From source file:edu.cmu.lti.oaqa.baseqa.answer.score.scorers.ConceptProximityAnswerScorer.java

@Override
public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams)
        throws ResourceInitializationException {
    boolean ret = super.initialize(aSpecifier, aAdditionalParams);
    String stoplistFile = (String) getParameterValue("stoplist");
    try {/*ww  w.ja v a 2s.c  o  m*/
        stoplist = Resources.readLines(getClass().getResource(stoplistFile), Charsets.UTF_8).stream()
                .collect(toSet());
    } catch (IOException e) {
        throw new ResourceInitializationException(e);
    }
    windowSize = (int) getParameterValue("window-size");
    infinity = (double) getParameterValue("infinity");
    smoothing = (double) getParameterValue("smoothing");
    return ret;
}

From source file:com.madvay.tools.android.perf.apat.Main.java

private static void printVersion() {
    outln(String.format("apat Version %s\n  Built at %s\n  On commit %s\n  Url: %s", BuildInfo.VERSION,
            BuildInfo.TIMESTAMP, BuildInfo.GIT_COMMIT, BuildInfo.URL));
    if (BuildInfo.VERSION.contains("SNAPSHOT")) {
        outln("*** Note: This is an unofficial snapshot release.");
        outln("*** See https://madvay.com/source/apat for official releases.");
    }/*  w ww .j a  va2  s.co m*/
    if (!BuildInfo.GIT_IS_CLEAN) {
        outln("!!! Warning: This unofficial build was made with local modifications.");
        outln("!!! See https://madvay.com/source/apat for official releases.");
    }
    outln("---------------------------------------------------------------");
    try {
        List<String> lines = Resources.readLines(Resources.getResource("NOTICE"), Charsets.UTF_8);
        for (String l : lines) {
            outln(l);
        }
    } catch (IOException err) {
        err(err);
    }
}

From source file:edu.cmu.lti.oaqa.baseqa.abstract_query.TokenConceptAbstractQueryGenerator.java

@Override
public void initialize(UimaContext context) throws ResourceInitializationException {
    super.initialize(context);
    useType = UimaContextHelper.getConfigParameterBooleanValue(context, "use-type", false);
    useWeight = UimaContextHelper.getConfigParameterBooleanValue(context, "use-weight", false);
    // get pos tags
    String posTagsPath = UimaContextHelper.getConfigParameterStringValue(context, "pos-tags-path", null);
    if (posTagsPath != null) {
        try {/*from w w  w . ja va 2  s  .c o  m*/
            posTags = Resources.readLines(getClass().getResource(posTagsPath), UTF_8).stream().map(String::trim)
                    .collect(toSet());
        } catch (IOException e) {
            throw new ResourceInitializationException(e);
        }
    }
    // get noun tags
    String nounTagsPath = UimaContextHelper.getConfigParameterStringValue(context, "noun-tags-path", null);
    if (nounTagsPath != null) {
        try {
            nounTags = Resources.readLines(getClass().getResource(nounTagsPath), UTF_8).stream()
                    .map(String::trim).collect(toSet());
        } catch (IOException e) {
            throw new ResourceInitializationException(e);
        }
    }
    // get stop word list
    String stoplistPath = UimaContextHelper.getConfigParameterStringValue(context, "stoplist-path", null);
    if (stoplistPath != null) {
        try {
            stoplist = Resources.readLines(getClass().getResource(stoplistPath), UTF_8).stream()
                    .map(String::trim).collect(toSet());
        } catch (IOException e) {
            throw new ResourceInitializationException(e);
        }
    }
}

From source file:edu.cmu.lti.oaqa.baseqa.answer_type.GSAnswerTypeLabeler.java

@Override
public void initialize(UimaContext context) throws ResourceInitializationException {
    super.initialize(context);
    String quantityQuestionWordsPath = UimaContextHelper.getConfigParameterStringValue(context,
            "quantity-question-words-path");
    try {/*w w  w  .java 2s .  com*/
        quantityQuestionPhrases = Resources
                .readLines(getClass().getResource(quantityQuestionWordsPath), Charsets.UTF_8).stream()
                .map(line -> Arrays.asList(line.split(" "))).collect(toList());
    } catch (IOException e) {
        throw new ResourceInitializationException(e);
    }
    atGslabelFile = UimaContextHelper.getConfigParameterStringValue(context, "at-gslabel-file");
    batchSize = UimaContextHelper.getConfigParameterIntValue(context, "batch-size", 1);
    completeQats = new ArrayList<>();
    pendingQats = new ArrayList<>();
}

From source file:org.opendaylight.controller.config.manager.impl.osgi.mapping.ModuleInfoBundleTracker.java

@Override
public Collection<ObjectRegistration<YangModuleInfo>> addingBundle(Bundle bundle, BundleEvent event) {
    URL resource = bundle.getEntry(MODULE_INFO_PROVIDER_PATH_PREFIX + YangModelBindingProvider.class.getName());
    LOG.debug("Got addingBundle({}) with YangModelBindingProvider resource {}", bundle, resource);
    if (resource == null) {
        return null;
    }/*from ww  w.j a  v a  2  s . c  o  m*/
    List<ObjectRegistration<YangModuleInfo>> registrations = new LinkedList<>();

    try {
        for (String moduleInfoName : Resources.readLines(resource, StandardCharsets.UTF_8)) {
            LOG.trace("Retrieve ModuleInfo({}, {})", moduleInfoName, bundle);
            YangModuleInfo moduleInfo = retrieveModuleInfo(moduleInfoName, bundle);
            registrations.add(moduleInfoRegistry.registerModuleInfo(moduleInfo));
        }

        if (!starting) {
            moduleInfoRegistry.updateService();
        }
    } catch (IOException e) {
        LOG.error("Error while reading {} from bundle {}", resource, bundle, e);
    } catch (RuntimeException e) {
        LOG.error("Failed to process {} for bundle {}", resource, bundle, e);
    }

    LOG.trace("Got following registrations {}", registrations);
    return registrations;
}

From source file:edu.cmu.lti.oaqa.baseqa.answer.generate.generators.CavCoveringConceptCavGenerator.java

@Override
public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams)
        throws ResourceInitializationException {
    boolean ret = super.initialize(aSpecifier, aAdditionalParams);
    String stoplistFile = (String) getParameterValue("stoplist");
    try {// ww w. ja v a 2s. c om
        stoplist = Resources.readLines(getClass().getResource(stoplistFile), Charsets.UTF_8).stream()
                .collect(toSet());
        checkStoplist = true;
    } catch (Exception e) {
        checkStoplist = false;
    }
    filterQuestionTokens = (Boolean) getParameterValue("filter-question-tokens");
    filterQuestionConcepts = (Boolean) getParameterValue("filter-question-concepts");
    return ret;
}

From source file:edu.cmu.lti.oaqa.baseqa.evidence.concept.PassageConceptRecognizer.java

@Override
public void initialize(UimaContext context) throws ResourceInitializationException {
    super.initialize(context);
    String conceptProviderName = UimaContextHelper.getConfigParameterStringValue(context, "concept-provider");
    conceptProvider = ProviderCache.getProvider(conceptProviderName, ConceptProvider.class);
    viewNamePrefix = UimaContextHelper.getConfigParameterStringValue(context, "view-name-prefix");
    String allowedConceptTypesFile = UimaContextHelper.getConfigParameterStringValue(context,
            "allowed-concept-types", null);
    try {/*from w w w .ja  va 2 s . c  o m*/
        allowedConceptTypes = Resources
                .readLines(getClass().getResource(allowedConceptTypesFile), Charsets.UTF_8).stream()
                .collect(toSet());
        checkConceptTypes = true;
    } catch (Exception e) {
        checkConceptTypes = false;
    }
}