本文整理汇总了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);
}
}
示例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;
}
示例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");
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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.
}
}
示例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());
}
示例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());
}
示例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();
}
示例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.
}
}
示例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.
}
}