Code example for ByteArrayInputStream

Methods: available, read

0
        os = new java.io.BufferedOutputStream(baos);
        os.write('t');
        bais = new java.io.ByteArrayInputStream(baos.toByteArray());
        assertEquals("Byte written, not buffered", 0, bais.available());
        os.flush();
        bais = new java.io.ByteArrayInputStream(baos.toByteArray());
        assertEquals("Byte not written after flush", 1, bais.available());
        byte[] wbytes = new byte[1];
        bais.read(wbytes, 0, 1);
        assertEquals("Incorrect byte written", 't', wbytes[0]);
    } 
 
    public void test_write_Close() throws IOException { 
        BufferedOutputStream buffos = new BufferedOutputStream(
                new ByteArrayOutputStream());
        buffos.write(new byte[0]);
        try { 
            buffos.write(null);
            fail("should throw NullPointerException");
        } catch (NullPointerException e) {
            // Expected