Code example for ByteArrayInputStream

Methods: available

0
        log = new StringWriter();
        name = "name";
    } 
 
    public void testConsumesAllAvailableInput() throws Exception { 
        InputStream source = new ByteArrayInputStream("abc".getBytes());
        assertEquals(3, source.available());
        runStreamConsumerOn(source);
        assertEquals(0, source.available());
    } 
 
    public void testWritesNameAndFullContentAfterReadingEverything() throws Exception { 
        runStreamConsumerOn(new ByteArrayInputStream("abc".getBytes()));
        assertEquals(name + ":\nabc\n", log.toString());
    } 
 
    private void runStreamConsumerOn(InputStream source) {
        new StreamConsumer(name, source, new PrintWriter(log)).run();
    } 
}