Created
February 16, 2018 14:45
-
-
Save Exerosis/96147b08a2d5a29cfdf21c582c17d6f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Builder { | |
interface Buffer<Return> extends Output<Return> { | |
Return __build(OutputStream err, | |
OutputStream out, | |
boolean redirect, | |
Number buffer) throws IOException; | |
@Override | |
default Return __build(OutputStream err, | |
OutputStream out, | |
boolean redirect) throws IOException { | |
return __build(err, out, redirect, 1024); | |
} | |
default Output<Return> buffer(Number buffer) { | |
return (err, out, redirect) -> __build(err, out, redirect, buffer); | |
} | |
} | |
interface Output<Return> extends Errors<Return> { | |
Return __build(OutputStream err, | |
OutputStream out, | |
boolean redirect) throws IOException; | |
@Override | |
default Return __build(OutputStream err, boolean redirect) throws IOException { | |
return __build(err, null, redirect); | |
} | |
default Errors.Redirect<Return> pipeOutput(OutputStream out) { | |
return (err, redirect) -> __build(err, out, redirect); | |
} | |
} | |
interface Errors<Return> { | |
Return __build(OutputStream err, | |
boolean redirect) throws IOException; | |
default Return pipeErrors(OutputStream err) throws IOException { | |
return __build(err, false); | |
} | |
default Return ignoreErrors() throws IOException { | |
return __build(null, true); | |
} | |
interface Redirect<Return> extends Errors<Return> { | |
default Return redirectErrors() throws IOException { | |
return __build(null, true); | |
} | |
@Override | |
default Return ignoreErrors() throws IOException { | |
return __build(null, false); | |
} | |
} | |
} | |
} | |
public static Builder.Buffer<CommandLine> create(String command) { | |
return (err, out, redirect, buffer) -> | |
new CommandLine(command, err, out, redirect, buffer.intValue()); | |
} | |
private CommandLine(String command, | |
OutputStream out, | |
OutputStream err, | |
boolean redirect, | |
int buffer) throws IOException { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment