From c869bd228095189d931f37cdaed34a0946d40726 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=89=91=E5=99=A8=E8=BF=91?= Date: Wed, 21 Jul 2021 09:57:56 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E7=A0=81=E5=BC=82=E5=B8=B8=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E4=B8=AD=E5=A2=9E=E5=8A=A0=E5=8E=9F=E5=A7=8B=E6=8A=A5?= =?UTF-8?q?=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../netmc/codec/MessageDecoderWrapper.java | 3 +- .../netmc/util/AdapterCollection.java | 50 +++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 src/main/java/io/github/yezhihao/netmc/util/AdapterCollection.java diff --git a/pom.xml b/pom.xml index d594a98..0758534 100644 --- a/pom.xml +++ b/pom.xml @@ -62,7 +62,7 @@ io.netty netty-handler - 4.1.65.Final + 4.1.66.Final provided diff --git a/src/main/java/io/github/yezhihao/netmc/codec/MessageDecoderWrapper.java b/src/main/java/io/github/yezhihao/netmc/codec/MessageDecoderWrapper.java index 2afa06b..a43539f 100644 --- a/src/main/java/io/github/yezhihao/netmc/codec/MessageDecoderWrapper.java +++ b/src/main/java/io/github/yezhihao/netmc/codec/MessageDecoderWrapper.java @@ -2,6 +2,7 @@ package io.github.yezhihao.netmc.codec; import io.github.yezhihao.netmc.session.Session; import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufUtil; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; @@ -31,7 +32,7 @@ public class MessageDecoderWrapper extends ChannelInboundHandlerAdapter { ctx.fireChannelRead(message); buf.skipBytes(buf.readableBytes()); } catch (Exception e) { - throw new DecoderException(e); + throw new DecoderException(ByteBufUtil.hexDump(buf), e); } finally { buf.release(); } diff --git a/src/main/java/io/github/yezhihao/netmc/util/AdapterCollection.java b/src/main/java/io/github/yezhihao/netmc/util/AdapterCollection.java new file mode 100644 index 0000000..dcf878f --- /dev/null +++ b/src/main/java/io/github/yezhihao/netmc/util/AdapterCollection.java @@ -0,0 +1,50 @@ +package io.github.yezhihao.netmc.util; + +import java.util.AbstractCollection; +import java.util.Collection; +import java.util.Iterator; +import java.util.function.Function; + +/** + * @author yezhihao + * home https://gitee.com/yezhihao/jt808-server + */ +public final class AdapterCollection extends AbstractCollection { + + private final Collection src; + private final Iterator iterator; + + public AdapterCollection(Collection src, Function function) { + this.src = src; + this.iterator = new Iterator() { + + private final Function f = function; + private final Iterator it = src.iterator(); + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public T next() { + return f.apply(it.next()); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public Iterator iterator() { + return iterator; + } + + @Override + public int size() { + return src.size(); + } +} \ No newline at end of file