Crossfire JXClient, Trunk
Grep Class Reference
+ Collaboration diagram for Grep:

Static Public Member Functions

static void main (String[] args) throws IOException
 

Static Private Member Functions

static Stream< Path > getPathStream (Path path)
 
static Stream< String > path2Lines (Path path)
 
static void printUsageAndExit (String... str)
 

Detailed Description

Grep prints lines matching a regex. See printUsageAndExit(String...) method for instructions and command line parameters. This sample shows examples of using next features:

  • Lambda and bulk operations. Working with streams: map(...),filter(...),flatMap(...),limit(...) methods.
  • Static method reference for printing values.
  • New Collections API forEach(...) method.
  • Try-with-resources feature.
  • new Files.walk(...), Files.lines(...) API.
  • Streams that need to be closed.

Definition at line 67 of file Grep.java.

Member Function Documentation

◆ getPathStream()

static Stream<Path> Grep.getPathStream ( Path  path)
staticprivate

Flattens file system hierarchy into a stream. This code is not inlined for the reason of Files.walk() throwing a checked IOException that must be caught.

Parameters
path- the file or directory
Returns
Whole file tree starting from path, a stream with one element - the path itself - if it is a file.

Definition at line 162 of file Grep.java.

Referenced by main().

+ Here is the caller graph for this function:

◆ main()

static void Grep.main ( String[]  args) throws IOException
static

The main method for the Grep program. Run program with empty argument list to see possible arguments.

Parameters
argsthe argument list for Grep.
Exceptions
java.io.IOExceptionIf an I/O error occurs.

Definition at line 89 of file Grep.java.

References getPathStream(), path2Lines(), and printUsageAndExit().

+ Here is the call graph for this function:

◆ path2Lines()

static Stream<String> Grep.path2Lines ( Path  path)
staticprivate

Produces a stream of lines from a file. The result is a stream in order to close it later. This code is not inlined for the reason of Files.lines() throwing a checked IOException that must be caught.

Parameters
path- the file to read
Returns
stream of lines from the file

Definition at line 178 of file Grep.java.

Referenced by main().

+ Here is the caller graph for this function:

◆ printUsageAndExit()

static void Grep.printUsageAndExit ( String...  str)
staticprivate

Definition at line 69 of file Grep.java.

Referenced by main().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: