private Void readData(final StringInputRowParser parser, final CharSource source) throws IOException return source.readLines( new LineProcessor<Void>()
/** Returns a copy of code as a list of lines. */ public List<String> getLines() { try { return CharSource.wrap(sourceBuilder).readLines(); } catch (IOException e) { throw new AssertionError("IOException not possible, as the string is in-memory"); } }
.readLines( new LineProcessor<List<String>>() { final List<String> result = Lists.newArrayList();
/** * Streams lines from a {@link File}, stopping when our callback returns false, or we have read * all of the lines. * * @param file the file to read from * @param charset the charset used to decode the input stream; see {@link StandardCharsets} for * helpful predefined constants * @param callback the {@link LineProcessor} to use to handle the lines * @return the output of processing the lines * @throws IOException if an I/O error occurs * @deprecated Prefer {@code asCharSource(file, charset).readLines(callback)}. This method is * scheduled to be removed in January 2019. */ @Deprecated @CanIgnoreReturnValue // some processors won't return a useful result public static <T> T readLines(File file, Charset charset, LineProcessor<T> callback) throws IOException { return asCharSource(file, charset).readLines(callback); }
/** * Streams lines from a URL, stopping when our callback returns false, or we have read all of the * lines. * * @param url the URL to read from * @param charset the charset used to decode the input stream; see {@link Charsets} for helpful * predefined constants * @param callback the LineProcessor to use to handle the lines * @return the output of processing the lines * @throws IOException if an I/O error occurs */ @CanIgnoreReturnValue // some processors won't return a useful result public static <T> T readLines(URL url, Charset charset, LineProcessor<T> callback) throws IOException { return asCharSource(url, charset).readLines(callback); }
return source.asCharSource(StandardCharsets.UTF_8).readLines( new LineProcessor<PopulateResult>()
.readLines( new LineProcessor<List<String>>() { final List<String> result = Lists.newArrayList();
public void testReadLines_toList() throws IOException { assertExpectedLines(source.readLines()); }
public ExampleRecordCursor(List<ExampleColumnHandle> columnHandles, ByteSource byteSource) { this.columnHandles = columnHandles; fieldToColumnIndex = new int[columnHandles.size()]; for (int i = 0; i < columnHandles.size(); i++) { ExampleColumnHandle columnHandle = columnHandles.get(i); fieldToColumnIndex[i] = columnHandle.getOrdinalPosition(); } try (CountingInputStream input = new CountingInputStream(byteSource.openStream())) { lines = byteSource.asCharSource(UTF_8).readLines().iterator(); totalBytes = input.getCount(); } catch (IOException e) { throw new UncheckedIOException(e); } }
/** * Streams lines from a {@link File}, stopping when our callback returns false, or we have read * all of the lines. * * @param file the file to read from * @param charset the charset used to decode the input stream; see {@link StandardCharsets} for * helpful predefined constants * @param callback the {@link LineProcessor} to use to handle the lines * @return the output of processing the lines * @throws IOException if an I/O error occurs * @deprecated Prefer {@code asCharSource(file, charset).readLines(callback)}. This method is * scheduled to be removed in January 2019. */ @Deprecated @CanIgnoreReturnValue // some processors won't return a useful result public static <T> T readLines(File file, Charset charset, LineProcessor<T> callback) throws IOException { return asCharSource(file, charset).readLines(callback); }
public void testReadLines_withProcessor() throws IOException { List<String> list = source.readLines( new LineProcessor<List<String>>() { List<String> list = Lists.newArrayList(); @Override public boolean processLine(String line) throws IOException { list.add(line); return true; } @Override public List<String> getResult() { return list; } }); assertExpectedLines(list); }
.readLines( new LineProcessor<List<String>>() { final List<String> result = Lists.newArrayList();
/** * Streams lines from a URL, stopping when our callback returns false, or we have read all of the * lines. * * @param url the URL to read from * @param charset the charset used to decode the input stream; see {@link Charsets} for helpful * predefined constants * @param callback the LineProcessor to use to handle the lines * @return the output of processing the lines * @throws IOException if an I/O error occurs */ @CanIgnoreReturnValue // some processors won't return a useful result public static <T> T readLines(URL url, Charset charset, LineProcessor<T> callback) throws IOException { return asCharSource(url, charset).readLines(callback); }
/** * Reads all lines from the asset and returns the result. * * @param charset The charset to read the asset with * @return An immutable list of the lines read from the asset * @throws IOException If any file exception is thrown */ default List<String> readLines(Charset charset) throws IOException { checkNotNull(charset, "charset"); return Resources.asCharSource(getUrl(), charset).readLines(); }
/** * Streams lines from a {@link File}, stopping when our callback returns false, or we have read * all of the lines. * * @param file the file to read from * @param charset the charset used to decode the input stream; see {@link StandardCharsets} for * helpful predefined constants * @param callback the {@link LineProcessor} to use to handle the lines * @return the output of processing the lines * @throws IOException if an I/O error occurs * @deprecated Prefer {@code asCharSource(file, charset).readLines(callback)}. This method is * scheduled to be removed in January 2019. */ @Deprecated @CanIgnoreReturnValue // some processors won't return a useful result public static <T> T readLines(File file, Charset charset, LineProcessor<T> callback) throws IOException { return asCharSource(file, charset).readLines(callback); }
/** * Streams lines from a URL, stopping when our callback returns false, or we have read all of the * lines. * * @param url the URL to read from * @param charset the charset used to decode the input stream; see {@link Charsets} for helpful * predefined constants * @param callback the LineProcessor to use to handle the lines * @return the output of processing the lines * @throws IOException if an I/O error occurs */ @CanIgnoreReturnValue // some processors won't return a useful result public static <T> T readLines(URL url, Charset charset, LineProcessor<T> callback) throws IOException { return asCharSource(url, charset).readLines(callback); }
Files.newBufferedWriter(wikiDir.resolve("bugpatterns.md"), StandardCharsets.UTF_8)) { List<BugPatternInstance> patterns = asCharSource(bugPatterns.toFile(), UTF_8).readLines(generator); new BugPatternIndexWriter().dump(patterns, w, options.target, enabledCheckNames());
public void testReadLines_withProcessor_stopsOnFalse() throws IOException { List<String> list = source.readLines( new LineProcessor<List<String>>() { List<String> list = Lists.newArrayList(); @Override public boolean processLine(String line) throws IOException { list.add(line); return false; } @Override public List<String> getResult() { return list; } }); if (expectedLines.isEmpty()) { assertTrue(list.isEmpty()); } else { assertEquals(expectedLines.subList(0, 1), list); } }
int lineCount = source.readLines( new LineProcessor<Integer>()
public static RootLexicon load(File input) throws IOException { return Files.asCharSource(input, Charsets.UTF_8).readLines(new TextLexiconProcessor()); }