ByteArrayInputStream and ByteArrayOutputStream is what you are looking for.
These are implementations of the interfaces InputStream and OutputStream that read from and write to a byte array in memory. For ByteArrayOutputStream, the array will grow automatically as you write data to the stream.