-
Notifications
You must be signed in to change notification settings - Fork 43
WIP: grep on InputStreams #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@terzerm @benjwarner hi, could you please let me know what's your take on this before I proceed with unit tests and documentation? |
terzerm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi
This is not required.
Unix4j supports redirection of input and output with different built in types and the option to implement your own custom type.
Grepping from input stream can be done via
Unix4j.from(inputStream).grep("Subject", testFile).toStringResult());|
closing as this is not required. |
|
Unit test was added demonstrating use of non-file input stream at the end of |
|
Are you trying to support grep from multiple input files given as input streams ? That is not supported so I might reconsider |
|
@terzerm thanks for the quick feedback! |
|
Hi Definitely the matching files option is expected to be faster --- in particular if a file has many matching lines. You can see this in WriteFilesWithMatchingLinesProcessor --- early return if first match found. I would do a small test but unix4j has generally been performance tested and performs reasonably well. In some cases even faster than the unix original :-) |
|
FYI, support for multiple inputs has been added to the following commands: cat, grep, head, sort, tail, wc You can either pass StreamInput instances to the newly added method or you create your own Input implementation for the AbstractFile class mentioned above (best with a good to-string implementation for commands that print the input name). See unit tests for examples. Change added as per 77f1847 |
|
Thanks @terzerm , I'll try :) |
The background for this PR is that file-search functionality was recently added to muCommander but we currently only search files by their name, there's no way to search by the content of the files (that appears to be desired). It seems like the
grepimplementation inunix4jcan be used for this.However, in muCommander we abstract files with the AbstractFile class. We have concrete implementations of the AbstractFile for various formats, like SFTP, SMB and so on, that we cannot use Java's File/Path for. The content of AbstractFiles can be read using Java's InputStream.
Looking at
unix4jit seems it intended to use Java's FileInputStream but (a) Looks like it's not used at the moment (at least not by thegrepcommand; (b) in muCommander, the InputStreams are not necessarily FileInputStreams.This PR makes it possible for the
grepcommand to operate on Java's InputStream.