java.nio.channels.UnsupportedAddressTypeException源码实例Demo

类java.nio.channels.UnsupportedAddressTypeException源码实例Demo

下面列出了java.nio.channels.UnsupportedAddressTypeException 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: dragonwell8_jdk   文件: JdpBroadcaster.java
/**
 * Create a new broadcaster
 *
 * @param address - multicast group address
 * @param srcAddress - address of interface we should use to broadcast.
 * @param port - udp port to use
 * @param ttl - packet ttl
 * @throws IOException
 */
public JdpBroadcaster(InetAddress address, InetAddress srcAddress, int port, int ttl)
        throws IOException, JdpException {
    this.addr = address;
    this.port = port;

    ProtocolFamily family = (address instanceof Inet6Address)
            ? StandardProtocolFamily.INET6 : StandardProtocolFamily.INET;

    channel = DatagramChannel.open(family);
    channel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
    channel.setOption(StandardSocketOptions.IP_MULTICAST_TTL, ttl);

    // with srcAddress equal to null, this constructor do exactly the same as
    // if srcAddress is not passed
    if (srcAddress != null) {
        // User requests particular interface to bind to
        NetworkInterface interf = NetworkInterface.getByInetAddress(srcAddress);
        try {
            channel.bind(new InetSocketAddress(srcAddress, 0));
        } catch (UnsupportedAddressTypeException ex) {
            throw new JdpException("Unable to bind to source address");
        }
        channel.setOption(StandardSocketOptions.IP_MULTICAST_IF, interf);
    }
}
 
源代码2 项目: TencentKona-8   文件: JdpBroadcaster.java
/**
 * Create a new broadcaster
 *
 * @param address - multicast group address
 * @param srcAddress - address of interface we should use to broadcast.
 * @param port - udp port to use
 * @param ttl - packet ttl
 * @throws IOException
 */
public JdpBroadcaster(InetAddress address, InetAddress srcAddress, int port, int ttl)
        throws IOException, JdpException {
    this.addr = address;
    this.port = port;

    ProtocolFamily family = (address instanceof Inet6Address)
            ? StandardProtocolFamily.INET6 : StandardProtocolFamily.INET;

    channel = DatagramChannel.open(family);
    channel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
    channel.setOption(StandardSocketOptions.IP_MULTICAST_TTL, ttl);

    // with srcAddress equal to null, this constructor do exactly the same as
    // if srcAddress is not passed
    if (srcAddress != null) {
        // User requests particular interface to bind to
        NetworkInterface interf = NetworkInterface.getByInetAddress(srcAddress);
        try {
            channel.bind(new InetSocketAddress(srcAddress, 0));
        } catch (UnsupportedAddressTypeException ex) {
            throw new JdpException("Unable to bind to source address");
        }
        channel.setOption(StandardSocketOptions.IP_MULTICAST_IF, interf);
    }
}
 
源代码3 项目: jdk8u60   文件: JdpBroadcaster.java
/**
 * Create a new broadcaster
 *
 * @param address - multicast group address
 * @param srcAddress - address of interface we should use to broadcast.
 * @param port - udp port to use
 * @param ttl - packet ttl
 * @throws IOException
 */
public JdpBroadcaster(InetAddress address, InetAddress srcAddress, int port, int ttl)
        throws IOException, JdpException {
    this.addr = address;
    this.port = port;

    ProtocolFamily family = (address instanceof Inet6Address)
            ? StandardProtocolFamily.INET6 : StandardProtocolFamily.INET;

    channel = DatagramChannel.open(family);
    channel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
    channel.setOption(StandardSocketOptions.IP_MULTICAST_TTL, ttl);

    // with srcAddress equal to null, this constructor do exactly the same as
    // if srcAddress is not passed
    if (srcAddress != null) {
        // User requests particular interface to bind to
        NetworkInterface interf = NetworkInterface.getByInetAddress(srcAddress);
        try {
            channel.bind(new InetSocketAddress(srcAddress, 0));
        } catch (UnsupportedAddressTypeException ex) {
            throw new JdpException("Unable to bind to source address");
        }
        channel.setOption(StandardSocketOptions.IP_MULTICAST_IF, interf);
    }
}
 
