当前位置: 首页>>代码示例>>Java>>正文


Java UnsupportedAddressTypeException类代码示例

本文整理汇总了Java中java.nio.channels.UnsupportedAddressTypeException的典型用法代码示例。如果您正苦于以下问题:Java UnsupportedAddressTypeException类的具体用法?Java UnsupportedAddressTypeException怎么用?Java UnsupportedAddressTypeException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


UnsupportedAddressTypeException类属于java.nio.channels包,在下文中一共展示了UnsupportedAddressTypeException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: JdpBroadcaster

import java.nio.channels.UnsupportedAddressTypeException; //导入依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:35,代码来源:JdpBroadcaster.java

示例2: connect

import java.nio.channels.UnsupportedAddressTypeException; //导入依赖的package包/类
public boolean connect (SocketAddress remote, int timeout) throws IOException
{
  if (!isOpen())
    throw new ClosedChannelException();

  if (isConnected())
    throw new AlreadyConnectedException();

  if (connectionPending)
    throw new ConnectionPendingException();

  if (!(remote instanceof InetSocketAddress))
    throw new UnsupportedAddressTypeException();

  connectAddress = (InetSocketAddress) remote;

  if (connectAddress.isUnresolved())
    throw new UnresolvedAddressException();

  connected = channel.connect(connectAddress, timeout);
  connectionPending = !connected;
  return connected;
}
 
开发者ID:vilie,项目名称:javify,代码行数:24,代码来源:SocketChannelImpl.java

示例3: getIpRangeMin

import java.nio.channels.UnsupportedAddressTypeException; //导入依赖的package包/类
private static IpAddress getIpRangeMin(IpAddress ipAddress, int maskLength) {
    BigInteger ip = ipAddress.toBigInteger();
    BigInteger subnetMask = new BigInteger(
            1,
            new byte[]{-1, -1, -1, -1})
            .shiftRight(maskLength)
            .xor(new BigInteger(1, new byte[]{-1, -1, -1, -1}));

    BigInteger networkAddress = ip.and(subnetMask);

    if (ipAddress instanceof Ipv4Address) {
        return Ipv4Address.gain(networkAddress.intValue());
    } else if (ipAddress instanceof Ipv6Address) {
        throw new UnsupportedAddressTypeException();
    } else {
        throw new IllegalArgumentException("Address acquisition failure");
    }
}
 
开发者ID:openNaEF,项目名称:openNaEF,代码行数:19,代码来源:InventoryGetIpAddressListState.java

示例4: connect

import java.nio.channels.UnsupportedAddressTypeException; //导入依赖的package包/类
public boolean connect (SocketAddress remote, int timeout) throws IOException
{
  if (!isOpen())
    throw new ClosedChannelException();
  
  if (isConnected())
    throw new AlreadyConnectedException();

  if (connectionPending)
    throw new ConnectionPendingException();

  if (!(remote instanceof InetSocketAddress))
    throw new UnsupportedAddressTypeException();
  
  connectAddress = (InetSocketAddress) remote;

  if (connectAddress.isUnresolved())
    throw new UnresolvedAddressException();
  
  connected = channel.connect(connectAddress, timeout);
  connectionPending = !connected;
  return connected;
}
 
开发者ID:nmldiegues,项目名称:jvm-stm,代码行数:24,代码来源:SocketChannelImpl.java

示例5: bind

import java.nio.channels.UnsupportedAddressTypeException; //导入依赖的package包/类
/** @hide Until ready for a public API change */
@Override
synchronized public DatagramChannel bind(SocketAddress local) throws IOException {
    checkOpen();
    if (isBound) {
        throw new AlreadyBoundException();
    }

    if (local == null) {
        local = new InetSocketAddress(Inet4Address.ANY, 0);
    } else if (!(local instanceof InetSocketAddress)) {
        throw new UnsupportedAddressTypeException();
    }

    InetSocketAddress localAddress = (InetSocketAddress) local;
    IoBridge.bind(fd, localAddress.getAddress(), localAddress.getPort());
    onBind(true /* updateSocketState */);
    return this;
}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:20,代码来源:DatagramChannelImpl.java

示例6: bind

import java.nio.channels.UnsupportedAddressTypeException; //导入依赖的package包/类
/** @hide Until ready for a public API change */
@Override
synchronized public final SocketChannel bind(SocketAddress local) throws IOException {
    if (!isOpen()) {
        throw new ClosedChannelException();
    }
    if (isBound) {
        throw new AlreadyBoundException();
    }

    if (local == null) {
        local = new InetSocketAddress(Inet4Address.ANY, 0);
    } else if (!(local instanceof InetSocketAddress)) {
        throw new UnsupportedAddressTypeException();
    }

    InetSocketAddress localAddress = (InetSocketAddress) local;
    IoBridge.bind(fd, localAddress.getAddress(), localAddress.getPort());
    onBind(true /* updateSocketState */);
    return this;
}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:22,代码来源:SocketChannelImpl.java

示例7: bind

import java.nio.channels.UnsupportedAddressTypeException; //导入依赖的package包/类
/** @hide Until ready for a public API change */
@Override
public final ServerSocketChannel bind(SocketAddress localAddr, int backlog) throws IOException {
    if (!isOpen()) {
        throw new ClosedChannelException();
    }
    if (socket.isBound()) {
        throw new AlreadyBoundException();
    }
    if (localAddr != null && !(localAddr instanceof InetSocketAddress)) {
        throw new UnsupportedAddressTypeException();
    }

    socket.bind(localAddr, backlog);
    return this;
}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:17,代码来源:ServerSocketChannelImpl.java

示例8: UDPTrackerClient

import java.nio.channels.UnsupportedAddressTypeException; //导入依赖的package包/类
/**
 * 
 * @param torrent
 */
protected UDPTrackerClient(SharedTorrent torrent, Peer peer, URI tracker)
	throws UnknownHostException {
	super(torrent, peer, tracker);

	/**
	 * The UDP announce request protocol only supports IPv4
	 *
	 * @see http://bittorrent.org/beps/bep_0015.html#ipv6
	 */
	if (! (InetAddress.getByName(peer.getIp()) instanceof Inet4Address)) {
		throw new UnsupportedAddressTypeException();
	}

	this.address = new InetSocketAddress(
		tracker.getHost(),
		tracker.getPort());

	this.socket = null;
	this.random = new Random();
	this.connectionExpiration = null;
	this.stop = false;
}
 
开发者ID:KingJoker,项目名称:PiratePlayar,代码行数:27,代码来源:UDPTrackerClient.java

示例9: getIPv4Address

import java.nio.channels.UnsupportedAddressTypeException; //导入依赖的package包/类
/**
 * Returns a usable {@link Inet4Address} for the given interface name.
 *
 * <p>
 * If an interface name is given, return the first usable IPv4 address for
 * that interface. If no interface name is given or if that interface
 * doesn't have an IPv4 address, return's localhost address (if IPv4).
 * </p>
 *
 * <p>
 * It is understood this makes the client IPv4 only, but it is important to
 * remember that most BitTorrent extensions (like compact peer lists from
 * trackers and UDP tracker support) are IPv4-only anyway.
 * </p>
 *
 * @param iface The network interface name.
 * @return A usable IPv4 address as a {@link Inet4Address}.
 * @throws UnsupportedAddressTypeException If no IPv4 address was available
 * to bind on.
 */
private static Inet4Address getIPv4Address(String iface)
	throws SocketException, UnsupportedAddressTypeException,
		UnknownHostException {
	if (iface != null) {
		Enumeration<InetAddress> addresses =
			NetworkInterface.getByName(iface).getInetAddresses();
		while (addresses.hasMoreElements()) {
			InetAddress addr = addresses.nextElement();
			if (addr instanceof Inet4Address) {
				return (Inet4Address)addr;
			}
		}
	}

	InetAddress localhost = InetAddress.getLocalHost();
	if (localhost instanceof Inet4Address) {
		return (Inet4Address)localhost;
	}

	throw new UnsupportedAddressTypeException();
}
 
开发者ID:KingJoker,项目名称:PiratePlayar,代码行数:42,代码来源:Client.java

示例10: testConnect_UnsupportedType

import java.nio.channels.UnsupportedAddressTypeException; //导入依赖的package包/类
/**
 * Test method for 'DatagramChannelImpl.connect(SocketAddress)'
 *
 * @throws IOException
 */
@TestTargetNew(
    level = TestLevel.PARTIAL_COMPLETE,
    notes = "Verifies UnsupportedAddressTypeException.",
    method = "connect",
    args = {java.net.SocketAddress.class}
)
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.
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:29,代码来源:DatagramChannelTest.java

示例11: testSerializationSelf

import java.nio.channels.UnsupportedAddressTypeException; //导入依赖的package包/类
/**
 * @tests serialization/deserialization compatibility.
 */
@TestTargets({
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        notes = "Verifies serialization/deserialization compatibility.",
        method = "!SerializationSelf",
        args = {}
    ),
    @TestTargetNew(
        level = TestLevel.PARTIAL_COMPLETE,
        notes = "Verifies serialization/deserialization compatibility.",
        method = "UnsupportedAddressTypeException",
        args = {}
    )
})
public void testSerializationSelf() throws Exception {

    SerializationTest.verifySelf(new UnsupportedAddressTypeException());
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:22,代码来源:UnsupportedAddressTypeExceptionTest.java

示例12: testSerializationCompatibility

import java.nio.channels.UnsupportedAddressTypeException; //导入依赖的package包/类
/**
 * @tests serialization/deserialization compatibility with RI.
 */
@TestTargets({
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        notes = "Verifies serialization/deserialization compatibility.",
        method = "!SerializationGolden",
        args = {}
    ),
    @TestTargetNew(
        level = TestLevel.PARTIAL_COMPLETE,
        notes = "Verifies serialization/deserialization compatibility.",
        method = "UnsupportedAddressTypeException",
        args = {}
    )
})
public void testSerializationCompatibility() throws Exception {

    SerializationTest.verifyGolden(this,
            new UnsupportedAddressTypeException());
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:23,代码来源:UnsupportedAddressTypeExceptionTest.java

示例13: getIPv4Address

import java.nio.channels.UnsupportedAddressTypeException; //导入依赖的package包/类
/**
 * Returns a usable {@link java.net.Inet4Address} for the given interface name.
 *
 * <p>
 * If an interface name is given, return the first usable IPv4 address for
 * that interface. If no interface name is given or if that interface
 * doesn't have an IPv4 address, return's localhost address (if IPv4).
 * </p>
 *
 * <p>
 * It is understood this makes the client IPv4 only, but it is important to
 * remember that most BitTorrent extensions (like compact peer lists from
 * trackers and UDP tracker support) are IPv4-only anyway.
 * </p>
 *
 * @param iface The network interface name.
 * @return A usable IPv4 address as a {@link java.net.Inet4Address}.
 * @throws java.nio.channels.UnsupportedAddressTypeException If no IPv4 address was available
 * to bind on.
 */
private static Inet4Address getIPv4Address(String iface)
        throws SocketException, UnsupportedAddressTypeException,
        UnknownHostException {
    if (iface != null) {
        Enumeration<InetAddress> addresses =
                NetworkInterface.getByName(iface).getInetAddresses();
        while (addresses.hasMoreElements()) {
            InetAddress addr = addresses.nextElement();
            if (addr instanceof Inet4Address) {
                return (Inet4Address) addr;
            }
        }
    }

    InetAddress localhost = InetAddress.getLocalHost();
    if (localhost instanceof Inet4Address) {
        return (Inet4Address) localhost;
    }

    throw new UnsupportedAddressTypeException();
}
 
开发者ID:letroll,项目名称:TtorrentAndroid,代码行数:42,代码来源:ClientMain.java

示例14: testConnect_UnsupportedType

import java.nio.channels.UnsupportedAddressTypeException; //导入依赖的package包/类
/**
 * Test method for 'DatagramChannelImpl.connect(SocketAddress)'
 * 
 * @throws IOException
 */
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.
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:23,代码来源:DatagramChannelTest.java

示例15: testCFII_UnsupportedType

import java.nio.channels.UnsupportedAddressTypeException; //导入依赖的package包/类
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.
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:19,代码来源:SocketChannelTest.java


注:本文中的java.nio.channels.UnsupportedAddressTypeException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。