UDP: Dynamic DatagramPacket buffer sizes

From what I've read of the DatagramSocket documentation, the only way to receive a DatagramPacket is to initialize the packet (and its buffer) ahead of time, and then pass it as an argument to DatagramSocket.receive(DatagramPacket).

I'm wondering why there is no option to dynamically create the DatagramPacket buffer based on the length specified in the header of the incoming packet? Since the packet length is at a well-known location it seems to me that this should be feasible (if a little less efficient).

Thanks,

JR

[549 byte] By [jrhodesa] at [2007-11-26 23:37:15]
# 1
The way it is, you can keep reusing the same DatagramPacket option for all reads (as long as you fix the length every time). Your way there would be a new packet per receive, which is wasteful.
ejpa at 2007-7-11 15:00:32 > top of Java-index,Core,Core APIs...