源代码4 项目: openjdk-jdk8u   文件: JdpBroadcaster.java
/**
 * Create a new broadcaster
 *
 * @param address - multicast group address
 * @param srcAddress - address of interface we should use to broadcast.
 * @param port - udp port to use
 * @param ttl - packet ttl
 * @throws IOException
 */
public JdpBroadcaster(InetAddress address, InetAddress srcAddress, int port, int ttl)
        throws IOException, JdpException {
    this.addr = address;
    this.port = port;

    ProtocolFamily family = (address instanceof Inet6Address)
            ? StandardProtocolFamily.INET6 : StandardProtocolFamily.INET;

    channel = DatagramChannel.open(family);
    channel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
    channel.setOption(StandardSocketOptions.IP_MULTICAST_TTL, ttl);

    // with srcAddress equal to null, this constructor do exactly the same as
    // if srcAddress is not passed
    if (srcAddress != null) {
        // User requests particular interface to bind to
        NetworkInterface interf = NetworkInterface.getByInetAddress(srcAddress);
        try {
            channel.bind(new InetSocketAddress(srcAddress, 0));
        } catch (UnsupportedAddressTypeException ex) {
            throw new JdpException("Unable to bind to source address");
        }
        channel.setOption(StandardSocketOptions.IP_MULTICAST_IF, interf);
    }
}
 
源代码5 项目: openjdk-jdk8u-backup   文件: JdpBroadcaster.java
/**
 * Create a new broadcaster
 *
 * @param address - multicast group address
 * @param srcAddress - address of interface we should use to broadcast.
 * @param port - udp port to use
 * @param ttl - packet ttl
 * @throws IOException
 */
public JdpBroadcaster(InetAddress address, InetAddress srcAddress, int port, int ttl)
        throws IOException, JdpException {
    this.addr = address;
    this.port = port;

    ProtocolFamily family = (address instanceof Inet6Address)
            ? StandardProtocolFamily.INET6 : StandardProtocolFamily.INET;

    channel = DatagramChannel.open(family);
    channel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
    channel.setOption(StandardSocketOptions.IP_MULTICAST_TTL, ttl);

    // with srcAddress equal to null, this constructor do exactly the same as
    // if srcAddress is not passed
    if (srcAddress != null) {
        // User requests particular interface to bind to
        NetworkInterface interf = NetworkInterface.getByInetAddress(srcAddress);
        try {
            channel.bind(new InetSocketAddress(srcAddress, 0));
        } catch (UnsupportedAddressTypeException ex) {
            throw new JdpException("Unable to bind to source address");
        }
        channel.setOption(StandardSocketOptions.IP_MULTICAST_IF, interf);
    }
}
 
源代码6 项目: Bytecoder   文件: NativeSocketAddress.java
/**
 * Encodes the given InetSocketAddress into this socket address.
 * @param protocolFamily protocol family
 * @param isa the InetSocketAddress to encode
 * @return the size of the socket address (sizeof sockaddr or sockaddr6)
 * @throws UnsupportedAddressTypeException if the address type is not supported
 */
int encode(ProtocolFamily protocolFamily, InetSocketAddress isa) {
    if (protocolFamily == StandardProtocolFamily.INET) {
        // struct sockaddr
        InetAddress ia = isa.getAddress();
        if (!(ia instanceof Inet4Address))
            throw new UnsupportedAddressTypeException();
        putFamily(AF_INET);
        putAddress(AF_INET, ia);
        putPort(AF_INET, isa.getPort());
        return SIZEOF_SOCKADDR4;
    } else {
        // struct sockaddr6
        putFamily(AF_INET6);
        putAddress(AF_INET6, isa.getAddress());
        putPort(AF_INET6, isa.getPort());
        UNSAFE.putInt(address + OFFSET_SIN6_FLOWINFO, 0);
        return SIZEOF_SOCKADDR6;
    }
}
 
源代码7 项目: jdk8u-jdk   文件: JdpBroadcaster.java
/**
 * Create a new broadcaster
 *
 * @param address - multicast group address
 * @param srcAddress - address of interface we should use to broadcast.
 * @param port - udp port to use
 * @param ttl - packet ttl
 * @throws IOException
 */
public JdpBroadcaster(InetAddress address, InetAddress srcAddress, int port, int ttl)
        throws IOException, JdpException {
    this.addr = address;
    this.port = port;

    ProtocolFamily family = (address instanceof Inet6Address)
            ? StandardProtocolFamily.INET6 : StandardProtocolFamily.INET;

    channel = DatagramChannel.open(family);
    channel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
    channel.setOption(StandardSocketOptions.IP_MULTICAST_TTL, ttl);

    // with srcAddress equal to null, this constructor do exactly the same as
    // if srcAddress is not passed
    if (srcAddress != null) {
        // User requests particular interface to bind to
        NetworkInterface interf = NetworkInterface.getByInetAddress(srcAddress);
        try {
            channel.bind(new InetSocketAddress(srcAddress, 0));
        } catch (UnsupportedAddressTypeException ex) {
            throw new JdpException("Unable to bind to source address");
        }
        channel.setOption(StandardSocketOptions.IP_MULTICAST_IF, interf);
    }
}
 
源代码8 项目: hottub   文件: JdpBroadcaster.java
/**
 * Create a new broadcaster
 *
 * @param address - multicast group address
 * @param srcAddress - address of interface we should use to broadcast.
 * @param port - udp port to use
 * @param ttl - packet ttl
 * @throws IOException
 */
public JdpBroadcaster(InetAddress address, InetAddress srcAddress, int port, int ttl)
        throws IOException, JdpException {
    this.addr = address;
    this.port = port;

    ProtocolFamily family = (address instanceof Inet6Address)
            ? StandardProtocolFamily.INET6 : StandardProtocolFamily.INET;

    channel = DatagramChannel.open(family);
    channel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
    channel.setOption(StandardSocketOptions.IP_MULTICAST_TTL, ttl);

    // with srcAddress equal to null, this constructor do exactly the same as
    // if srcAddress is not passed
    if (srcAddress != null) {
        // User requests particular interface to bind to
        NetworkInterface interf = NetworkInterface.getByInetAddress(srcAddress);
        try {
            channel.bind(new InetSocketAddress(srcAddress, 0));
        } catch (UnsupportedAddressTypeException ex) {
            throw new JdpException("Unable to bind to source address");
        }
        channel.setOption(StandardSocketOptions.IP_MULTICAST_IF, interf);
    }
}
 
源代码9 项目: openjdk-8-source   文件: JdpBroadcaster.java
/**
 * Create a new broadcaster
 *
 * @param address - multicast group address
 * @param srcAddress - address of interface we should use to broadcast.
 * @param port - udp port to use
 * @param ttl - packet ttl
 * @throws IOException
 */
public JdpBroadcaster(InetAddress address, InetAddress srcAddress, int port, int ttl)
        throws IOException, JdpException {
    this.addr = address;
    this.port = port;

    ProtocolFamily family = (address instanceof Inet6Address)
            ? StandardProtocolFamily.INET6 : StandardProtocolFamily.INET;

    channel = DatagramChannel.open(family);
    channel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
    channel.setOption(StandardSocketOptions.IP_MULTICAST_TTL, ttl);

    // with srcAddress equal to null, this constructor do exactly the same as
    // if srcAddress is not passed
    if (srcAddress != null) {
        // User requests particular interface to bind to
        NetworkInterface interf = NetworkInterface.getByInetAddress(srcAddress);
        try {
            channel.bind(new InetSocketAddress(srcAddress, 0));
        } catch (UnsupportedAddressTypeException ex) {
            throw new JdpException("Unable to bind to source address");
        }
        channel.setOption(StandardSocketOptions.IP_MULTICAST_IF, interf);
    }
}
 
源代码10 项目: openjdk-8   文件: JdpBroadcaster.java
/**
 * Create a new broadcaster
 *
 * @param address - multicast group address
 * @param srcAddress - address of interface we should use to broadcast.
 * @param port - udp port to use
 * @param ttl - packet ttl
 * @throws IOException
 */
