use of java.io.PipedInputStream in project zeppelin by apache.
the class PythonInterpreter method createGatewayServerAndStartScript.
private void createGatewayServerAndStartScript() throws UnknownHostException {
createPythonScript();
if (System.getenv("ZEPPELIN_HOME") != null) {
py4jLibPath = System.getenv("ZEPPELIN_HOME") + File.separator + ZEPPELIN_PY4JPATH;
pythonLibPath = System.getenv("ZEPPELIN_HOME") + File.separator + ZEPPELIN_PYTHON_LIBS;
} else {
Path workingPath = Paths.get("..").toAbsolutePath();
py4jLibPath = workingPath + File.separator + ZEPPELIN_PY4JPATH;
pythonLibPath = workingPath + File.separator + ZEPPELIN_PYTHON_LIBS;
}
port = findRandomOpenPortOnAllLocalInterfaces();
gatewayServer = new GatewayServer(this, port, GatewayServer.DEFAULT_PYTHON_PORT, InetAddress.getByName("0.0.0.0"), InetAddress.getByName("0.0.0.0"), GatewayServer.DEFAULT_CONNECT_TIMEOUT, GatewayServer.DEFAULT_READ_TIMEOUT, (List) null);
gatewayServer.start();
// Run python shell
String pythonCmd = getPythonCommand();
CommandLine cmd = CommandLine.parse(pythonCmd);
if (!pythonCmd.endsWith(".py")) {
// PythonDockerInterpreter set pythoncmd with script
cmd.addArgument(getScriptPath(), false);
}
cmd.addArgument(Integer.toString(port), false);
cmd.addArgument(getLocalIp(), false);
executor = new DefaultExecutor();
outputStream = new InterpreterOutputStream(logger);
PipedOutputStream ps = new PipedOutputStream();
in = null;
try {
in = new PipedInputStream(ps);
} catch (IOException e1) {
throw new InterpreterException(e1);
}
ins = new BufferedWriter(new OutputStreamWriter(ps));
input = new ByteArrayOutputStream();
PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream, outputStream, in);
executor.setStreamHandler(streamHandler);
executor.setWatchdog(new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT));
try {
Map env = EnvironmentUtils.getProcEnvironment();
if (!env.containsKey("PYTHONPATH")) {
env.put("PYTHONPATH", py4jLibPath + File.pathSeparator + pythonLibPath);
} else {
env.put("PYTHONPATH", env.get("PYTHONPATH") + File.pathSeparator + py4jLibPath + File.pathSeparator + pythonLibPath);
}
logger.info("cmd = {}", cmd.toString());
executor.execute(cmd, env, this);
pythonscriptRunning = true;
} catch (IOException e) {
throw new InterpreterException(e);
}
try {
input.write("import sys, getopt\n".getBytes());
ins.flush();
} catch (IOException e) {
throw new InterpreterException(e);
}
}
use of java.io.PipedInputStream in project jetty.project by eclipse.
the class HttpTesterTest method testResponsesSplitInput.
@Test
public void testResponsesSplitInput() throws Exception {
PipedOutputStream src = new PipedOutputStream();
PipedInputStream stream = new PipedInputStream(src) {
@Override
public synchronized int read(byte[] b, int off, int len) throws IOException {
if (available() == 0)
return 0;
return super.read(b, off, len);
}
};
HttpTester.Input in = HttpTester.from(stream);
src.write(("HTTP/1.1 200 OK\r\n" + "Header: value\r\n" + "Transfer-Encoding: chunked\r\n" + "\r\n" + "A\r\n" + "0123456789\r\n" + "6\r\n" + "ABC").getBytes(StandardCharsets.ISO_8859_1));
HttpTester.Response response = HttpTester.parseResponse(in);
assertThat(response, nullValue());
src.write(("DEF\r\n" + "0\r\n" + "\r\n" + "HTTP/1.1 400 OK\r\n" + "Next: response\r\n" + "Content-Length: 16\r\n" + "\r\n" + "0123456789").getBytes(StandardCharsets.ISO_8859_1));
response = HttpTester.parseResponse(in);
assertThat(response.getVersion(), is(HttpVersion.HTTP_1_1));
assertThat(response.getStatus(), is(200));
assertThat(response.getReason(), is("OK"));
assertThat(response.get("Header"), is("value"));
assertThat(response.getContent(), is("0123456789ABCDEF"));
response = HttpTester.parseResponse(in);
assertThat(response, nullValue());
src.write(("ABCDEF").getBytes(StandardCharsets.ISO_8859_1));
response = HttpTester.parseResponse(in);
assertThat(response.getVersion(), is(HttpVersion.HTTP_1_1));
assertThat(response.getStatus(), is(400));
assertThat(response.getReason(), is("OK"));
assertThat(response.get("Next"), is("response"));
assertThat(response.getContent(), is("0123456789ABCDEF"));
}
use of java.io.PipedInputStream in project stetho by facebook.
the class GunzippingOutputStream method create.
public static GunzippingOutputStream create(OutputStream finalOut) throws IOException {
PipedInputStream pipeIn = new PipedInputStream();
PipedOutputStream pipeOut = new PipedOutputStream(pipeIn);
Future<Void> copyFuture = sExecutor.submit(new GunzippingCallable(pipeIn, finalOut));
return new GunzippingOutputStream(pipeOut, copyFuture);
}
use of java.io.PipedInputStream in project gitblit by gitblit.
the class DeepCopier method copyParallel.
/**
* This conserves heap memory!!!!! Produce a deep copy of the given object.
* Serializes the object through a pipe between two threads. Recommended for
* very large objects. The current thread is used for serializing the
* original object in order to respect any synchronization the caller may
* have around it, and a new thread is used for deserializing the copy.
*
*/
public static <T> T copyParallel(T original) {
try {
PipedOutputStream outputStream = new PipedOutputStream();
PipedInputStream inputStream = new PipedInputStream(outputStream);
ObjectOutputStream ois = new ObjectOutputStream(outputStream);
Receiver<T> receiver = new Receiver<T>(inputStream);
try {
ois.writeObject(original);
} finally {
ois.close();
}
return receiver.getResult();
} catch (IOException iox) {
// doesn't seem likely to happen as these streams are in memory
throw new RuntimeException(iox);
}
}
use of java.io.PipedInputStream in project flink by apache.
the class PrimitiveDataTypeTest method setup.
@Before
public void setup() throws Exception {
in = new PipedInputStream(1000);
out = new PipedOutputStream(in);
mIn = new DataInputViewStreamWrapper(in);
mOut = new DataOutputViewStreamWrapper(out);
}
Aggregations