Example usage for org.apache.commons.io IOUtils readLines

List of usage examples for org.apache.commons.io IOUtils readLines

Introduction

In this page you can find the example usage for org.apache.commons.io IOUtils readLines.

Prototype

public static List readLines(InputStream input, String encoding) throws IOException 

Source Link

Document

Get the contents of an InputStream as a list of Strings, one entry per line, using the specified character encoding.

Usage

From source file:com.opengamma.integration.coppclark.CoppClarkExchangeFileReader.java

/**
 * Creates a populated file reader.//from  w w w  .j a v a 2  s. com
 * <p>
 * The values can be extracted using the methods.
 * 
 * @param exchangeMaster  the exchange master to populate, not null
 * @return the exchange reader, not null
 */
private static CoppClarkExchangeFileReader createPopulated0(ExchangeMaster exchangeMaster) {
    CoppClarkExchangeFileReader fileReader = new CoppClarkExchangeFileReader(exchangeMaster);
    InputStream indexStream = fileReader.getClass().getResourceAsStream(EXCHANGE_INDEX_RESOURCE);
    if (indexStream == null) {
        throw new IllegalArgumentException(
                "Unable to find exchange index resource: " + EXCHANGE_INDEX_RESOURCE);
    }
    try {
        List<String> fileNames = IOUtils.readLines(indexStream, "UTF-8");
        if (fileNames.size() != 1) {
            throw new IllegalArgumentException("Exchange index file should contain one line");
        }
        InputStream dataStream = fileReader.getClass()
                .getResourceAsStream(EXCHANGE_RESOURCE_PACKAGE + fileNames.get(0));
        if (dataStream == null) {
            throw new IllegalArgumentException(
                    "Unable to find exchange data resource: " + EXCHANGE_RESOURCE_PACKAGE + fileNames.get(0));
        }
        try {
            fileReader.readStream(dataStream);
            return fileReader;
        } finally {
            IOUtils.closeQuietly(dataStream);
        }

    } catch (IOException ex) {
        throw new OpenGammaRuntimeException("Unable to read exchange file", ex);
    } finally {
        IOUtils.closeQuietly(indexStream);
    }
}

From source file:com.intuit.karate.cucumber.FeatureWrapper.java

