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:io.fabric8.vertx.maven.plugin.utils.ServiceCombinerUtil.java

private Map<String, List<Set<String>>> findSPIsFromDependencies(List<JavaArchive> jars) {
    Map<String, List<Set<String>>> map = new HashMap<>();

    ArchivePath spiPath = ArchivePaths.create("META-INF/services");

    Set<JavaArchive> serviceProviderArchives = jars.stream().filter(a -> a.contains(spiPath))
            .collect(Collectors.toSet());

    for (JavaArchive archive : serviceProviderArchives) {
        Node node = archive.get(spiPath);
        Set<Node> children = node.getChildren();
        for (Node child : children) {
            String name = child.getPath().get().substring(spiPath.get().length() + 1);
            try {
                List<String> lines = IOUtils.readLines(child.getAsset().openStream(), "UTF-8");
                List<Set<String>> items = map.get(name);
                if (items == null) {
                    items = new ArrayList<>();
                }/* w  w  w. jav  a2s . c o m*/
                items.add(new LinkedHashSet<>(lines));
                map.put(name, items);
            } catch (IOException e) {
                throw new RuntimeException("Cannot read  " + node.getPath().get(), e);
            }
        }
    }

    return map;
}

From source file:com.seleniumtests.browserfactory.BrowserInfo.java

/**
 * SeleniumRobot uses external jar files to hold drivers (seleniumRobot-windows-driver, seleniumRobot-linux-driver,seleniumRobot-mac-driver)
 * Each one also contains a file (driver-list-<windows/linux/mac>.txt) which references all driver files in the jar.
 * This method returns the content of this text file
 * @return/*from   ww  w.  ja v a  2s . c  o m*/
 * @throws IOException 
 */
public String[] getDriverListFromJarResources(String driverListFileName) throws IOException {
    return IOUtils.readLines(BrowserInfo.class.getClassLoader().getResourceAsStream(driverListFileName),
            Charset.forName("UTF-8")).get(0).split(",");
}

From source file:com.adaptris.core.marshaller.xstream.XStreamUtils.java

/**
 * Reads in the entire file contents skipping any blank lines.
 * //from  w  ww  .  j  a  v  a  2 s  .  c o m
 * @param in - InputStream to read
 * @return List<String> List of lines.
 * @throws IOException
 */
public static List<String> readResource(InputStream in) throws IOException {
    List<String> result = new ArrayList<String>();
    try (InputStream closeable = in) {
        result = IOUtils.readLines(closeable, Charset.defaultCharset());
        // Well, is this more or less readable the other it's not even as
        // though the predicate style actually returns a new list.
        // result.removeIf(StringUtils::isBlank);
        result.removeAll(Arrays.asList("", null));
    }
    return result;
}

From source file:net.birelian.liquibase.converter.mojo.XmlToYamlConverterMojo.java

/**
 * Get change log files from the classpath
 *
 * @return Files from the file system//from  w  ww .ja v  a2s  .co m
 * @throws ApplicationException If any
 */
