Permalink
Browse files

Rename IpAddresses to NetUtil

  • Loading branch information...
1 parent 5d13c7d commit 0fb0037eab86b74e62935ab1d46e83bf8f81acb0 @normanmaurer normanmaurer committed Nov 19, 2012
@@ -17,7 +17,7 @@
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 SocksCmdRequest(CmdType cmdType, AddressType addressType, String host, in
}
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 SocksCmdRequest(CmdType cmdType, AddressType addressType, String host, in
}
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 void encodeAsByteBuf(ByteBuf byteBuf) {
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 void encodeAsByteBuf(ByteBuf byteBuf) {
}
case IPv6: {
- byteBuf.writeBytes(IpAddresses.createByteArrayFromIpAddressString(host));
+ byteBuf.writeBytes(NetUtil.createByteArrayFromIpAddressString(host));
byteBuf.writeShort(port);
break;
}
@@ -38,7 +38,7 @@
* <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 @@
* 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 @@ private static void validateHost(InetAddress host) throws IOException {
}
}
-
/**
* Creates an byte[] based on an ipAddressString. No error handling is
* performed here.
@@ -302,7 +300,6 @@ private static void validateHost(InetAddress host) throws IOException {
}
return ipByteArray;
-
}
/** Converts a 4 character hex word into a 2 byte word equivalent */
@@ -605,7 +602,7 @@ public static boolean isValidIpV4Address(String value) {
/**
* A constructor to stop this class being constructed.
*/
- private IpAddresses() {
+ private NetUtil() {
// Unused
}
}
@@ -19,16 +19,16 @@
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);
}
}
@@ -20,7 +20,7 @@
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 @@ protected void run() throws Throwable {
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(
@@ -21,7 +21,7 @@
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 @@ protected void run() throws Throwable {
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);
@@ -21,7 +21,7 @@
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 @@ protected void run() throws Throwable {
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);
@@ -20,7 +20,7 @@
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 @@ protected void run() throws Throwable {
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(
@@ -21,7 +21,7 @@
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 @@ protected void run() throws Throwable {
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);
@@ -24,7 +24,7 @@
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 void messageReceived(
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 void messageReceived(
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);
@@ -29,7 +29,7 @@
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 void initChannel(SocketChannel channel) throws Exception {
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) {
@@ -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 static int getFreePort() {
ss = new ServerSocket();
ss.setReuseAddress(false);
- ss.bind(new InetSocketAddress(IpAddresses.LOCALHOST, port));
+ ss.bind(new InetSocketAddress(NetUtil.LOCALHOST, port));
ss.close();
return port;
@@ -21,7 +21,7 @@
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 @@
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.
@@ -21,7 +21,7 @@
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 @@
implements ServerSocketChannelConfig {
private final ServerSocket socket;
- private volatile int backlog = IpAddresses.SOMAXCONN;
+ private volatile int backlog = NetUtil.SOMAXCONN;
/**
* Creates a new instance.
@@ -22,7 +22,7 @@
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 @@
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 @@
*/
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.

0 comments on commit 0fb0037

Please sign in to comment.