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.
}
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));
}
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();
}
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());
}
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));
}
Aggregations