Search in sources :

Example 21 with PipedInputStream

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

the class ScannerTest method test_ConstructorLjava_io_InputStreamLjava_lang_String.

/**
     * @tests java.util.Scanner#Scanner(InputStream, String)
     */
public void test_ConstructorLjava_io_InputStreamLjava_lang_String() {
    s = new Scanner(new PipedInputStream(), Charset.defaultCharset().name());
    assertNotNull(s);
    s.close();
    try {
        s = new Scanner((PipedInputStream) null, "invalid charset");
        fail();
    } catch (NullPointerException expected) {
    }
    try {
        s = new Scanner(new PipedInputStream(), null);
        fail();
    } catch (NullPointerException expected) {
    }
    try {
        s = new Scanner(new PipedInputStream(), "invalid charset");
        fail();
    } catch (IllegalArgumentException expected) {
    }
// TODO: test if the specified charset is used.
}
Also used : Scanner(java.util.Scanner) PipedInputStream(java.io.PipedInputStream)

Example 22 with PipedInputStream

use of java.io.PipedInputStream in project limelight by slagyr.

the class StreamReaderTest method setUp.

@Before
public void setUp() throws Exception {
    output = new PipedOutputStream();
    reader = new StreamReader(new PipedInputStream(output));
}
Also used : PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) Before(org.junit.Before)

Example 23 with PipedInputStream

use of java.io.PipedInputStream in project exhibitor by soabase.

the class ExplorerResource method usageListing.

@POST
@Path("usage-listing")
@Consumes("application/json")
@Produces("text/plain")
public Response usageListing(UsageListingRequest usageListingRequest) throws Exception {
    context.getExhibitor().getLog().add(ActivityLog.Type.INFO, "Starting usage listing");
    final UsageListing usageListing = new UsageListing(context.getExhibitor(), usageListingRequest.getStartPath(), usageListingRequest.getMaxChildrenForTraversal());
    usageListing.generate();
    final PipedInputStream in = new PipedInputStream();
    final PipedOutputStream pipedOutputStream = new PipedOutputStream(in);
    executorService.submit(new Runnable() {

        @Override
        public void run() {
            PrintStream out = null;
            try {
                out = new PrintStream(pipedOutputStream);
                out.println("Path\tCreateDate\tChildQty\tDeepChildQty");
                Iterator<String> iterator = usageListing.getPaths();
                while (iterator.hasNext()) {
                    String path = iterator.next();
                    UsageListing.NodeEntry details = usageListing.getNodeDetails(path);
                    out.println(path + "\t" + details.getCreationDate() + "\t" + details.getDirectChildQty() + "\t" + details.getDeepChildQty());
                }
            } catch (Exception e) {
                context.getExhibitor().getLog().add(ActivityLog.Type.ERROR, "Generating usage listing", e);
            } finally {
                CloseableUtils.closeQuietly(out);
            }
        }
    });
    return Response.ok(in).header("content-disposition", "attachment; filename=listing_tab_delimited.txt").build();
}
Also used : PrintStream(java.io.PrintStream) Iterator(java.util.Iterator) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) KeeperException(org.apache.zookeeper.KeeperException) UsageListing(com.netflix.exhibitor.core.analyze.UsageListing)

Example 24 with PipedInputStream

use of java.io.PipedInputStream in project cachecloud by sohutv.

the class ProtocolTest method buildACommand.

@Test
public void buildACommand() throws IOException {
    PipedInputStream pis = new PipedInputStream();
    BufferedInputStream bis = new BufferedInputStream(pis);
    PipedOutputStream pos = new PipedOutputStream(pis);
    RedisOutputStream ros = new RedisOutputStream(pos);
    Protocol.sendCommand(ros, Protocol.Command.GET, "SOMEKEY".getBytes(Protocol.CHARSET));
    ros.flush();
    pos.close();
    String expectedCommand = "*2\r\n$3\r\nGET\r\n$7\r\nSOMEKEY\r\n";
    int b;
    StringBuilder sb = new StringBuilder();
    while ((b = bis.read()) != -1) {
        sb.append((char) b);
    }
    assertEquals(expectedCommand, sb.toString());
}
Also used : BufferedInputStream(java.io.BufferedInputStream) RedisOutputStream(redis.clients.util.RedisOutputStream) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) Test(org.junit.Test)

Example 25 with PipedInputStream

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

the class StreamPumperTest method shouldNotHaveExpiredTimeoutWhenCompleted.

@Test
public void shouldNotHaveExpiredTimeoutWhenCompleted() throws Exception {
    PipedOutputStream output = new PipedOutputStream();
    InputStream inputStream = new PipedInputStream(output);
    TestingClock clock = new TestingClock();
    StreamPumper pumper = new StreamPumper(inputStream, new TestConsumer(), "", null, clock);
    new Thread(pumper).start();
    output.write("line1\n".getBytes());
    output.flush();
    output.close();
    pumper.readToEnd();
    clock.addSeconds(2);
    assertThat(pumper.didTimeout(1L, TimeUnit.SECONDS), is(false));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) PipedInputStream(java.io.PipedInputStream) InputStream(java.io.InputStream) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) TestingClock(com.thoughtworks.go.util.TestingClock) Test(org.junit.Test)

Aggregations

PipedInputStream (java.io.PipedInputStream)122 PipedOutputStream (java.io.PipedOutputStream)118 IOException (java.io.IOException)38 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 ByteArrayInputStream (java.io.ByteArrayInputStream)7 PrintStream (java.io.PrintStream)7 InputStreamReader (java.io.InputStreamReader)6 ImmutableList (com.google.common.collect.ImmutableList)5 List (java.util.List)5 ISymmetricEngine (org.jumpmind.symmetric.ISymmetricEngine)5