The code writes the random string that is assumed (and with astronomic level of probability very likely to be true) unique, no other calls to UUID.randomUUID will probably ever produce it. Probably this string is checked at another end as the "end of stream" sequence.
Most likely the designer was not able to reserve any particular char sequence to mark the end of the data stream, and for some reason could not use the usual IO methods either. It is highly unlikely that such string will appear inside the stream as well for some reason just by chance.