Code example for ByteArrayInputStream

Methods: available, read

0
        assertEquals("Bytes written, not buffered", 0, bais.available());
        os.flush();
        bais = new ByteArrayInputStream(baos.toByteArray());
        assertEquals("Bytes not written after flush", 500, bais.available());
        os.write(fileString.getBytes(), 500, 513);
        bais = new ByteArrayInputStream(baos.toByteArray());
        assertTrue("Bytes not written when buffer full",
                bais.available() >= 1000);
        byte[] wbytes = new byte[1013];
        bais.read(wbytes, 0, 1013);
        assertEquals("Incorrect bytes written", new String(wbytes, 0,
                wbytes.length), fileString.substring(0, 1013));
 
        // regression test for HARMONY-4177 
        MockOutputStream mos = new MockOutputStream(5);
        BufferedOutputStream bos = new BufferedOutputStream(mos, 3);
        bos.write("a".getBytes());
        bos.write("bcde".getBytes());
        assertEquals("Large data should be written directly", "abcde", mos
                .getWritten()); 
        mos = new MockOutputStream(4);