public JdpBroadcaster(InetAddress address, InetAddress srcAddress, int port, int ttl)
        throws IOException, JdpException {
    this.addr = address;
    this.port = port;

    ProtocolFamily family = (address instanceof Inet6Address)
            ? StandardProtocolFamily.INET6 : StandardProtocolFamily.INET;

    channel = DatagramChannel.open(family);
    channel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
    channel.setOption(StandardSocketOptions.IP_MULTICAST_TTL, ttl);

    // with srcAddress equal to null, this constructor do exactly the same as
    // if srcAddress is not passed
    if (srcAddress != null) {
        // User requests particular interface to bind to
        NetworkInterface interf = NetworkInterface.getByInetAddress(srcAddress);
        try {
            channel.bind(new InetSocketAddress(srcAddress, 0));
        } catch (UnsupportedAddressTypeException ex) {
            throw new JdpException("Unable to bind to source address");
        }
        channel.setOption(StandardSocketOptions.IP_MULTICAST_IF, interf);
    }
}
 
源代码11 项目: jdk8u_jdk   文件: JdpBroadcaster.java
/**
 * Create a new broadcaster
 *
 * @param address - multicast group address
 * @param srcAddress - address of interface we should use to broadcast.
 * @param port - udp port to use
 * @param ttl - packet ttl
 * @throws IOException
 */
public JdpBroadcaster(InetAddress address, InetAddress srcAddress, int port, int ttl)
        throws IOException, JdpException {
    this.addr = address;
    this.port = port;

    ProtocolFamily family = (address instanceof Inet6Address)
            ? StandardProtocolFamily.INET6 : StandardProtocolFamily.INET;

    channel = DatagramChannel.open(family);
    channel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
    channel.setOption(StandardSocketOptions.IP_MULTICAST_TTL, ttl);

    // with srcAddress equal to null, this constructor do exactly the same as
    // if srcAddress is not passed
    if (srcAddress != null) {
        // User requests particular interface to bind to
        NetworkInterface interf = NetworkInterface.getByInetAddress(srcAddress);
        try {
            channel.bind(new InetSocketAddress(srcAddress, 0));
        } catch (UnsupportedAddressTypeException ex) {
            throw new JdpException("Unable to bind to source address");
        }
        channel.setOption(StandardSocketOptions.IP_MULTICAST_IF, interf);
    }
}
 
源代码12 项目: jdk8u-jdk   文件: JdpBroadcaster.java
/**
 * Create a new broadcaster
 *
 * @param address - multicast group address
 * @param srcAddress - address of interface we should use to broadcast.
 * @param port - udp port to use
 * @param ttl - packet ttl
 * @throws IOException
 */
public JdpBroadcaster(InetAddress address, InetAddress srcAddress, int port, int ttl)
        throws IOException, JdpException {
    this.addr = address;
    this.port = port;

    ProtocolFamily family = (address instanceof Inet6Address)
            ? StandardProtocolFamily.INET6 : StandardProtocolFamily.INET;

    channel = DatagramChannel.open(family);
    channel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
    channel.setOption(StandardSocketOptions.IP_MULTICAST_TTL, ttl);

    // with srcAddress equal to null, this constructor do exactly the same as
    // if srcAddress is not passed
    if (srcAddress != null) {
        // User requests particular interface to bind to
        NetworkInterface interf = NetworkInterface.getByInetAddress(srcAddress);
        try {
            channel.bind(new InetSocketAddress(srcAddress, 0));
        } catch (UnsupportedAddressTypeException ex) {
            throw new JdpException("Unable to bind to source address");
        }
        channel.setOption(StandardSocketOptions.IP_MULTICAST_IF, interf);
    }
}
 
源代码13 项目: jdk8u-dev-jdk   文件: JdpBroadcaster.java
/**
 * Create a new broadcaster
 *
 * @param address - multicast group address
 * @param srcAddress - address of interface we should use to broadcast.
 * @param port - udp port to use
 * @param ttl - packet ttl
 * @throws IOException
 */
