Code example for ByteArrayInputStream

Methods: available

        log = new StringWriter();
        name = "name";
    public void testConsumesAllAvailableInput() throws Exception { 
        InputStream source = new ByteArrayInputStream("abc".getBytes());
        assertEquals(3, source.available());
        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();
Connect your IDE to all the code out there  Get Codota for Java