Rename IpAddresses to NetUtil

This commit is contained in:
Norman Maurer 2012-11-19 06:07:18 +01:00
parent 5d13c7d27b
commit 0fb0037eab
14 changed files with 36 additions and 44 deletions

View File

@ -17,7 +17,7 @@ package io.netty.handler.codec.socks;
import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;
import io.netty.util.IpAddresses;
import io.netty.util.NetUtil;
import java.net.IDN;
@ -46,7 +46,7 @@ public final class SocksCmdRequest extends SocksRequest {
}
switch (addressType) {
case IPv4:
if (!IpAddresses.isValidIpV4Address(host)) {
if (!NetUtil.isValidIpV4Address(host)) {
throw new IllegalArgumentException(host + " is not a valid IPv4 address");
}
break;
@ -56,7 +56,7 @@ public final class SocksCmdRequest extends SocksRequest {
}
break;
case IPv6:
if (!IpAddresses.isValidIp6Address(host)) {
if (!NetUtil.isValidIp6Address(host)) {
throw new IllegalArgumentException(host + " is not a valid IPv6 address");
}
break;
@ -116,7 +116,7 @@ public final class SocksCmdRequest extends SocksRequest {
byteBuf.writeByte(addressType.getByteValue());
switch (addressType) {
case IPv4: {
byteBuf.writeBytes(IpAddresses.createByteArrayFromIpAddressString(host));
byteBuf.writeBytes(NetUtil.createByteArrayFromIpAddressString(host));
byteBuf.writeShort(port);
break;
}
@ -129,7 +129,7 @@ public final class SocksCmdRequest extends SocksRequest {
}
case IPv6: {
byteBuf.writeBytes(IpAddresses.createByteArrayFromIpAddressString(host));
byteBuf.writeBytes(NetUtil.createByteArrayFromIpAddressString(host));
byteBuf.writeShort(port);
break;
}

View File

@ -38,7 +38,7 @@ import java.util.StringTokenizer;
* <a href="http://svn.apache.org/repos/asf/harmony/enhanced/java/branches/java6/classlib/modules/luni/
* src/main/java/org/apache/harmony/luni/util/Inet6Util.java">Inet6Util class</a> which was part of Apache Harmony.
*/
public final class IpAddresses {
public final class NetUtil {
/**
* The {@link InetAddress} representing the host machine
@ -64,10 +64,9 @@ public final class IpAddresses {
* The logger being used by this class
*/
private static final InternalLogger logger =
InternalLoggerFactory.getInstance(IpAddresses.class);
InternalLoggerFactory.getInstance(NetUtil.class);
static {
//Start the process of discovering localhost
InetAddress localhost;
try {
@ -183,7 +182,6 @@ public final class IpAddresses {
}
}
/**
* Creates an byte[] based on an ipAddressString. No error handling is
* performed here.
@ -302,7 +300,6 @@ public final class IpAddresses {
}
return ipByteArray;
}
/** Converts a 4 character hex word into a 2 byte word equivalent */
@ -605,7 +602,7 @@ public final class IpAddresses {
/**
* A constructor to stop this class being constructed.
*/
private IpAddresses() {
private NetUtil() {
// Unused
}
}

View File

@ -19,16 +19,16 @@ import org.junit.Test;
import static org.junit.Assert.*;
public class IpAddressesTest {
public class NetUtilTest {
@Test
public void testLocalhost() {
assertNotNull(IpAddresses.LOCALHOST);
assertNotNull(NetUtil.LOCALHOST);
}
@Test
public void testLoopback() {
assertNotNull(IpAddresses.LOOPBACK_IF);
assertNotNull(NetUtil.LOOPBACK_IF);
}
}

View File

@ -20,7 +20,7 @@ import io.netty.logging.InternalLogger;
import io.netty.logging.InternalLoggerFactory;
import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory;
import io.netty.testsuite.util.TestUtils;
import io.netty.util.IpAddresses;
import io.netty.util.NetUtil;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@ -47,7 +47,7 @@ public abstract class AbstractClientSocketTest {
for (Factory<Bootstrap> e: COMBO) {
cb = e.newInstance();
addr = new InetSocketAddress(
IpAddresses.LOCALHOST, TestUtils.getFreePort());
NetUtil.LOCALHOST, TestUtils.getFreePort());
cb.remoteAddress(addr);
logger.info(String.format(

View File

@ -21,7 +21,7 @@ import io.netty.logging.InternalLogger;
import io.netty.logging.InternalLoggerFactory;
import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory;
import io.netty.testsuite.util.TestUtils;
import io.netty.util.IpAddresses;
import io.netty.util.NetUtil;
import org.junit.Rule;
import org.junit.rules.TestName;
@ -52,7 +52,7 @@ public abstract class AbstractDatagramTest {
sb = e.getKey().newInstance();
cb = e.getValue().newInstance();
addr = new InetSocketAddress(
IpAddresses.LOCALHOST, TestUtils.getFreePort());
NetUtil.LOCALHOST, TestUtils.getFreePort());
sb.localAddress(addr);
cb.localAddress(0).remoteAddress(addr);

View File

@ -21,7 +21,7 @@ import io.netty.logging.InternalLogger;
import io.netty.logging.InternalLoggerFactory;
import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory;
import io.netty.testsuite.util.TestUtils;
import io.netty.util.IpAddresses;
import io.netty.util.NetUtil;
import org.junit.Rule;
import org.junit.rules.TestName;
@ -53,7 +53,7 @@ public abstract class AbstractSctpTest {
sb = e.getKey().newInstance();
cb = e.getValue().newInstance();
addr = new InetSocketAddress(
IpAddresses.LOCALHOST, TestUtils.getFreePort());
NetUtil.LOCALHOST, TestUtils.getFreePort());
sb.localAddress(addr);
cb.remoteAddress(addr);

View File

@ -20,7 +20,7 @@ import io.netty.logging.InternalLogger;
import io.netty.logging.InternalLoggerFactory;
import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory;
import io.netty.testsuite.util.TestUtils;
import io.netty.util.IpAddresses;
import io.netty.util.NetUtil;
import org.junit.Rule;
import org.junit.rules.TestName;
@ -47,7 +47,7 @@ public abstract class AbstractServerSocketTest {
for (Factory<ServerBootstrap> e: COMBO) {
sb = e.newInstance();
addr = new InetSocketAddress(
IpAddresses.LOCALHOST, TestUtils.getFreePort());
NetUtil.LOCALHOST, TestUtils.getFreePort());
sb.localAddress(addr);
logger.info(String.format(

View File

@ -21,7 +21,7 @@ import io.netty.logging.InternalLogger;
import io.netty.logging.InternalLoggerFactory;
import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory;
import io.netty.testsuite.util.TestUtils;
import io.netty.util.IpAddresses;
import io.netty.util.NetUtil;
import org.junit.Rule;
import org.junit.rules.TestName;
@ -54,7 +54,7 @@ public abstract class AbstractSocketTest {
sb = e.getKey().newInstance();
cb = e.getValue().newInstance();
addr = new InetSocketAddress(
IpAddresses.LOCALHOST, TestUtils.getFreePort());
NetUtil.LOCALHOST, TestUtils.getFreePort());
sb.localAddress(addr);
cb.remoteAddress(addr);

View File

@ -24,7 +24,7 @@ import io.netty.channel.ChannelOption;
import io.netty.channel.socket.DatagramChannel;
import io.netty.channel.socket.DatagramPacket;
import io.netty.channel.socket.oio.OioDatagramChannel;
import io.netty.util.IpAddresses;
import io.netty.util.NetUtil;
import org.junit.Ignore;
import org.junit.Test;
@ -56,9 +56,9 @@ public class DatagramMulticastTest extends AbstractDatagramTest {
cb.handler(mhandler);
sb.option(ChannelOption.IP_MULTICAST_IF, IpAddresses.LOOPBACK_IF);
sb.option(ChannelOption.IP_MULTICAST_IF, NetUtil.LOOPBACK_IF);
sb.option(ChannelOption.SO_REUSEADDR, true);
cb.option(ChannelOption.IP_MULTICAST_IF, IpAddresses.LOOPBACK_IF);
cb.option(ChannelOption.IP_MULTICAST_IF, NetUtil.LOOPBACK_IF);
cb.option(ChannelOption.SO_REUSEADDR, true);
cb.localAddress(addr.getPort());
@ -75,13 +75,13 @@ public class DatagramMulticastTest extends AbstractDatagramTest {
String group = "230.0.0.1";
InetSocketAddress groupAddress = new InetSocketAddress(group, addr.getPort());
cc.joinGroup(groupAddress, IpAddresses.LOOPBACK_IF).sync();
cc.joinGroup(groupAddress, NetUtil.LOOPBACK_IF).sync();
sc.write(new DatagramPacket(Unpooled.copyInt(1), groupAddress)).sync();
assertTrue(mhandler.await());
// leave the group
cc.leaveGroup(groupAddress, IpAddresses.LOOPBACK_IF).sync();
cc.leaveGroup(groupAddress, NetUtil.LOOPBACK_IF).sync();
// sleep a second to make sure we left the group
Thread.sleep(1000);

View File

@ -29,7 +29,7 @@ import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.spdy.SpdyConstants;
import io.netty.handler.codec.spdy.SpdyFrameDecoder;
import io.netty.handler.codec.spdy.SpdyFrameEncoder;
import io.netty.util.IpAddresses;
import io.netty.util.NetUtil;
import java.io.IOException;
import java.net.InetSocketAddress;
@ -197,7 +197,7 @@ public class SocketSpdyEchoTest extends AbstractSocketTest {
Channel sc = sb.localAddress(0).bind().sync().channel();
int port = ((InetSocketAddress) sc.localAddress()).getPort();
Channel cc = cb.remoteAddress(IpAddresses.LOCALHOST, port).connect().sync().channel();
Channel cc = cb.remoteAddress(NetUtil.LOCALHOST, port).connect().sync().channel();
cc.write(frames);
while (ch.counter < frames.writerIndex() - ignoredBytes) {

View File

@ -15,7 +15,7 @@
*/
package io.netty.testsuite.util;
import io.netty.util.IpAddresses;
import io.netty.util.NetUtil;
import java.io.IOException;
import java.net.InetSocketAddress;
@ -64,7 +64,7 @@ public final class TestUtils {
ss = new ServerSocket();
ss.setReuseAddress(false);
ss.bind(new InetSocketAddress(IpAddresses.LOCALHOST, port));
ss.bind(new InetSocketAddress(NetUtil.LOCALHOST, port));
ss.close();
return port;

View File

@ -21,7 +21,7 @@ import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelException;
import io.netty.channel.ChannelOption;
import io.netty.channel.DefaultChannelConfig;
import io.netty.util.IpAddresses;
import io.netty.util.NetUtil;
import java.io.IOException;
import java.util.Map;
@ -36,7 +36,7 @@ import static com.sun.nio.sctp.SctpStandardSocketOptions.SO_SNDBUF;
public class DefaultSctpServerChannelConfig extends DefaultChannelConfig implements SctpServerChannelConfig {
private final SctpServerChannel serverChannel;
private volatile int backlog = IpAddresses.SOMAXCONN;
private volatile int backlog = NetUtil.SOMAXCONN;
/**
* Creates a new instance.

View File

@ -21,7 +21,7 @@ import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelException;
import io.netty.channel.ChannelOption;
import io.netty.channel.DefaultChannelConfig;
import io.netty.util.IpAddresses;
import io.netty.util.NetUtil;
import java.net.ServerSocket;
import java.net.SocketException;
@ -34,7 +34,7 @@ public class DefaultServerSocketChannelConfig extends DefaultChannelConfig
implements ServerSocketChannelConfig {
private final ServerSocket socket;
private volatile int backlog = IpAddresses.SOMAXCONN;
private volatile int backlog = NetUtil.SOMAXCONN;
/**
* Creates a new instance.

View File

@ -22,7 +22,7 @@ import io.netty.channel.ChannelException;
import io.netty.channel.ChannelOption;
import io.netty.channel.DefaultChannelConfig;
import io.netty.channel.socket.ServerSocketChannelConfig;
import io.netty.util.IpAddresses;
import io.netty.util.NetUtil;
import java.io.IOException;
import java.net.SocketOption;
@ -38,10 +38,9 @@ import java.util.concurrent.atomic.AtomicReference;
final class AioServerSocketChannelConfig extends DefaultChannelConfig
implements ServerSocketChannelConfig {
<<<<<<< HEAD
private final AtomicReference<AsynchronousServerSocketChannel> channel
= new AtomicReference<AsynchronousServerSocketChannel>();
private volatile int backlog = NetworkConstants.SOMAXCONN;
private volatile int backlog = NetUtil.SOMAXCONN;
private Map<SocketOption<?>, Object> options = new ConcurrentHashMap<SocketOption<?>, Object>();
private static final int DEFAULT_SND_BUF_SIZE = 32 * 1024;
private static final boolean DEFAULT_SO_REUSEADDR = false;
@ -54,10 +53,6 @@ final class AioServerSocketChannelConfig extends DefaultChannelConfig
*/
AioServerSocketChannelConfig() {
}
=======
private final AsynchronousServerSocketChannel channel;
private volatile int backlog = IpAddresses.SOMAXCONN;
>>>>>>> 9e370a3... Merge IPUtil and NetworkConstants into IpAddresses and also make naming of methods consistent
/**
* Creates a new instance with the given {@link AsynchronousServerSocketChannel} assigned to it.