A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© QQ被盗 中级黑马   /  2013-12-6 11:23  /  1469 人查看  /  4 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

DatagramSocketImpl这个类是由哪些子类实现的,怎么在jdk源码库中找不到

评分

参与人数 1技术分 +1 收起 理由
狼王 + 1 赞一个!

查看全部评分

4 个回复

倒序浏览
难道这个抽象类,在哪个类中使用了匿名的形式实现?
回复 使用道具 举报
  1. /**
  2. * @(#)DatagramSocketImpl.java        1.34 06/04/26
  3. *
  4. * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */

  7. package java.net;

  8. import java.io.FileDescriptor;
  9. import java.io.IOException;
  10. import java.io.InterruptedIOException;

  11. /***
  12. * Abstract datagram and multicast socket implementation base class.
  13. * @author Pavani Diwanji
  14. * @since  JDK1.1
  15. */

  16. public abstract class DatagramSocketImpl implements SocketOptions {

  17.     /***
  18.      * The local port number.
  19.      */   
  20.     protected int localPort;

  21.     /***
  22.      * The file descriptor object.
  23.      */
  24.     protected FileDescriptor fd;

  25.     /***
  26.      * Creates a datagram socket.
  27.      * @exception SocketException if there is an error in the
  28.      * underlying protocol, such as a TCP error.
  29.      */
  30.     protected abstract void create() throws SocketException;

  31.     /***
  32.      * Binds a datagram socket to a local port and address.
  33.      * @param lport the local port
  34.      * @param laddr the local address
  35.      * @exception SocketException if there is an error in the
  36.      * underlying protocol, such as a TCP error.
  37.      */
  38.     protected abstract void bind(int lport, InetAddress laddr) throws SocketException;

  39.     /***
  40.      * Sends a datagram packet. The packet contains the data and the
  41.      * destination address to send the packet to.
  42.      * @param p the packet to be sent.
  43.      * @exception IOException if an I/O exception occurs while sending the
  44.      * datagram packet.
  45.      * @exception  PortUnreachableException may be thrown if the socket is connected
  46.      * to a currently unreachable destination. Note, there is no guarantee that
  47.      * the exception will be thrown.
  48.      */
  49.     protected abstract void send(DatagramPacket p) throws IOException;

  50.     /***
  51.      * Connects a datagram socket to a remote destination. This associates the remote
  52.      * address with the local socket so that datagrams may only be sent to this destination
  53.      * and received from this destination. This may be overridden to call a native
  54.      * system connect.
  55.      *
  56.      * <p>If the remote destination to which the socket is connected does not
  57.      * exist, or is otherwise unreachable, and if an ICMP destination unreachable
  58.      * packet has been received for that address, then a subsequent call to
  59.      * send or receive may throw a PortUnreachableException.
  60.      * Note, there is no guarantee that the exception will be thrown.
  61.      * @param address the remote InetAddress to connect to
  62.      * @param port the remote port number
  63.      * @exception   SocketException may be thrown if the socket cannot be
  64.      * connected to the remote destination
  65.      * @since 1.4
  66.      */
  67.     protected void connect(InetAddress address, int port) throws SocketException {}

  68.     /***
  69.      * Disconnects a datagram socket from its remote destination.
  70.      * @since 1.4
  71.      */
  72.     protected void disconnect() {}

  73.     /***
  74.      * Peek at the packet to see who it is from. Updates the specified <code>InetAddress</code>
  75.      * to the address which the packet came from.
  76.      * @param i an InetAddress object
  77.      * @return the port number which the packet came from.
  78.      * @exception IOException if an I/O exception occurs
  79.      * @exception  PortUnreachableException may be thrown if the socket is connected
  80.      *       to a currently unreachable destination. Note, there is no guarantee that the
  81.      *       exception will be thrown.
  82.      */
  83.     protected abstract int peek(InetAddress i) throws IOException;

  84.     /***
  85.      * Peek at the packet to see who it is from. The data is copied into the specified
  86.      * <code>DatagramPacket</code>. The data is returned,
  87.      * but not consumed, so that a subsequent peekData/receive operation
  88.      * will see the same data.
  89.      * @param p the Packet Received.
  90.      * @return the port number which the packet came from.
  91.      * @exception IOException if an I/O exception occurs
  92.      * @exception  PortUnreachableException may be thrown if the socket is connected
  93.      *       to a currently unreachable destination. Note, there is no guarantee that the
  94.      *       exception will be thrown.
  95.      * @since 1.4
  96.      */
  97.     protected abstract int peekData(DatagramPacket p) throws IOException;
  98.     /***
  99.      * Receive the datagram packet.
  100.      * @param p the Packet Received.
  101.      * @exception IOException if an I/O exception occurs
  102.      * while receiving the datagram packet.
  103.      * @exception  PortUnreachableException may be thrown if the socket is connected
  104.      *       to a currently unreachable destination. Note, there is no guarantee that the
  105.      *       exception will be thrown.
  106.      */
  107.     protected abstract void receive(DatagramPacket p) throws IOException;

  108.     /***
  109.      * Set the TTL (time-to-live) option.
  110.      * @param ttl a byte specifying the TTL value
  111.      *
  112.      * @deprecated use setTimeToLive instead.
  113.      * @exception IOException if an I/O exception occurs while setting
  114.      * the time-to-live option.
  115.      * @see #getTTL()
  116.      */
  117.     @Deprecated
  118.     protected abstract void setTTL(byte ttl) throws IOException;

  119.     /***
  120.      * Retrieve the TTL (time-to-live) option.
  121.      *
  122.      * @exception IOException if an I/O exception occurs
  123.      * while retrieving the time-to-live option
  124.      * @deprecated use getTimeToLive instead.
  125.      * @return a byte representing the TTL value
  126.      * @see #setTTL(byte)
  127.      */
  128.     @Deprecated
  129.     protected abstract byte getTTL() throws IOException;

  130.     /***
  131.      * Set the TTL (time-to-live) option.
  132.      * @param ttl an <tt>int</tt> specifying the time-to-live value
  133.      * @exception IOException if an I/O exception occurs
  134.      * while setting the time-to-live option.
  135.      * @see #getTimeToLive()
  136.      */
  137.     protected abstract void setTimeToLive(int ttl) throws IOException;

  138.     /***
  139.      * Retrieve the TTL (time-to-live) option.
  140.      * @exception IOException if an I/O exception occurs
  141.      * while retrieving the time-to-live option
  142.      * @return an <tt>int</tt> representing the time-to-live value
  143.      * @see #setTimeToLive(int)
  144.      */
  145.     protected abstract int getTimeToLive() throws IOException;

  146.     /***
  147.      * Join the multicast group.
  148.      * @param inetaddr multicast address to join.
  149.      * @exception IOException if an I/O exception occurs
  150.      * while joining the multicast group.
  151.      */
  152.     protected abstract void join(InetAddress inetaddr) throws IOException;

  153.     /***
  154.      * Leave the multicast group.
  155.      * @param inetaddr multicast address to leave.
  156.      * @exception IOException if an I/O exception occurs
  157.      * while leaving the multicast group.
  158.      */
  159.     protected abstract void leave(InetAddress inetaddr) throws IOException;

  160.     /***
  161.      * Join the multicast group.
  162.      * @param mcastaddr address to join.
  163.      * @param netIf specifies the local interface to receive multicast
  164.      *        datagram packets
  165.      * @throws IOException if an I/O exception occurs while joining
  166.      * the multicast group
  167.      * @since 1.4
  168.      */
  169.     protected abstract void joinGroup(SocketAddress mcastaddr,
  170.                                       NetworkInterface netIf)
  171.         throws IOException;

  172.     /***
  173.      * Leave the multicast group.
  174.      * @param mcastaddr address to leave.
  175.      * @param netIf specified the local interface to leave the group at
  176.      * @throws IOException if an I/O exception occurs while leaving
  177.      * the multicast group
  178.      * @since 1.4
  179.      */
  180.     protected abstract void leaveGroup(SocketAddress mcastaddr,
  181.                                        NetworkInterface netIf)
  182.         throws IOException;

  183.     /***
  184.      * Close the socket.
  185.      */
  186.     protected abstract void close();

  187.     /***
  188.      * Gets the local port.
  189.      * @return an <tt>int</tt> representing the local port value
  190.      */
  191.     protected int getLocalPort() {
  192.         return localPort;
  193.     }

  194.     /***
  195.      * Gets the datagram socket file descriptor.
  196.      * @return a <tt>FileDescriptor</tt> object representing the datagram socket
  197.      * file descriptor
  198.      */
  199.     protected FileDescriptor getFileDescriptor() {
  200.         return fd;
  201.     }
  202. }
复制代码

评分

参与人数 1技术分 +1 黑马币 +3 收起 理由
狼王 + 1 + 3 赞一个!

查看全部评分

回复 使用道具 举报
本帖最后由 lovecx24 于 2013-12-6 14:48 编辑
  1. package java.net;

  2. import java.io.FileDescriptor;
  3. import java.io.IOException;
  4. import java.io.InterruptedIOException;

  5. /***
  6. * Abstract datagram and multicast socket implementation base class.
  7. * @author Pavani Diwanji
  8. * @since  JDK1.1
  9. */

  10. public abstract class DatagramSocketImpl implements SocketOptions {

  11.     /***
  12.      * The local port number.
  13.      */  
  14.     protected int localPort;

  15.     /***
  16.      * The file descriptor object.
  17.      */
  18.     protected FileDescriptor fd;

  19.     /***
  20.      * Creates a datagram socket.
  21.      * @exception SocketException if there is an error in the
  22.      * underlying protocol, such as a TCP error.
  23.      */
  24.     protected abstract void create() throws SocketException;

  25.     /***
  26.      * Binds a datagram socket to a local port and address.
  27.      * @param lport the local port
  28.      * @param laddr the local address
  29.      * @exception SocketException if there is an error in the
  30.      * underlying protocol, such as a TCP error.
  31.      */
  32.     protected abstract void bind(int lport, InetAddress laddr) throws SocketException;

  33.     /***
  34.      * Sends a datagram packet. The packet contains the data and the
  35.      * destination address to send the packet to.
  36.      * @param p the packet to be sent.
  37.      * @exception IOException if an I/O exception occurs while sending the
  38.      * datagram packet.
  39.      * @exception  PortUnreachableException may be thrown if the socket is connected
  40.      * to a currently unreachable destination. Note, there is no guarantee that
  41.      * the exception will be thrown.
  42.      */
  43.     protected abstract void send(DatagramPacket p) throws IOException;

  44.     /***
  45.      * Connects a datagram socket to a remote destination. This associates the remote
  46.      * address with the local socket so that datagrams may only be sent to this destination
  47.      * and received from this destination. This may be overridden to call a native
  48.      * system connect.
  49.      *
  50.      * <p>If the remote destination to which the socket is connected does not
  51.      * exist, or is otherwise unreachable, and if an ICMP destination unreachable
  52.      * packet has been received for that address, then a subsequent call to
  53.      * send or receive may throw a PortUnreachableException.
  54.      * Note, there is no guarantee that the exception will be thrown.
  55.      * @param address the remote InetAddress to connect to
  56.      * @param port the remote port number
  57.      * @exception   SocketException may be thrown if the socket cannot be
  58.      * connected to the remote destination
  59.      * @since 1.4
  60.      */
  61.     protected void connect(InetAddress address, int port) throws SocketException {}

  62.     /***
  63.      * Disconnects a datagram socket from its remote destination.
  64.      * @since 1.4
  65.      */


  66.     /***
  67.      * Peek at the packet to see who it is from. Updates the specified <code>InetAddress</code>
  68.      * to the address which the packet came from.
  69.      * @param i an InetAddress object
  70.      * @return the port number which the packet came from.
  71.      * @exception IOException if an I/O exception occurs
  72.      * @exception  PortUnreachableException may be thrown if the socket is connected
  73.      *       to a currently unreachable destination. Note, there is no guarantee that the
  74.      *       exception will be thrown.

  75.      */
  76.     protected abstract int peek(InetAddress i) throws IOException;

  77.     /***
  78.      * Peek at the packet to see who it is from. The data is copied into the specified
  79.      * <code>DatagramPacket</code>. The data is returned,
  80.      * but not consumed, so that a subsequent peekData/receive operation
  81.      * @param p the Packet Received.
  82.      * @exception IOException if an I/O exception occurs
  83.      * @exception  PortUnreachableException may be thrown if the socket is connected
  84.      *       to a currently unreachable destination. Note, there is no guarantee that the
  85.      *       exception will be thrown.
  86.      * @since 1.4
  87.      */
  88.     protected abstract int peekData(DatagramPacket p) throws IOException;
  89.     /***
  90.      * Receive the datagram packet.
  91.      * @param p the Packet Received.
  92.      * @exception IOException if an I/O exception occurs
  93.      * while receiving the datagram packet.
  94.      *       to a currently unreachable destination. Note, there is no guarantee that the
  95.      *       exception will be thrown.
  96.      */
  97.     protected abstract void receive(DatagramPacket p) throws IOException;
  98.     /***
  99.      * Set the TTL (time-to-live) option.
  100.      * @param ttl a byte specifying the TTL value
  101.      *
  102.      * @deprecated use setTimeToLive instead.
  103.      * @exception IOException if an I/O exception occurs while setting
  104.      * the time-to-live option.
  105.      * @see #getTTL()
  106.      */
  107.     @Deprecated
  108.     protected abstract void setTTL(byte ttl) throws IOException;
  109.     /***
  110.      * Retrieve the TTL (time-to-live) option.
  111.      *
  112.      * @exception IOException if an I/O exception occurs
  113.      * while retrieving the time-to-live option
  114.      * @deprecated use getTimeToLive instead.
  115.      * @return a byte representing the TTL value
  116.      * @see #setTTL(byte)
  117.      */
  118.     @Deprecated
  119.     protected abstract byte getTTL() throws IOException;
  120.     /***
  121.      * Set the TTL (time-to-live) option.
  122.      * @param ttl an <tt>int</tt> specifying the time-to-live value
  123.      * @exception IOException if an I/O exception occurs
  124.      * while setting the time-to-live option.
  125.      * @see #getTimeToLive()
  126.      */
  127.     protected abstract void setTimeToLive(int ttl) throws IOException;
  128.     /***
  129.      * Retrieve the TTL (time-to-live) option.
  130.      * @exception IOException if an I/O exception occurs
  131.      * while retrieving the time-to-live option
  132.      * @return an <tt>int</tt> representing the time-to-live value
  133.      */
  134.     protected abstract int getTimeToLive() throws IOException;

  135.     /***
  136.      * Join the multicast group.
  137.      * @param inetaddr multicast address to join.
  138.      * @exception IOException if an I/O exception occurs
  139.      */
  140.     protected abstract void join(InetAddress inetaddr) throws IOException;
  141.     /***
  142.      * Leave the multicast group.
  143.      * @exception IOException if an I/O exception occurs
  144.      * while leaving the multicast group.
  145.      */
  146.     protected abstract void leave(InetAddress inetaddr) throws IOException;

  147.     /***
  148.      * Join the multicast group.
  149.      * @param mcastaddr address to join.
  150.      * @param netIf specifies the local interface to receive multicast
  151.      *        datagram packets
  152.      * @throws IOException if an I/O exception occurs while joining
  153.      * @since 1.4
  154.     protected abstract void joinGroup(SocketAddress mcastaddr,
  155.                       NetworkInterface netIf)
  156.     throws IOException;

  157.     /***
  158.      * Leave the multicast group.
  159.      * @param mcastaddr address to leave.
  160.      * @param netIf specified the local interface to leave the group at
  161.      * @throws IOException if an I/O exception occurs while leaving
  162.      * the multicast group
  163.      * @since 1.4
  164.      */
  165.     protected abstract void leaveGroup(SocketAddress mcastaddr,
  166.                        NetworkInterface netIf)
  167.     throws IOException;
  168.     /***
  169.      * Close the socket.
  170.      */
  171.     protected abstract void close();
  172.     /***
  173.      * Gets the local port.
  174.      */
  175.     protected int getLocalPort() {
  176.     return localPort;
  177.     }

  178.     /***
  179.      * Gets the datagram socket file descriptor.
  180.      * @return a <tt>FileDescriptor</tt> object representing the datagram socket
  181.      * file descriptor
  182.      */
  183.     protected FileDescriptor getFileDescriptor() {
  184.     return fd;
  185.     }
  186. }
复制代码

评分

参与人数 1技术分 +1 黑马币 +3 收起 理由
狼王 + 1 + 3 很给力!

查看全部评分

回复 使用道具 举报
DatagramSocketImpl类和Iterator类使用一样的,都是内部类的父类,在内部类(或匿名内部类)中覆盖它的方法;所以看不到它的实现类;

评分

参与人数 1黑马币 +9 收起 理由
狼王 + 9 赞一个!

查看全部评分

回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马