Ответ 1
Из-за перегрузки оператора он в конечном итоге вызывает ProcessGroovyMethods.pipeTo() в среде выполнения Groovy, которая действительно имитирует каналы с использованием java потоки:
/**
* Allows one Process to asynchronously pipe data to another Process.
*
* @param left a Process instance
* @param right a Process to pipe output to
* @return the second Process to allow chaining
* @throws java.io.IOException if an IOException occurs.
* @since 1.5.2
*/
public static Process pipeTo(final Process left, final Process right) throws IOException {
new Thread(new Runnable() {
public void run() {
InputStream in = new BufferedInputStream(getIn(left));
OutputStream out = new BufferedOutputStream(getOut(right));
byte[] buf = new byte[8192];
int next;
try {
while ((next = in.read(buf)) != -1) {
out.write(buf, 0, next);
}
} catch (IOException e) {
throw new GroovyRuntimeException("exception while reading process stream", e);
} finally {
closeWithWarning(out);
}
}
}).start();
return right;
}
Я не могу говорить о количестве накладных расходов, связанных с верхней частью моей головы.