Search in sources :

Example 56 with PipedInputStream

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;
    }
}
Also used : PrintStream(java.io.PrintStream) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) IOException(java.io.IOException)

Example 57 with PipedInputStream

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();
    }
}
Also used : SshClient(org.apache.sshd.SshClient) ClientSession(org.apache.sshd.ClientSession) PipedOutputStream(java.io.PipedOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PipedInputStream(java.io.PipedInputStream) IOException(java.io.IOException) ClientChannel(org.apache.sshd.ClientChannel) Test(org.junit.Test)

Example 58 with PipedInputStream

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;
}
Also used : PipedInputStream(java.io.PipedInputStream) IOException(java.io.IOException)

Example 59 with PipedInputStream

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;
}
Also used : PipedInputStream(java.io.PipedInputStream) IOException(java.io.IOException)

Example 60 with PipedInputStream

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;
}
Also used : PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream)

Aggregations

PipedInputStream (java.io.PipedInputStream)128 PipedOutputStream (java.io.PipedOutputStream)121 IOException (java.io.IOException)42 Test (org.junit.Test)33 BinaryDecoder (co.cask.cdap.common.io.BinaryDecoder)21 BinaryEncoder (co.cask.cdap.common.io.BinaryEncoder)21 ReflectionDatumReader (co.cask.cdap.internal.io.ReflectionDatumReader)17 TypeToken (com.google.common.reflect.TypeToken)17 DataInputStream (java.io.DataInputStream)13 DataOutputStream (java.io.DataOutputStream)13 InputStream (java.io.InputStream)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 Before (org.junit.Before)10 OutputStream (java.io.OutputStream)9 PrintStream (java.io.PrintStream)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 InputStreamReader (java.io.InputStreamReader)6 ImmutableList (com.google.common.collect.ImmutableList)5 List (java.util.List)5 ISymmetricEngine (org.jumpmind.symmetric.ISymmetricEngine)5