private FeatureWrapper(String text, ScriptEnv scriptEnv) {
    this.text = text;
    this.scriptEnv = scriptEnv;
    this.feature = CucumberUtils.parse(text);
    try {//from   ww w .  ja  v  a2  s  .c o  m
        InputStream is = IOUtils.toInputStream(text, "utf-8");
        this.lines = IOUtils.readLines(is, "utf-8");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    featureSections = new ArrayList<>();
    List<CucumberTagStatement> elements = feature.getFeatureElements();
    int count = elements.size();
    for (int i = 0; i < count; i++) {
        CucumberTagStatement cts = elements.get(i);
        if (cts instanceof CucumberScenario) {
            CucumberScenario sw = (CucumberScenario) cts;
            ScenarioWrapper scenario = new ScenarioWrapper(this, -1, sw, null);
            FeatureSection section = new FeatureSection(i, this, scenario, null);
            featureSections.add(section);
        } else if (cts instanceof CucumberScenarioOutline) {
            CucumberScenarioOutline cso = (CucumberScenarioOutline) cts;
            ScenarioOutlineWrapper scenarioOutline = new ScenarioOutlineWrapper(this, cso);
            FeatureSection section = new FeatureSection(i, this, null, scenarioOutline);
            featureSections.add(section);
        } else {
            throw new RuntimeException("unexpected type: " + cts.getClass());
        }
    }
}

From source file:com.simiacryptus.util.lang.CodeUtil.java

/**
 * Gets javadoc./*from ww  w  .  j  a  v  a 2  s  .c om*/
 *
 * @param clazz the clazz
 * @return the javadoc
 */
public static String getJavadoc(@Nullable final Class<?> clazz) {
    try {
        if (null == clazz)
            return null;
        @Nullable
        final File source = com.simiacryptus.util.lang.CodeUtil.findFile(clazz);
        if (null == source)
            return clazz.getName() + " not found";
        final List<String> lines = IOUtils.readLines(new FileInputStream(source), Charset.forName("UTF-8"));
        final int classDeclarationLine = IntStream.range(0, lines.size())
                .filter(i -> lines.get(i).contains("class " + clazz.getSimpleName())).findFirst().getAsInt();
        final int firstLine = IntStream.rangeClosed(1, classDeclarationLine).map(i -> classDeclarationLine - i)
                .filter(i -> !lines.get(i).matches("\\s*[/\\*@].*")).findFirst().orElse(-1) + 1;
        final String javadoc = lines.subList(firstLine, classDeclarationLine).stream()
                .filter(s -> s.matches("\\s*[/\\*].*")).map(s -> s.replaceFirst("^[ \t]*[/\\*]+", "").trim())
                .filter(x -> !x.isEmpty()).reduce((a, b) -> a + "\n" + b).orElse("");
        return javadoc.replaceAll("<p>", "\n");
    } catch (@javax.annotation.Nonnull final Throwable e) {
        e.printStackTrace();
        return "";
    }
}

From source file:de.tudarmstadt.ukp.dkpro.core.dictionaryannotator.DictionaryAnnotator.java

@Override
public void initialize(UimaContext aContext) throws ResourceInitializationException {
    super.initialize(aContext);

    if (annotationType == null) {
        annotationType = NGram.class.getName();
    }/*from   ww  w . j  av  a 2  s .co  m*/

    phrases = new PhraseTree();

    InputStream is = null;
    try {
        URL phraseFileUrl = ResourceUtils.resolveLocation(phraseFile, aContext);
        is = phraseFileUrl.openStream();
        for (String inputLine : IOUtils.readLines(is, modelEncoding)) {
            String[] phraseSplit = inputLine.split(" ");
            phrases.addPhrase(phraseSplit);
        }
    } catch (IOException e) {
        throw new ResourceInitializationException(e);
    } finally {
        IOUtils.closeQuietly(is);
    }
}

From source file:com.webguys.djinn.marid.util.BuiltinAnnotationProcessor.java

private boolean shouldGenerate() throws IOException {
    boolean result = false;
    UnifiedSet<String> typeStrings = this.elements.transform(ELEMENT_TO_TYPESTRING,
            UnifiedSet.<String>newSet(this.elements.size()));

    if (this.db.exists()) {
        this.builtins = UnifiedSet.<String>newSet(IOUtils.readLines(new FileInputStream(this.db), "UTF-8"));
        if (!this.builtins.containsAll(typeStrings)) {
            this.builtins.addAll(typeStrings);
            result = true;//from  ww  w.  jav  a  2 s  .co m
        }
    } else {
        this.builtins = typeStrings;
        result = true;
    }

    return result;
}

From source file:de.uhh.lt.lefex.Utils.DictionaryAnnotator.java

@Override
public void initialize(UimaContext aContext) throws ResourceInitializationException {
    super.initialize(aContext);

    if (annotationType == null) {
        annotationType = NGram.class.getName();
    }/*from  w w  w .  j  a  v  a 2  s.c o m*/

    phrases = new PhraseTree();

    InputStream is = null;
    try {
        URL phraseFileUrl = ResourceUtils.resolveLocation(phraseFile, aContext);
        is = phraseFileUrl.openStream();
        for (String inputLine : IOUtils.readLines(is, modelEncoding)) {
            String[] phraseSplit;
            if (extendedMatch.toLowerCase().equals("true"))
                phraseSplit = inputLine.toLowerCase().split(" ");
            else
                phraseSplit = inputLine.split(" ");
            phrases.addPhrase(phraseSplit);
        }
    } catch (IOException e) {
        throw new ResourceInitializationException(e);
    } finally {
        IOUtils.closeQuietly(is);
    }
}

From source file:jenkins.security.stapler.StaticRoutingDecisionProvider.java

private synchronized void reloadFromDefault() {
    try (InputStream is = StaticRoutingDecisionProvider.class.getResourceAsStream("default-whitelist.txt")) {
        whitelistSignaturesFromFixedList = new HashSet<>();
        blacklistSignaturesFromFixedList = new HashSet<>();

        parseFileIntoList(IOUtils.readLines(is, StandardCharsets.UTF_8), whitelistSignaturesFromFixedList,
                blacklistSignaturesFromFixedList);
    } catch (IOException e) {
        throw new ExceptionInInitializerError(e);
    }//from  w w w  . ja v  a2 s  .co  m

    LOGGER.log(Level.FINE, "Found {0} getter in the standard whitelist",
            whitelistSignaturesFromFixedList.size());
}

From source file:net.birelian.xmltoyaml.Main.java

/**
 * Get change log files from the classpath
 *
 * @return Files from the file system/*  ww w.  j a  va2 s . c  o  m*/
 *
 * @throws ApplicationException If any
 */
private List<String> getFileListFromClasspath() throws ApplicationException {

    if (Main.class.getClassLoader().getResourceAsStream(SOURCE_DIR) != null) {

        try {
            return IOUtils.readLines(Main.class.getClassLoader().getResourceAsStream(SOURCE_DIR),
                    Charsets.UTF_8);

        } catch (IOException e) {
            throw new ApplicationException("Unable to get files from the classpath", e);
        }
    }

    return null;
}

From source file:com.opengamma.component.ComponentConfigLoader.java

/**
 * Reads lines from the resource./* ww  w .  j a va2  s  .  c o m*/
 * 
 * @param resource  the resource to read, not null
 * @return the lines, not null
 */
private List<String> readLines(Resource resource) {
    try {
        return IOUtils.readLines(resource.getInputStream(), "UTF8");
    } catch (IOException ex) {
        throw new OpenGammaRuntimeException("Unable to read resource: " + resource, ex);
    }
}

From source file:com.arvato.thoroughly.util.CommonUtils.java

/**
 * @param ins/*from  w w  w. j  a  v a  2 s.com*/
 * @return String
 */
public static String readFile(InputStream ins) {
    List<String> list;
    StringBuffer sb = new StringBuffer();
    try {
        list = IOUtils.readLines(ins, "UTF-8");
        Iterator<String> iter = list.iterator();
        while (iter.hasNext()) {
            sb.append(iter.next());
        }
    } catch (IOException e) {
        LOGGER.error("Exception while reading file " + e.getMessage(), e);
    }
    return sb.toString();
}