private List<String> getFileListFromClasspath() throws ApplicationException {

    getLog().info("Trying to get files from the classpath");

    if (XmlToYamlConverterMojo.class.getClassLoader().getResourceAsStream(sourceDir) != null) {

        try {
            return IOUtils.readLines(
                    XmlToYamlConverterMojo.class.getClassLoader().getResourceAsStream(sourceDir),
                    Charsets.UTF_8);

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

    return null;
}

From source file:com.quinsoft.zeidon.standardoe.ApplicationImpl.java

@Override
public List<String> getLodNameList(Task task) {
    ClassLoader loader = this.getClass().getClassLoader();
    final String resourceDir = getObjectDir() + "/";

    Pattern pattern = Pattern.compile("(.*)(\\.xod$)", Pattern.CASE_INSENSITIVE);
    try {/*from  w  ww.j  ava2  s . c  o m*/
        return (List<String>) IOUtils.readLines(loader.getResourceAsStream(resourceDir), StandardCharsets.UTF_8)
                .stream().map(resourceName -> pattern.matcher(resourceName)) // Create a matcher
                .filter(matcher -> matcher.matches()) // Keep only ones that match.
                .map(matcher -> matcher.group(1)) // Get the base filename.
                .collect(Collectors.toList());
    } catch (IOException e) {
        throw ZeidonException.wrapException(e).appendMessage("XOD resource dir: %s", resourceDir);
    }

}

From source file:com.mmounirou.spotirss.SpotiRss.java

private static Iterable<String> getCharts(String strProvider) throws IOException {
    InputStream chartsStreams = SpotiRss.class.getResourceAsStream("/" + strProvider + ".charts");
    try {//from  w w  w  .  ja  va 2 s .co m
        List<String> readLines = IOUtils.readLines(chartsStreams, Charsets.UTF_8);
        return Iterables.filter(readLines, new Predicate<String>() {

            @Override
            public boolean apply(@Nullable String input) {
                return !StringUtils.startsWith(input, "#");
            }
        });

    } finally {
        IOUtils.closeQuietly(chartsStreams);
    }
}

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

/**
 * Creates a populated file reader.//  ww w . ja  v  a  2 s  .c  o m
 * <p>
 * The values can be extracted using the methods.
 * 
 * @param holidayMaster  the holiday master to populate, not null
 * @return the holiday reader, not null
 */
private static CoppClarkHolidayFileReader createPopulated0(HolidayMaster holidayMaster) {
    CoppClarkHolidayFileReader fileReader = new CoppClarkHolidayFileReader(holidayMaster);
    InputStream indexStream = fileReader.getClass().getResourceAsStream(HOLIDAY_INDEX_RESOURCE);
    if (indexStream == null) {
        throw new IllegalArgumentException("Unable to find holiday index resource: " + HOLIDAY_INDEX_RESOURCE);
    }
    try {
        List<String> suffixes = IOUtils.readLines(indexStream, "UTF-8");
        for (String suffix : suffixes) {
            if (StringUtils.isNotEmpty(suffix)) {
                String prefix = "";
                if (suffix.startsWith("U")) {
                    prefix = "Update_";
                    suffix = suffix.substring(1);
                }
                prefix = HOLIDAY_RESOURCE_PACKAGE + prefix;
                suffix += ".csv";
                InputStream currencyStream = fileReader.getClass()
                        .getResourceAsStream(prefix + "Currencies_" + suffix);
                if (currencyStream == null) {
                    throw new IllegalArgumentException(
                            "Unable to find holiday data resource: " + prefix + "Currencies_" + suffix);
                }
                fileReader.getCurrencyStreams().add(currencyStream);

                InputStream financialCentersStream = fileReader.getClass()
                        .getResourceAsStream(prefix + "FinancialCentres_" + suffix);
                if (financialCentersStream == null) {
                    throw new IllegalArgumentException(
                            "Unable to find holiday data resource: " + prefix + "FinancialCentres_" + suffix);
                }
                fileReader.getFinancialCentresStreams().add(financialCentersStream);

                InputStream exchangeSettlementStream = fileReader.getClass()
                        .getResourceAsStream(prefix + "ExchangeSettlement_" + suffix);
                if (exchangeSettlementStream == null) {
                    throw new IllegalArgumentException(
                            "Unable to find holiday data resource: " + prefix + "ExchangeSettlement_" + suffix);
                }
                fileReader.getExchangeSettlementStreams().add(exchangeSettlementStream);

                InputStream exchangeTradingStream = fileReader.getClass()
                        .getResourceAsStream(prefix + "ExchangeTrading_" + suffix);
                if (exchangeTradingStream == null) {
                    throw new IllegalArgumentException(
                            "Unable to find holiday data resource: " + prefix + "ExchangeTrading_" + suffix);
                }
                fileReader.getExchangeTradingStreams().add(exchangeTradingStream);
            }
        }
        try {
            fileReader.read();
            return fileReader;
        } finally {
            fileReader.close();
        }

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

From source file:bixo.operations.UrlLengthener.java

public static Set<String> loadUrlShorteners() throws IOException {
    Set<String> result = new HashSet<String>();
    List<String> lines = IOUtils.readLines(UrlLengthener.class.getResourceAsStream("/url-shorteners.txt"),
            "UTF-8");
    for (String line : lines) {
        line = line.trim();/*from   w  w  w  .ja  v  a2  s.c  o m*/
        if ((line.length() == 0) || (line.startsWith("#"))) {
            continue;
        }

        int commentIndex = line.indexOf('#');
        if (commentIndex != -1) {
            line = line.substring(0, commentIndex).trim();
        }

        result.add(line);
    }

    return result;
}

From source file:com.github.stagirs.lingvo.build.Xml2Plain.java

private static List<String> extract(File file) throws IOException {
    ZipInputStream zis = new ZipInputStream(new FileInputStream(file));
    try {/*w  w  w.  j av  a2 s  . c o  m*/
        ZipEntry ze = zis.getNextEntry();
        if (ze == null) {
            throw new RuntimeException("can't unzip file");
        }
        return IOUtils.readLines(zis, Charset.forName("utf-8"));
    } finally {
        zis.close();
    }
}

From source file:com.junoyoon.SourcePainter.java

/**
 * paint source code with decision point
 **///from   www  . j  a  v  a  2s .co  m
public String paint(File file, List<SrcDecisionPoint> decisionPoints, Encoding encoding) throws IOException {
    InputStream inputStream = new FileInputStream(file);
    PeekingIterator<SrcDecisionPoint> peekingIterator = BullsUtil.peekingIterator(decisionPoints.iterator());
    StringBuffer sb = this.renderer.highlight(IOUtils.readLines(inputStream, encoding.getEncodingKey()),
            peekingIterator);
    IOUtils.closeQuietly(inputStream);
    return sb.toString();
}