String result = new BufferedReader(new InputStreamReader(inputStream)) .lines().collect(Collectors.joining("\n"));
@Override public void run() { try { new BufferedReader(new InputStreamReader(inputStream)).lines().forEach(consumeInputLine); } catch (UncheckedIOException ignored) { // If this gobbler is reading the System.out stream from a process that gets killed, // we will occasionally see an exception here than can be ignored. } }
public List<String> findHeadings(Reader input) { try (BufferedReader reader = new BufferedReader(input)) { return reader.lines() .filter(line -> line.endsWith(":")) .map(line -> line.substring(0, line.length() - 1)) .collect(toList()); } catch (IOException e) { throw new HeadingLookupException(e); } } // END nodip_headings
private <T> T withLinesOf(Reader input, Function<Stream<String>, T> handler, Function<IOException, RuntimeException> error) { try (BufferedReader reader = new BufferedReader(input)) { return handler.apply(reader.lines()); } catch (IOException e) { throw error.apply(e); } } // END with_lines_Of
public static String fileToString(InputStream inputStream) { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); return bufferedReader.lines().collect(Collectors.joining(System.lineSeparator())); } }
@Override public void run() { try { new BufferedReader(new InputStreamReader(inputStream)).lines() .map(line -> line + LINE_SEPARATOR).forEach(this.inputListener::notifyInputLine); } catch (UncheckedIOException e) { logger.debug(e); } } }
/** * Set a property from a ByteArrayOutputStream * * @param baos * contains the property value. * @param propertyName * the property name. */ private void setPropertyFromBAOS(final ByteArrayOutputStream baos, final String propertyName) { final BufferedReader in = new BufferedReader(new StringReader(Execute.toString(baos))); managingTask.getProject().setNewProperty(propertyName, in.lines().collect(Collectors.joining(System.lineSeparator()))); }
private static void printLog( String description, File file, PrintStream out ) { if ( file != null && file.exists() ) { out.println( String.format( "---------- BEGIN %s ----------", description ) ); try ( BufferedReader reader = new BufferedReader( new FileReader( file ) ) ) { reader.lines().forEach( out::println ); } catch ( IOException ex ) { out.println( "Unable to collect log files: " + ex.getMessage() ); ex.printStackTrace( out ); } finally { out.println( String.format( "---------- END %s ----------", description ) ); } } }
String result = new BufferedReader(new InputStreamReader(inputStream)).lines() .parallel().collect(Collectors.joining("\n"));
@Override public void run() { try (final BufferedReader reader = new BufferedReader(new InputStreamReader(externalProcess.getErrorStream()))) { reader.lines().filter(line -> line != null && line.length() > 0).forEach(getLogger()::warn); } catch (final IOException ioe) { } } });
private String resource(String suffix) throws IOException { String name = this.getClass().getSimpleName() + "-" + suffix; ClassPathResource resource = new ClassPathResource(name, this.getClass()); try ( BufferedReader reader = new BufferedReader(new FileReader(resource.getFile())) ) { return reader.lines().collect(Collectors.joining()); } } }
BufferedReader fooBarReader = new BufferedReader(new StringReader("Foo\nBar")); fooBarReader.lines() .skip(1L) .parallel() .forEach(System.out::println);
private static List<String> loadLines(InputStream stream, Charset charset) throws IOException { try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream, charset))) { return reader.lines().collect(Collectors.toList()); } }
/** Returns a stream of each line in the trace file. */ protected Stream<String> lines() throws IOException { InputStream input = readFiles(); Reader reader = new InputStreamReader(input, UTF_8); return new BufferedReader(reader).lines().map(String::trim) .onClose(() -> Closeables.closeQuietly(input)); } }
int size = LEFT_COLUMN_SIZE - label.length(); final String prefix = size > 0 ? Stream.generate(() -> " ") .limit(size).collect(Collectors.joining()) + label : label; new BufferedReader(new StringReader(event.getMessage()))) { message.append(r.lines() .collect(Collectors.joining(System.lineSeparator() + prefix, prefix, ""))); } catch (IOException e) {
/** * Simple hack to handle the PVCS command-line tools botch when * handling UNC notation. * @throws IOException if there is an error. */ private void massagePCLI(File in, File out) throws IOException { try (BufferedReader inReader = new BufferedReader(new FileReader(in)); BufferedWriter outWriter = new BufferedWriter(new FileWriter(out))) { for (String line : (Iterable<String>) () -> inReader.lines() .map(s -> s.replace('\\', '/')).iterator()) { outWriter.write(line); outWriter.newLine(); } } }