public JdpBroadcaster(InetAddress address, InetAddress srcAddress, int port, int ttl)
        throws IOException, JdpException {
    this.addr = address;
    this.port = port;

    ProtocolFamily family = (address instanceof Inet6Address)
            ? StandardProtocolFamily.INET6 : StandardProtocolFamily.INET;

    channel = DatagramChannel.open(family);
    channel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
    channel.setOption(StandardSocketOptions.IP_MULTICAST_TTL, ttl);

    // with srcAddress equal to null, this constructor do exactly the same as
    // if srcAddress is not passed
    if (srcAddress != null) {
        // User requests particular interface to bind to
        NetworkInterface interf = NetworkInterface.getByInetAddress(srcAddress);
        try {
            channel.bind(new InetSocketAddress(srcAddress, 0));
        } catch (UnsupportedAddressTypeException ex) {
            throw new JdpException("Unable to bind to source address");
        }
        channel.setOption(StandardSocketOptions.IP_MULTICAST_IF, interf);
    }
}
 
源代码14 项目: j2objc   文件: DatagramChannelTest.java
/**
 * Test method for 'DatagramChannelImpl.connect(SocketAddress)'
 */
public void testConnect_UnsupportedType() throws IOException {
    assertFalse(this.channel1.isConnected());
    class SubSocketAddress extends SocketAddress {
        private static final long serialVersionUID = 1L;

        public SubSocketAddress() {
            super();
        }
    }
    SocketAddress newTypeAddress = new SubSocketAddress();
    try {
        this.channel1.connect(newTypeAddress);
        fail("Should throw an UnsupportedAddressTypeException here.");
    } catch (UnsupportedAddressTypeException e) {
        // OK.
    }
}
 
源代码15 项目: j2objc   文件: SocketChannelTest.java
public void testCFII_UnsupportedType() throws Exception {
    class SubSocketAddress extends SocketAddress {
        private static final long serialVersionUID = 1L;

        //empty
        public SubSocketAddress() {
            super();
        }
    }
    statusNotConnected_NotPending();
    SocketAddress newTypeAddress = new SubSocketAddress();
    try {
        this.channel1.connect(newTypeAddress);
        fail("Should throw an UnsupportedAddressTypeException here.");
    } catch (UnsupportedAddressTypeException e) {
        // OK.
    }
}
 
源代码16 项目: netty-4.1.22   文件: AbstractAddressResolver.java
@Override
public final boolean isResolved(SocketAddress address) {
    if (!isSupported(address)) {
        throw new UnsupportedAddressTypeException();
    }

    @SuppressWarnings("unchecked")
    final T castAddress = (T) address;
    return doIsResolved(castAddress);
}
 
源代码17 项目: Bytecoder   文件: Net.java
public static InetSocketAddress checkAddress(SocketAddress sa) {
    if (sa == null)
        throw new NullPointerException();
    if (!(sa instanceof InetSocketAddress))
        throw new UnsupportedAddressTypeException(); // ## needs arg
    InetSocketAddress isa = (InetSocketAddress)sa;
    if (isa.isUnresolved())
        throw new UnresolvedAddressException(); // ## needs arg
    InetAddress addr = isa.getAddress();
    if (!(addr instanceof Inet4Address || addr instanceof Inet6Address))
        throw new IllegalArgumentException("Invalid address type");
    return isa;
}
 
源代码18 项目: Bytecoder   文件: Net.java
static InetSocketAddress checkAddress(SocketAddress sa, ProtocolFamily family) {
    InetSocketAddress isa = checkAddress(sa);
    if (family == StandardProtocolFamily.INET) {
        InetAddress addr = isa.getAddress();
        if (!(addr instanceof Inet4Address))
            throw new UnsupportedAddressTypeException();
    }
    return isa;
}
 
源代码19 项目: openjdk-jdk9   文件: JdpBroadcaster.java
/**
 * Create a new broadcaster
 *
 * @param address - multicast group address
 * @param srcAddress - address of interface we should use to broadcast.
 * @param port - udp port to use
 * @param ttl - packet ttl
 * @throws IOException
 */
