but how do the data get in the buffer?
Something sent a UDP packet. That something made the data available for parsePacket() (stupid name) to copy to a buffer. parsePacket() then tells you how much data is in the buffer, and read() gets the data from the buffer into your array.