List of usage examples for org.apache.commons.io IOUtils readLines
public static List readLines(Reader input) throws IOException
Reader
as a list of Strings, one entry per line. From source file:com.lithium.flow.matcher.StringMatchers.java
@Nonnull public static StringMatcher fromInputStream(@Nonnull InputStream in) { try (InputStream tryIn = checkNotNull(in)) { return fromList( IOUtils.readLines(tryIn).stream().filter(line -> !line.startsWith("#")).collect(toList())); } catch (IOException e) { throw new RuntimeException(e); }//from w w w . j ava 2 s .c o m }
From source file:de.shadowhunt.sonar.plugins.ignorecode.model.CoveragePattern.java
/** * Create a list of {@link CoveragePattern} from the given {@link java.io.InputStream} * * @param input containing one {@link CoveragePattern} per line (for a description of the * line format see {@link #parseLine(String)}. Empty lines or comments (lines starting * with '#') are ignored/*w ww . j av a2 s . c o m*/ * * @return the list of {@link CoveragePattern} from the given {@link java.io.InputStream} * * @throws java.io.IOException in case the {@link java.io.InputStream} can not be read */ public static List<CoveragePattern> parse(final InputStream input) throws IOException { final List<CoveragePattern> patterns = new ArrayList<>(); for (final String line : IOUtils.readLines(input)) { if (StringUtils.isBlank(line) || (line.charAt(0) == '#')) { continue; } final CoveragePattern pattern = parseLine(line); patterns.add(pattern); } return patterns; }
From source file:com.buddycloud.channeldirectory.commons.db.CreateSchema.java
private static void runScript(ChannelDirectoryDataSource channelDirectoryDataSource, String sqlFile) throws IOException, FileNotFoundException, SQLException { List<String> readLines = IOUtils.readLines(new FileInputStream(sqlFile)); Connection connection = channelDirectoryDataSource.getConnection(); StringBuilder statementStr = new StringBuilder(); for (String line : readLines) { statementStr.append(line);/*w w w. j av a 2 s . c om*/ if (line.endsWith(SQL_DELIMITER)) { Statement statement = connection.createStatement(); statement.execute(statementStr.toString()); statement.close(); statementStr.setLength(0); } } connection.close(); }
From source file:com.tek271.reverseProxy.utils.FileTools.java
public static List<String> readLinesFromContext(String fileName) { InputStream is = readFromContextToInputStream(fileName); try {//from www .j av a 2s . c o m return IOUtils.readLines(is); } catch (IOException e) { throw new IllegalArgumentException("Cannot read file: " + fileName, e); } }
From source file:de.shadowhunt.sonar.plugins.ignorecode.model.IssuePattern.java
/** * Create a list of {@link IssuePattern} from the given {@link InputStream} * * @param input containing one {@link IssuePattern} per line (for a description of the * line format see {@link #parseLine(String)}. Empty lines or comments (lines starting * with '#') are ignored//from w w w .ja v a 2 s. c o m * * @return the list of {@link IssuePattern} from the given {@link InputStream} * * @throws IOException in case the {@link InputStream} can not be read */ public static List<IssuePattern> parse(final InputStream input) throws IOException { final List<IssuePattern> patterns = new ArrayList<>(); for (final String line : IOUtils.readLines(input)) { if (StringUtils.isBlank(line) || (line.charAt(0) == '#')) { continue; } final IssuePattern pattern = parseLine(line); patterns.add(pattern); } return patterns; }
From source file:com.xpn.xwiki.doc.merge.MergeUtils.java
/** * Merge a String.//from ww w. ja va 2s . co m * * @param previousStr previous version of the string * @param newStr new version of the string * @param currentStr current version of the string * @param mergeResult the merge report * @return the merged string */ // TODO: add support for line merge public static String mergeString(String previousStr, String newStr, String currentStr, MergeResult mergeResult) { String result = currentStr; try { Patch patch = DiffUtils.diff(IOUtils.readLines(new StringReader(previousStr)), IOUtils.readLines(new StringReader(newStr))); if (patch.getDeltas().size() > 0) { result = StringUtils.join(patch.applyTo(IOUtils.readLines(new StringReader(currentStr))), '\n'); mergeResult.setModified(true); } } catch (Exception e) { mergeResult.getErrors().add(e); } return result; }
From source file:com.trigonic.jrobotx.util.DefaultURLInputStreamFactoryTest.java
@Test public void test() throws IOException { URL testUrl = getClass().getResource("test.txt"); List<String> lines = (List<String>) IOUtils .readLines(new DefaultURLInputStreamFactory().openStream(testUrl)); assertEquals(1, lines.size());//from w w w . j a v a 2 s. co m assertEquals("This is a test.", lines.get(0)); }
From source file:de.rallye.test.helper.HttpClient.java
public static HttpResponse apiCall(String url, int expectedStatusCode) throws IOException { HttpGet httpget = new HttpGet("http://localhost:10111/" + url); HttpResponse r = httpclient.execute(httpget); int statusCode = r.getStatusLine().getStatusCode(); if (expectedStatusCode != statusCode) { System.err.println("Got unexpected status code: " + statusCode); // Let's see if it's printable boolean printable = true; Header[] ct = r.getHeaders("Content-Type"); if (ct.length > 0) { String type = ct[0].getValue(); printable = (type.startsWith("text/") || type.startsWith("application/")); }/*from w ww . jav a2 s . c o m*/ if (printable) { System.err.println("This is the content:"); List<String> contents = IOUtils.readLines(r.getEntity().getContent()); for (String line : contents) System.err.println(line); } assertEquals("StatusCode should match expected", expectedStatusCode, statusCode); } return r; }
From source file:net.sf.nutchcontentexporter.filter.CreativeCommonsCandidateFilter.java
@Override public boolean acceptContent(WARCRecordInfo recordInfo) { ByteArrayInputStream contentStream = (ByteArrayInputStream) recordInfo.getContentStream(); try {//from www . j av a 2s .co m List<String> lines = IOUtils.readLines(contentStream); contentStream.reset(); for (String line : lines) { if (line.contains("creativecommons")) { return true; } } } catch (IOException e) { throw new RuntimeException(e); } return false; }
From source file:com.alibaba.otter.shared.common.utils.JavaSourceCompilerTest.java
@Test public void testSimple() { String javasource = null;/* w ww . ja va 2s . c o m*/ try { List<String> lines = IOUtils .readLines(Thread.currentThread().getContextClassLoader().getResourceAsStream("compiler.txt")); javasource = StringUtils.join(lines, "\n"); } catch (IOException e1) { e1.printStackTrace(); } JdkCompiler compiler = new JdkCompiler(); Class<?> clazz = compiler.compile(javasource); System.out.println(clazz.getName()); }