public JdpBroadcaster(InetAddress address, InetAddress srcAddress, int port, int ttl)
        throws IOException, JdpException {
    this.addr = address;
    this.port = port;

    ProtocolFamily family = (address instanceof Inet6Address)
            ? StandardProtocolFamily.INET6 : StandardProtocolFamily.INET;

    channel = DatagramChannel.open(family);
    channel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
    channel.setOption(StandardSocketOptions.IP_MULTICAST_TTL, ttl);

    // with srcAddress equal to null, this constructor do exactly the same as
    // if srcAddress is not passed
    if (srcAddress != null) {
        // User requests particular interface to bind to
        NetworkInterface interf = NetworkInterface.getByInetAddress(srcAddress);

        if (interf == null) {
            throw new JdpException("Unable to get network interface for " + srcAddress.toString());
        }

        if (!interf.isUp()) {
            throw new JdpException(interf.getName() + " is not up.");
        }

        if (!interf.supportsMulticast()) {
            throw new JdpException(interf.getName() + " does not support multicast.");
        }

        try {
            channel.bind(new InetSocketAddress(srcAddress, 0));
        } catch (UnsupportedAddressTypeException ex) {
            throw new JdpException("Unable to bind to source address");
        }
        channel.setOption(StandardSocketOptions.IP_MULTICAST_IF, interf);
    }
}
 
源代码20 项目: TorrentEngine   文件: NetworkAdmin.java
public InetAddress getSingleHomedServiceBindAddress(int proto)
{
	InetAddress[] addrs = currentBindIPs;
	if(proto == IP_PROTOCOL_VERSION_AUTO){
		return addrs[0];
	}else{
		for( InetAddress addr: addrs ){

			if( (proto == IP_PROTOCOL_VERSION_REQUIRE_V4 && addr instanceof Inet4Address || addr.isAnyLocalAddress()) ||
				(proto == IP_PROTOCOL_VERSION_REQUIRE_V6 && addr instanceof Inet6Address) ){

				if ( addr.isAnyLocalAddress()){

					if ( proto == IP_PROTOCOL_VERSION_REQUIRE_V4 ){

						return( anyLocalAddressIPv4 );

					}else{

						return( anyLocalAddressIPv6 );
					}
				}else{

					return( addr );
				}
			}
		}
	}

	throw new UnsupportedAddressTypeException();
}
 
源代码21 项目: kylin   文件: TCPMemcachedNodeImpl.java
public final SocketAddress getSocketAddress() {
    if (!(socketAddress instanceof InetSocketAddress)) {
        throw new UnsupportedAddressTypeException();
    }
    InetSocketAddress inetSocketAddress = (InetSocketAddress) socketAddress;
    return new InetSocketAddress(inetSocketAddress.getHostName(), inetSocketAddress.getPort());
}
 
/**
 * @tests {@link java.nio.channels.UnsupportedAddressTypeException#UnsupportedAddressTypeException()}
 */
public void test_Constructor() {
    UnsupportedAddressTypeException e = new UnsupportedAddressTypeException();
    assertNull(e.getMessage());
    assertNull(e.getLocalizedMessage());
    assertNull(e.getCause());
}
 
源代码23 项目: Bytecoder   文件: Net.java
static InetSocketAddress asInetSocketAddress(SocketAddress sa) {
    if (!(sa instanceof InetSocketAddress))
        throw new UnsupportedAddressTypeException();
    return (InetSocketAddress)sa;
}
 
