Created
February 16, 2018 14:37
-
-
Save Exerosis/e6f03e0c12181a39490c93a709d0820b 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 Error.Ignore<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 Redirect<Return> pipeOutput(OutputStream out) { | |
return (err, redirect) -> __build(err, out, redirect); | |
} | |
} | |
interface Error<Return> { | |
Return __build(OutputStream err, | |
boolean redirect) throws IOException; | |
default Return pipeErrors(OutputStream err) throws IOException { | |
return __build(err, false); | |
} | |
interface Redirect<Return> extends Error<Return> { | |
default Return redirectErrors() throws IOException { | |
return __build(null, true); | |
} | |
} | |
interface Ignore<Return> extends Error<Return> { | |
default Return ignoreErrors() throws IOException { | |
return __build(null, true); | |
} | |
} | |
} | |
} | |
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