use of java.io.PipedInputStream in project textdb by TextDB.
the class TextQLParserTest method string2InputStream.
/**
* Create an InputStream that contains an given String.
* @param s the string to be available in the resulting InputStream
* @return an InputStream containing the string s
*/
private InputStream string2InputStream(String s) {
try {
// create a piped input stream to write to and a piped output stream to return as result
PipedOutputStream pos = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream(pos);
// print the string to the stream
PrintStream ppos = new PrintStream(pos);
ppos.print(s);
ppos.close();
// return the generated InputStream
return pis;
} catch (IOException e) {
// return null if an IOException is thrown
return null;
}
}
use of java.io.PipedInputStream in project tomee by apache.
the class SSHServerTest method call.
@Test(timeout = 10000L)
public void call() throws Exception {
final SshClient client = SshClient.setUpDefaultClient();
client.start();
try {
final ClientSession session = client.connect("localhost", 4222).await().getSession();
session.authPassword("jonathan", "secret");
final ClientChannel channel = session.createChannel("shell");
ByteArrayOutputStream sent = new ByteArrayOutputStream();
PipedOutputStream pipedIn = new TeePipedOutputStream(sent);
channel.setIn(new PipedInputStream(pipedIn));
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayOutputStream err = new ByteArrayOutputStream();
channel.setOut(out);
channel.setErr(err);
channel.open();
pipedIn.write("properties\r\n".getBytes());
pipedIn.flush();
pipedIn.write("exit\r\n".getBytes());
pipedIn.flush();
channel.waitFor(ClientChannel.CLOSED, 0);
channel.close(false);
client.stop();
assertTrue(new String(sent.toByteArray()).contains("properties\r\nexit\r\n"));
assertTrue(new String(out.toByteArray()).contains("ServerService(id=ssh)"));
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of java.io.PipedInputStream in project tigervnc by TigerVNC.
the class Channel method getInputStream.
public InputStream getInputStream() throws IOException {
int max_input_buffer_size = 32 * 1024;
try {
max_input_buffer_size = Integer.parseInt(getSession().getConfig("max_input_buffer_size"));
} catch (Exception e) {
}
PipedInputStream in = new MyPipedInputStream(// this value should be customizable.
32 * 1024, max_input_buffer_size);
boolean resizable = 32 * 1024 < max_input_buffer_size;
io.setOutputStream(new PassiveOutputStream(in, resizable), false);
return in;
}
use of java.io.PipedInputStream in project tigervnc by TigerVNC.
the class Channel method getExtInputStream.
public InputStream getExtInputStream() throws IOException {
int max_input_buffer_size = 32 * 1024;
try {
max_input_buffer_size = Integer.parseInt(getSession().getConfig("max_input_buffer_size"));
} catch (Exception e) {
}
PipedInputStream in = new MyPipedInputStream(// this value should be customizable.
32 * 1024, max_input_buffer_size);
boolean resizable = 32 * 1024 < max_input_buffer_size;
io.setExtOutputStream(new PassiveOutputStream(in, resizable), false);
return in;
}
use of java.io.PipedInputStream in project apex-malhar by apache.
the class OutputCollectorImpl method cloneObj.
private <T> T cloneObj(T t) throws IOException {
Serializer<T> keySerializer;
Class<T> keyClass;
PipedInputStream pis = new PipedInputStream();
PipedOutputStream pos = new PipedOutputStream(pis);
keyClass = (Class<T>) t.getClass();
keySerializer = serializationFactory.getSerializer(keyClass);
keySerializer.open(pos);
keySerializer.serialize(t);
Deserializer<T> keyDesiralizer = serializationFactory.getDeserializer(keyClass);
keyDesiralizer.open(pis);
T clonedArg0 = keyDesiralizer.deserialize(null);
pos.close();
pis.close();
keySerializer.close();
keyDesiralizer.close();
return clonedArg0;
}
Aggregations