DatagramPacket.java: updated to JDK 1.4 API new methods are...
authorMichael Koch <konqueror@gmx.de>
Thu, 29 Aug 2002 18:44:42 +0000 (18:44 +0000)
committerMichael Koch <mkoch@gcc.gnu.org>
Thu, 29 Aug 2002 18:44:42 +0000 (18:44 +0000)
2002-08-29  Michael Koch  <konqueror@gmx.de>

* java/net/DatagramPacket.java: updated to JDK 1.4 API
new methods are:
DatagramPacket(byte[] buf, int offset, int length, SocketAddress
  address),
DatagramPacket(byte[] buf, int length, SocketAddress address),
void setSocketAddress(SocketAddress address)
public SocketAddress getSocketAddress()

From-SVN: r56659

libjava/ChangeLog
libjava/java/net/DatagramPacket.java

index a00a4db5f9001cf6dc72c9754820dae0b6980563..06211f11563269ed67c5adad01d3d60b5342c150 100644 (file)
@@ -1,3 +1,13 @@
+2002-08-29  Michael Koch  <konqueror@gmx.de>
+
+       * java/net/DatagramPacket.java: updated to JDK 1.4 API
+       new methods are:
+       DatagramPacket(byte[] buf, int offset, int length, SocketAddress
+         address),
+       DatagramPacket(byte[] buf, int length, SocketAddress address),
+       void setSocketAddress(SocketAddress address)
+       public SocketAddress getSocketAddress()
+
 2002-08-29  Tom Tromey  <tromey@redhat.com>
 
        * java/io/natFileDescriptorPosix.cc (setLength): Handle case where
index 2140f454f435ad8cafd1a5146763d92a2bfecc5d..d136f8424a5719107b33ad272259acff4c87b1bf 100644 (file)
@@ -186,6 +186,45 @@ public final class DatagramPacket
     this(buf, 0, length, address, port);
   }
 
+  /**
+   * Initializes a new instance of <code>DatagramPacket</code> for
+   * transmitting packets across the network.
+   *
+   * @param buf A buffer containing the data to send
+   * @param offset The offset into the buffer to start writing from.
+   * @param length The length of the buffer (must be <= buf.length)
+   * @param address The socket address to send to
+   *
+   * @exception SocketException If an error occurs
+   *
+   * @since 1.4
+   */
+  public DatagramPacket(byte[] buf, int offset, int length, SocketAddress address)
+     throws SocketException
+  {
+    this(buf, offset, length, ((InetSocketAddress)address).getAddress(),
+         ((InetSocketAddress)address).getPort());
+  }
+
+  /**
+   * Initializes a new instance of <code>DatagramPacket</code> for
+   * transmitting packets across the network.
+   *
+   * @param buf A buffer containing the data to send
+   * @param length The length of the buffer (must be <= buf.length)
+   * @param address The socket address to send to
+   *
+   * @exception SocketException If an error occurs
+   *
+   * @since 1.4
+   */
+  public DatagramPacket(byte[] buf, int length, SocketAddress address)
+    throws SocketException
+  {
+    this(buf, 0, length, ((InetSocketAddress)address).getAddress(),
+         ((InetSocketAddress)address).getPort());
+  }
+
 /**
   * Returns the address that this packet is being sent to or, if it was used
   * to receive a packet, the address that is was received from.  If the
@@ -277,6 +316,38 @@ public final class DatagramPacket
     port = iport;
   }
 
+  /**
+   * Sets the address of the remote host this package will be sent
+   *
+   * @param address The socket address of the remove host
+   *
+   * @exception IllegalArgumentException If an error occurs
+   *
+   * @since 1.4
+   */
+  public void setSocketAddress(SocketAddress address)
+    throws IllegalArgumentException
+  {
+    if (address == null) throw new IllegalArgumentException();
+
+    InetSocketAddress tmp = (InetSocketAddress)address;
+    this.address = tmp.getAddress();
+    this.port = tmp.getPort();
+  }
+
+  /**
+   * Gets the socket address of the host this packet
+   * will be sent to/is coming from
+   *
+   * @return The socket address of the remote host
+   * 
+   * @since 1.4
+   */
+  public SocketAddress getSocketAddress()
+  {
+    return new InetSocketAddress (address, port);
+  }
+
 /**
   * Sets the data buffer for this packet.
   *