diff --git a/src/main/java/hxy/bytecode/java8/TestSupplier.java b/src/main/java/hxy/bytecode/java8/TestSupplier.java new file mode 100644 index 0000000000000000000000000000000000000000..23193621063b5aab85b0b1a54b6b04df5de58c4e --- /dev/null +++ b/src/main/java/hxy/bytecode/java8/TestSupplier.java @@ -0,0 +1,21 @@ +package hxy.bytecode.java8; + +import java.util.function.Supplier; + +public class TestSupplier { + private int age; + + TestSupplier() { + System.out.println("正在初始化" + age); + } + + public static void main(String[] args) { + //创建Supplier容器,声明为TestSupplier类型,此时并不会调用对象的构造方法,即不会创建对象 + Supplier sup = TestSupplier::new; + System.out.println("--------"); + //调用get()方法,此时会调用对象的构造方法,即获得到真正对象 + final TestSupplier testSupplier = sup.get(); + //每次get都会调用构造方法,即获取的对象不同 + sup.get(); + } +} \ No newline at end of file diff --git a/src/main/java/hxy/bytecode/proxy/JdkInvocation.java b/src/main/java/hxy/bytecode/proxy/JdkInvocation.java new file mode 100644 index 0000000000000000000000000000000000000000..c40ed2dcc8a2fb9a70ae98843f31d52df879dd7e --- /dev/null +++ b/src/main/java/hxy/bytecode/proxy/JdkInvocation.java @@ -0,0 +1,25 @@ +package hxy.bytecode.proxy; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; + +/** + * @author iris + */ +public class JdkInvocation implements InvocationHandler { + + private Object object; + + public void setTagServiceObject(Object object) { + this.object = object; + } + + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + System.out.println("TagService代理前"); + Object returnObject = method.invoke(this.object, args); + System.out.println("TagService代理后"); + return returnObject; + } + +} \ No newline at end of file diff --git a/src/main/java/hxy/bytecode/proxy/ProxyStart.java b/src/main/java/hxy/bytecode/proxy/ProxyStart.java new file mode 100644 index 0000000000000000000000000000000000000000..1439236ca754ccb2312d50698449a2be159d6454 --- /dev/null +++ b/src/main/java/hxy/bytecode/proxy/ProxyStart.java @@ -0,0 +1,26 @@ +package hxy.bytecode.proxy; + +import hxy.bytecode.proxy.service.TagService; +import hxy.bytecode.proxy.service.impl.TagServiceImpl; + +import java.lang.reflect.Proxy; + +/** + * @author iris + * @link https://blog.csdn.net/zxysshgood/article/details/78684229 + * https://blog.csdn.net/zxysshgood/article/details/78684229 + */ +public class ProxyStart { + + public static void main(String[] args) { + + JdkInvocation invocation = new JdkInvocation(); + + invocation.setTagServiceObject(new TagServiceImpl()); + + TagService service = (TagService) Proxy.newProxyInstance(ProxyStart.class.getClassLoader(), new Class[]{TagService.class}, invocation); + + service.printSomeThing(); + + } +} \ No newline at end of file diff --git a/src/main/java/hxy/bytecode/proxy/service/TagService.java b/src/main/java/hxy/bytecode/proxy/service/TagService.java new file mode 100644 index 0000000000000000000000000000000000000000..95e05157473ee8f0de051618eac04313d6840b60 --- /dev/null +++ b/src/main/java/hxy/bytecode/proxy/service/TagService.java @@ -0,0 +1,8 @@ +package hxy.bytecode.proxy.service; + +/** + * @author iris + */ +public interface TagService { + void printSomeThing(); +} \ No newline at end of file diff --git a/src/main/java/hxy/bytecode/proxy/service/impl/TagServiceImpl.java b/src/main/java/hxy/bytecode/proxy/service/impl/TagServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..60d71b46df27861bb1ad53cab6957f64b90815be --- /dev/null +++ b/src/main/java/hxy/bytecode/proxy/service/impl/TagServiceImpl.java @@ -0,0 +1,16 @@ +package hxy.bytecode.proxy.service.impl; + +import hxy.bytecode.proxy.service.TagService; + +/** + * @author iris + */ +public class TagServiceImpl implements TagService { + + @Override + public final void printSomeThing() { + System.err.println("this is printSomeThing Core ServiceImpl"); + } + + +} \ No newline at end of file diff --git "a/src/main/java/hxy/bytecode/proxy/\346\210\252\345\233\276_\351\200\211\346\213\251\345\214\272\345\237\237_20210823232147.png" "b/src/main/java/hxy/bytecode/proxy/\346\210\252\345\233\276_\351\200\211\346\213\251\345\214\272\345\237\237_20210823232147.png" new file mode 100644 index 0000000000000000000000000000000000000000..faa4e9a4afc57bdad2ef0dec9524ed700b094395 Binary files /dev/null and "b/src/main/java/hxy/bytecode/proxy/\346\210\252\345\233\276_\351\200\211\346\213\251\345\214\272\345\237\237_20210823232147.png" differ diff --git a/src/main/java/hxy/bytecode/sql/IpLongUtils.java b/src/main/java/hxy/bytecode/sql/IpLongUtils.java new file mode 100644 index 0000000000000000000000000000000000000000..58a2167eea14bd7013326ab2194ee2a3fee59b18 --- /dev/null +++ b/src/main/java/hxy/bytecode/sql/IpLongUtils.java @@ -0,0 +1,42 @@ +package hxy.bytecode.sql; + + +/** + * @author Mikan + */ +public class IpLongUtils { + + /** + * 把字符串IP转换成long + * + * @param ipStr 字符串IP + * @return IP对应的long值 + */ + public static long ip2Long(String ipStr) { + String[] ip = ipStr.split("\\."); + return (Long.valueOf(ip[0]) << 24) + (Long.valueOf(ip[1]) << 16) + + (Long.valueOf(ip[2]) << 8) + Long.valueOf(ip[3]); + } + + /** + * 把IP的long值转换成字符串 + * + * @param ipLong IP的long值 + * @return long值对应的字符串 + */ + public static String long2Ip(long ipLong) { + StringBuilder ip = new StringBuilder(); + ip.append(ipLong >>> 24).append("."); + ip.append((ipLong >>> 16) & 0xFF).append("."); + ip.append((ipLong >>> 8) & 0xFF).append("."); + ip.append(ipLong & 0xFF); + return ip.toString(); + } + + public static void main(String[] args) { + System.out.println(ip2Long("192.168.0.1")); + System.out.println(long2Ip(3232235521L)); + System.out.println(ip2Long("10.0.0.1")); + } + +}