源代码24 项目: BiglyBT   文件: NetworkAdminImpl.java
@Override
public InetAddress getSingleHomedServiceBindAddress(int proto)
{
	InetAddress[] addrs = currentBindIPs;
	
	if ( proto == IP_PROTOCOL_VERSION_AUTO ){
		
			// don't try and do anything smart here regarding converting an 'any local address' into either
			// anyLocalAddressIPv4 or anyLocalAddressIPv6 depending on preferv6 or supportsV6 because this stuffs
			// up other code in PRUDPPacketHandlerImpl creating 'alt-protocol-delegates' Don't ask me...
		
		return( addrs[0] );
		
	}else{
		
		for( InetAddress addr: addrs ){

			if( (proto == IP_PROTOCOL_VERSION_REQUIRE_V4 && addr instanceof Inet4Address || addr.isAnyLocalAddress()) ||
				(proto == IP_PROTOCOL_VERSION_REQUIRE_V6 && addr instanceof Inet6Address) ){

				if ( addr.isAnyLocalAddress()){

					if ( proto == IP_PROTOCOL_VERSION_REQUIRE_V4 ){

						return( anyLocalAddressIPv4 );

					}else{

						return( anyLocalAddressIPv6 );
					}
				}else{

					return( addr );
				}
			}
		}
	}

	throw(
			new UnsupportedAddressTypeException(){
				public String
				getMessage()
				{
					return(	"No bind address for " + (proto == IP_PROTOCOL_VERSION_REQUIRE_V4?"IPv4":"IPv6" ));
				}
			});
}
 
源代码25 项目: TorrentEngine   文件: PRUDPPacketHandlerImpl.java
protected void
calcBind()
{
	if ( explicit_bind_ip != null ){

		if(altProtocolDelegate != null)
		{
			altProtocolDelegate.destroy();
			altProtocolDelegate = null;
		}

		target_bind_ip = explicit_bind_ip;

	}else{

		InetAddress altAddress = null;
		NetworkAdmin adm = NetworkAdmin.getSingleton();
		try
		{
			if (default_bind_ip instanceof Inet6Address && !default_bind_ip.isAnyLocalAddress() && adm.hasIPV4Potential())
				altAddress = adm.getSingleHomedServiceBindAddress(NetworkAdmin.IP_PROTOCOL_VERSION_REQUIRE_V4);
			else if (default_bind_ip instanceof Inet4Address && adm.hasIPV6Potential())
				altAddress = adm.getSingleHomedServiceBindAddress(NetworkAdmin.IP_PROTOCOL_VERSION_REQUIRE_V6);
		} catch (UnsupportedAddressTypeException e)
		{
		}

		if(altProtocolDelegate != null && !altProtocolDelegate.explicit_bind_ip.equals(altAddress))
		{
			altProtocolDelegate.destroy();
			altProtocolDelegate = null;
		}

		if(altAddress != null && altProtocolDelegate == null)
		{
			altProtocolDelegate = new PRUDPPacketHandlerImpl(port,altAddress,packet_transformer);
			altProtocolDelegate.stats = stats;
			altProtocolDelegate.primordial_handlers = primordial_handlers;
			altProtocolDelegate.request_handler = request_handler;
		}


		target_bind_ip = default_bind_ip;
	}
}
 
源代码26 项目: sarl   文件: AbstractXmlHighlightingFragment2.java
@Override
public void appendHeader() {
	throw new UnsupportedAddressTypeException();
}
 
/**
 * @tests serialization/deserialization compatibility.
 */
public void testSerializationSelf() throws Exception {

    SerializationTest.verifySelf(new UnsupportedAddressTypeException());
}
 
/**
 * @tests serialization/deserialization compatibility with RI.
 */
public void testSerializationCompatibility() throws Exception {

    SerializationTest.verifyGolden(this,
            new UnsupportedAddressTypeException());
}
 
源代码29 项目: BiglyBT   文件: NetworkAdmin.java
/**
 * @throws UnsupportedAddressTypeException when no address matching the v4/v6 requirements is found, always returns an address when auto is selected
 */
public abstract InetAddress
getSingleHomedServiceBindAddress(int protocolVersion) throws UnsupportedAddressTypeException;
 
源代码30 项目: BiglyBT   文件: NetworkAdmin.java
/**
 * Selects a bind address based on available host address and bind protocol families
 * 
 * @param host
 * @return Array with 2 entries, first is selected host address, second is selected bind address (possibly null of course)
 */
public abstract InetAddress[]
getSingleHomedServiceBinding( String host ) throws UnknownHostException, UnsupportedAddressTypeException;
 
如果文章对您有帮助,请点击页面广告。以鼓励作者做出的努力。
 类所在包
 同包方法