java.io.BufferedReader.lines()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.1k)|赞(0)|评价(0)|浏览(632)

本文整理了Java中java.io.BufferedReader.lines()方法的一些代码示例,展示了BufferedReader.lines()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BufferedReader.lines()方法的具体详情如下:
包路径:java.io.BufferedReader
类名称:BufferedReader
方法名:lines

BufferedReader.lines介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

String result = new BufferedReader(new InputStreamReader(inputStream))
.lines().collect(Collectors.joining("\n"));

代码示例来源:origin: lets-blade/blade

public static String readToString(Path path) throws IOException {
  BufferedReader bufferedReader = Files.newBufferedReader(path);
  return bufferedReader.lines().collect(Collectors.joining(System.lineSeparator()));
}

代码示例来源:origin: apache/geode

@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.
 }
}

代码示例来源:origin: RichardWarburton/java-8-lambdas-exercises

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

代码示例来源:origin: RichardWarburton/java-8-lambdas-exercises

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

代码示例来源:origin: ctripcorp/apollo

public static String fileToString(InputStream inputStream) {
  BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
  return bufferedReader.lines().collect(Collectors.joining(System.lineSeparator()));
 }
}

代码示例来源:origin: apache/geode

@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);
  }
 }
}

代码示例来源:origin: org.apache.ant/ant

/**
 * 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())));
}

代码示例来源:origin: lets-blade/blade

public static String readToString(BufferedReader bufferedReader) {
  return bufferedReader.lines().collect(Collectors.joining(System.lineSeparator()));
}

代码示例来源:origin: neo4j/neo4j

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 ) );
    }
  }
}

代码示例来源:origin: stackoverflow.com

String result = new BufferedReader(new InputStreamReader(inputStream)).lines()
 .parallel().collect(Collectors.joining("\n"));

代码示例来源:origin: apache/nifi

@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) {
    }
  }
});

代码示例来源:origin: spring-projects/spring-security

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());
    }
  }
}

代码示例来源:origin: lets-blade/blade

public static String readToString(BufferedReader bufferedReader) {
  return bufferedReader.lines().collect(Collectors.joining(System.lineSeparator()));
}

代码示例来源:origin: stackoverflow.com

BufferedReader fooBarReader = new BufferedReader(new StringReader("Foo\nBar"));
fooBarReader.lines()
    .skip(1L)
    .parallel()
    .forEach(System.out::println);

代码示例来源:origin: org.assertj/assertj-core

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());
 }
}

代码示例来源:origin: ben-manes/caffeine

/** 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));
 }
}

代码示例来源:origin: org.apache.ant/ant

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) {

代码示例来源:origin: lets-blade/blade

public static String readToString(Path path) throws IOException {
  BufferedReader bufferedReader = Files.newBufferedReader(path);
  return bufferedReader.lines().collect(Collectors.joining(System.lineSeparator()));
}

代码示例来源:origin: org.apache.ant/ant

/**
 * 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();
    }
  }
}

相关文章