Search in sources :

Example 86 with PipedInputStream

use of java.io.PipedInputStream in project hadoop by apache.

the class TestJMXGet method checkPrintAllValues.

private static boolean checkPrintAllValues(JMXGet jmx) throws Exception {
    int size = 0;
    byte[] bytes = null;
    String pattern = "List of all the available keys:";
    PipedOutputStream pipeOut = new PipedOutputStream();
    PipedInputStream pipeIn = new PipedInputStream(pipeOut);
    PrintStream oldErr = System.err;
    System.setErr(new PrintStream(pipeOut));
    try {
        jmx.printAllValues();
        if ((size = pipeIn.available()) != 0) {
            bytes = new byte[size];
            pipeIn.read(bytes, 0, bytes.length);
        }
        pipeOut.close();
        pipeIn.close();
    } finally {
        System.setErr(oldErr);
    }
    return bytes != null ? new String(bytes).contains(pattern) : false;
}
Also used : PrintStream(java.io.PrintStream) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream)

Example 87 with PipedInputStream

use of java.io.PipedInputStream in project mongo-hadoop by mongodb.

the class MongoUpdateOutputReaderTest method inputFromBSONObject.

private DataInput inputFromBSONObject(final BSONObject object) throws IOException {
    PipedOutputStream outputStream = new PipedOutputStream();
    PipedInputStream inputStream = new PipedInputStream(outputStream);
    bsonWritable.setDoc(object);
    bsonWritable.write(new DataOutputStream(outputStream));
    return new DataInputStream(inputStream);
}
Also used : DataOutputStream(java.io.DataOutputStream) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) DataInputStream(java.io.DataInputStream)

Example 88 with PipedInputStream

use of java.io.PipedInputStream in project robovm by robovm.

the class InputStreamReaderTest method testReadDoesNotBlockUnnecessarily.

/**
     * This bug claims that InputStreamReader blocks unnecessarily:
     * http://code.google.com/p/android/issues/detail?id=10252
     */
public void testReadDoesNotBlockUnnecessarily() throws IOException {
    PipedInputStream pin = new PipedInputStream();
    PipedOutputStream pos = new PipedOutputStream(pin);
    pos.write("hello".getBytes("UTF-8"));
    InputStreamReader reader = new InputStreamReader(pin);
    char[] buffer = new char[1024];
    int count = reader.read(buffer);
    assertEquals(5, count);
}
Also used : InputStreamReader(java.io.InputStreamReader) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream)

Example 89 with PipedInputStream

use of java.io.PipedInputStream in project robovm by robovm.

the class InterruptedStreamTest method testInterruptPipedInputStream.

public void testInterruptPipedInputStream() throws Exception {
    PipedOutputStream out = new PipedOutputStream();
    PipedInputStream in = new PipedInputStream(out);
    testInterruptInputStream(in);
}
Also used : PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream)

Example 90 with PipedInputStream

use of java.io.PipedInputStream in project robovm by robovm.

the class InterruptedStreamTest method testInterruptPipedOutputStream.

public void testInterruptPipedOutputStream() throws Exception {
    PipedOutputStream out = new PipedOutputStream();
    new PipedInputStream(out);
    testInterruptOutputStream(out);
}
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