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.buffer.ByteBuf;
import io.netty.util.CharsetUtil; import io.netty.util.CharsetUtil;
import io.netty.util.IpAddresses; import io.netty.util.NetUtil;
import java.net.IDN; import java.net.IDN;
@ -46,7 +46,7 @@ public final class SocksCmdRequest extends SocksRequest {
} }
switch (addressType) { switch (addressType) {
case IPv4: case IPv4:
if (!IpAddresses.isValidIpV4Address(host)) { if (!NetUtil.isValidIpV4Address(host)) {
throw new IllegalArgumentException(host + " is not a valid IPv4 address"); throw new IllegalArgumentException(host + " is not a valid IPv4 address");
} }
break; break;
@ -56,7 +56,7 @@ public final class SocksCmdRequest extends SocksRequest {
} }
break; break;
case IPv6: case IPv6:
if (!IpAddresses.isValidIp6Address(host)) { if (!NetUtil.isValidIp6Address(host)) {
throw new IllegalArgumentException(host + " is not a valid IPv6 address"); throw new IllegalArgumentException(host + " is not a valid IPv6 address");
} }
break; break;
@ -116,7 +116,7 @@ public final class SocksCmdRequest extends SocksRequest {
byteBuf.writeByte(addressType.getByteValue()); byteBuf.writeByte(addressType.getByteValue());
switch (addressType) { switch (addressType) {
case IPv4: { case IPv4: {
byteBuf.writeBytes(IpAddresses.createByteArrayFromIpAddressString(host)); byteBuf.writeBytes(NetUtil.createByteArrayFromIpAddressString(host));
byteBuf.writeShort(port); byteBuf.writeShort(port);
break; break;
} }
@ -129,7 +129,7 @@ public final class SocksCmdRequest extends SocksRequest {
} }
case IPv6: { case IPv6: {
byteBuf.writeBytes(IpAddresses.createByteArrayFromIpAddressString(host)); byteBuf.writeBytes(NetUtil.createByteArrayFromIpAddressString(host));
byteBuf.writeShort(port); byteBuf.writeShort(port);
break; 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/ * <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. * 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 * The {@link InetAddress} representing the host machine
@ -64,10 +64,9 @@ public final class IpAddresses {
* The logger being used by this class * The logger being used by this class
*/ */
private static final InternalLogger logger = private static final InternalLogger logger =
InternalLoggerFactory.getInstance(IpAddresses.class); InternalLoggerFactory.getInstance(NetUtil.class);
static { static {
//Start the process of discovering localhost //Start the process of discovering localhost
InetAddress localhost; InetAddress localhost;
try { try {
@ -183,7 +182,6 @@ public final class IpAddresses {
} }
} }
/** /**
* Creates an byte[] based on an ipAddressString. No error handling is * Creates an byte[] based on an ipAddressString. No error handling is
* performed here. * performed here.
@ -302,7 +300,6 @@ public final class IpAddresses {
} }
return ipByteArray; return ipByteArray;
} }
/** Converts a 4 character hex word into a 2 byte word equivalent */ /** 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. * A constructor to stop this class being constructed.
*/ */
private IpAddresses() { private NetUtil() {
// Unused // Unused
} }
} }

View File

@ -19,16 +19,16 @@ import org.junit.Test;
import static org.junit.Assert.*; import static org.junit.Assert.*;
public class IpAddressesTest { public class NetUtilTest {
@Test @Test
public void testLocalhost() { public void testLocalhost() {
assertNotNull(IpAddresses.LOCALHOST); assertNotNull(NetUtil.LOCALHOST);
} }
@Test @Test
public void testLoopback() { 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.logging.InternalLoggerFactory;
import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory; import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory;
import io.netty.testsuite.util.TestUtils; 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.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -47,7 +47,7 @@ public abstract class AbstractClientSocketTest {
for (Factory<Bootstrap> e: COMBO) { for (Factory<Bootstrap> e: COMBO) {
cb = e.newInstance(); cb = e.newInstance();
addr = new InetSocketAddress( addr = new InetSocketAddress(
IpAddresses.LOCALHOST, TestUtils.getFreePort()); NetUtil.LOCALHOST, TestUtils.getFreePort());
cb.remoteAddress(addr); cb.remoteAddress(addr);
logger.info(String.format( logger.info(String.format(

View File

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

View File

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

View File

@ -21,7 +21,7 @@ import io.netty.logging.InternalLogger;
import io.netty.logging.InternalLoggerFactory; import io.netty.logging.InternalLoggerFactory;
import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory; import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory;
import io.netty.testsuite.util.TestUtils; import io.netty.testsuite.util.TestUtils;
import io.netty.util.IpAddresses; import io.netty.util.NetUtil;
import org.junit.Rule; import org.junit.Rule;
import org.junit.rules.TestName; import org.junit.rules.TestName;
@ -54,7 +54,7 @@ public abstract class AbstractSocketTest {
sb = e.getKey().newInstance(); sb = e.getKey().newInstance();
cb = e.getValue().newInstance(); cb = e.getValue().newInstance();
addr = new InetSocketAddress( addr = new InetSocketAddress(
IpAddresses.LOCALHOST, TestUtils.getFreePort()); NetUtil.LOCALHOST, TestUtils.getFreePort());
sb.localAddress(addr); sb.localAddress(addr);
cb.remoteAddress(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.DatagramChannel;
import io.netty.channel.socket.DatagramPacket; import io.netty.channel.socket.DatagramPacket;
import io.netty.channel.socket.oio.OioDatagramChannel; import io.netty.channel.socket.oio.OioDatagramChannel;
import io.netty.util.IpAddresses; import io.netty.util.NetUtil;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
@ -56,9 +56,9 @@ public class DatagramMulticastTest extends AbstractDatagramTest {
cb.handler(mhandler); 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); 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.option(ChannelOption.SO_REUSEADDR, true);
cb.localAddress(addr.getPort()); cb.localAddress(addr.getPort());
@ -75,13 +75,13 @@ public class DatagramMulticastTest extends AbstractDatagramTest {
String group = "230.0.0.1"; String group = "230.0.0.1";
InetSocketAddress groupAddress = new InetSocketAddress(group, addr.getPort()); 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(); sc.write(new DatagramPacket(Unpooled.copyInt(1), groupAddress)).sync();
assertTrue(mhandler.await()); assertTrue(mhandler.await());
// leave the group // 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 // sleep a second to make sure we left the group
Thread.sleep(1000); 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.SpdyConstants;
import io.netty.handler.codec.spdy.SpdyFrameDecoder; import io.netty.handler.codec.spdy.SpdyFrameDecoder;
import io.netty.handler.codec.spdy.SpdyFrameEncoder; import io.netty.handler.codec.spdy.SpdyFrameEncoder;
import io.netty.util.IpAddresses; import io.netty.util.NetUtil;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
@ -197,7 +197,7 @@ public class SocketSpdyEchoTest extends AbstractSocketTest {
Channel sc = sb.localAddress(0).bind().sync().channel(); Channel sc = sb.localAddress(0).bind().sync().channel();
int port = ((InetSocketAddress) sc.localAddress()).getPort(); 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); cc.write(frames);
while (ch.counter < frames.writerIndex() - ignoredBytes) { while (ch.counter < frames.writerIndex() - ignoredBytes) {

View File

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

View File

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

View File

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

View File

@ -22,7 +22,7 @@ import io.netty.channel.ChannelException;
import io.netty.channel.ChannelOption; import io.netty.channel.ChannelOption;
import io.netty.channel.DefaultChannelConfig; import io.netty.channel.DefaultChannelConfig;
import io.netty.channel.socket.ServerSocketChannelConfig; import io.netty.channel.socket.ServerSocketChannelConfig;
import io.netty.util.IpAddresses; import io.netty.util.NetUtil;
import java.io.IOException; import java.io.IOException;
import java.net.SocketOption; import java.net.SocketOption;
@ -38,10 +38,9 @@ import java.util.concurrent.atomic.AtomicReference;
final class AioServerSocketChannelConfig extends DefaultChannelConfig final class AioServerSocketChannelConfig extends DefaultChannelConfig
implements ServerSocketChannelConfig { implements ServerSocketChannelConfig {
<<<<<<< HEAD
private final AtomicReference<AsynchronousServerSocketChannel> channel private final AtomicReference<AsynchronousServerSocketChannel> channel
= new AtomicReference<AsynchronousServerSocketChannel>(); = 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 Map<SocketOption<?>, Object> options = new ConcurrentHashMap<SocketOption<?>, Object>();
private static final int DEFAULT_SND_BUF_SIZE = 32 * 1024; private static final int DEFAULT_SND_BUF_SIZE = 32 * 1024;
private static final boolean DEFAULT_SO_REUSEADDR = false; private static final boolean DEFAULT_SO_REUSEADDR = false;
@ -54,10 +53,6 @@ final class AioServerSocketChannelConfig extends DefaultChannelConfig
*/ */
AioServerSocketChannelConfig() { 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. * Creates a new instance with the given {@link AsynchronousServerSocketChannel} assigned to it.