The DataOutputStream
only requires any implementation of an OutputStream
in its constructor. It doesn't care how it's implemented only that it satisfies the interface. A ByteArrayOutputStream
provides an output stream backed by a byte array. Similarly, you could use a FileOutputStream
to get a stream backed by a file on disk. From the DataOutputStream
's perspective, they are both streams that used with an interface. OutputStream
is a really simple interface, and just defines some methods that write byte arrays to some kind of storage device.
There's no magic going on under the scenes, it just uses an OutputStream
and doesn't care how it's implemented.