use of java.io.PipedOutputStream in project che by eclipse.
the class JschSshProcess method start.
// todo how to manage disconnections due to network failures?
@Override
public void start(LineConsumer output) throws MachineException {
try (PipedOutputStream pipedOS = new PipedOutputStream();
PipedInputStream pipedIS = new PipedInputStream(pipedOS);
BufferedReader outReader = new BufferedReader(new InputStreamReader(pipedIS))) {
exec.setOutputStream(pipedOS);
exec.setExtOutputStream(pipedOS);
exec.connect();
String outLine;
while ((outLine = outReader.readLine()) != null) {
output.writeLine(outLine);
}
} catch (IOException | JSchException e) {
throw new MachineException("Ssh machine command execution error:" + e.getLocalizedMessage());
} finally {
exec.disconnect();
}
}
use of java.io.PipedOutputStream in project symmetric-ds by JumpMind.
the class InternalTransportManager method getPushTransport.
@Override
public IOutgoingWithResponseTransport getPushTransport(final Node remote, final Node local, String securityToken, Map<String, String> requestProperties, String registrationUrl) throws IOException {
final PipedOutputStream pushOs = new PipedOutputStream();
final PipedInputStream pushIs = new PipedInputStream(pushOs);
final PipedOutputStream respOs = new PipedOutputStream();
final PipedInputStream respIs = new PipedInputStream(respOs);
runAtClient(remote.getSyncUrl(), pushIs, respOs, new IClientRunnable() {
public void run(ISymmetricEngine engine, InputStream is, OutputStream os) throws Exception {
// This should be basically what the push servlet does ...
engine.getDataLoaderService().loadDataFromPush(local, pushIs, respOs);
}
});
return new InternalOutgoingWithResponseTransport(pushOs, respIs);
}
use of java.io.PipedOutputStream in project jdk8u_jdk by JetBrains.
the class JarBackSlash method testJarList.
private static void testJarList(String jarFile) throws IOException {
List<String> argList = new ArrayList<String>();
argList.add("-tvf");
argList.add(jarFile);
argList.add(JARBACKSLASH + File.separatorChar + DIR + File.separatorChar + FILENAME);
String[] jarArgs = new String[argList.size()];
jarArgs = argList.toArray(jarArgs);
PipedOutputStream pipedOutput = new PipedOutputStream();
PipedInputStream pipedInput = new PipedInputStream(pipedOutput);
PrintStream out = new PrintStream(pipedOutput);
Main jarTool = new Main(out, System.err, "jar");
if (!jarTool.run(jarArgs)) {
fail("Could not list jar file.");
}
out.flush();
check(pipedInput.available() > 0);
}
use of java.io.PipedOutputStream in project robovm by robovm.
the class OldAndroidPipedStreamTest method testA.
public void testA() throws Exception {
final PipedInputStream in = new PipedInputStream();
final PipedOutputStream out = new PipedOutputStream(in);
assertEquals(0, in.available());
TestThread reader, writer;
reader = new TestThread() {
Fibonacci fib = new Fibonacci();
@Override
public void runTest() throws Exception {
int readInt;
byte readByte;
for (; ; ) {
readInt = in.read();
if (readInt == -1) {
return;
}
readByte = (byte) readInt;
assertEquals(readByte, (byte) fib.next());
countRead++;
}
}
};
reader.start();
writer = new TestThread() {
Fibonacci fib = new Fibonacci();
@Override
public void runTest() throws Exception {
for (int i = 0; i < 2000; i++) {
int toWrite = fib.next();
out.write(toWrite);
}
out.close();
}
};
writer.start();
for (; ; ) {
try {
reader.join(60 * 1000);
writer.join(1000);
break;
} catch (InterruptedException ex) {
}
}
assertEquals(2000, reader.countRead);
if (writer.exception != null) {
throw new Exception(writer.exception);
}
if (reader.exception != null) {
throw new Exception(reader.exception);
}
}
use of java.io.PipedOutputStream in project robovm by robovm.
the class OldAndroidPipedStreamTest method testB.
public void testB() throws Exception {
final PipedInputStream in = new PipedInputStream();
final PipedOutputStream out = new PipedOutputStream(in);
assertEquals(0, in.available());
TestThread reader, writer;
reader = new TestThread() {
Fibonacci fib = new Fibonacci();
@Override
public void runTest() throws Exception {
byte[] readBytes = new byte[5];
int ret;
for (; ; ) {
int nread = 0;
while (nread < 5) {
ret = in.read(readBytes, nread, readBytes.length - nread);
if (ret == -1) {
return;
}
nread += ret;
}
assertEquals(5, nread);
int readInt = (((int) readBytes[0] & 0xff) << 24) | (((int) readBytes[1] & 0xff) << 16) | (((int) readBytes[2] & 0xff) << 8) | (((int) readBytes[3] & 0xff));
assertEquals("Error at " + countRead, fib.next(), readInt);
assertEquals("Error at " + countRead, 0, readBytes[4]);
countRead++;
}
}
};
reader.start();
writer = new TestThread() {
Fibonacci fib = new Fibonacci();
@Override
public void runTest() throws Exception {
byte[] writeBytes = new byte[5];
for (int i = 0; i < 2000; i++) {
int toWrite = fib.next();
writeBytes[0] = (byte) (toWrite >> 24);
writeBytes[1] = (byte) (toWrite >> 16);
writeBytes[2] = (byte) (toWrite >> 8);
writeBytes[3] = (byte) (toWrite);
writeBytes[4] = 0;
out.write(writeBytes, 0, writeBytes.length);
}
out.close();
}
};
writer.start();
for (; ; ) {
try {
reader.join(60 * 1000);
writer.join(1000);
break;
} catch (InterruptedException ex) {
}
}
if (reader.exception != null) {
throw new Exception(reader.exception);
}
if (writer.exception != null) {
throw new Exception(writer.exception);
}
assertEquals(2000, reader.countRead);
}
Aggregations