Close ObjectInputStream in ObjectDecoder.decode(...)

Motivation:

We create a new CompactObjectInputStream with ByteBufInputStream in ObjectDecoder.decode(...) method and don't close this InputStreams before return statement.

Modifications:

Save link to the ObjectInputStream and close it before return statement.

Result:

Close InputStreams and clean up unused resources. It will be better for GC.
This commit is contained in:
Idel Pivnitskiy 2014-07-20 00:02:03 +04:00 committed by Norman Maurer
parent 53141b04a8
commit 0cc3eccc2b

View File

@ -20,6 +20,7 @@ import io.netty.buffer.ByteBufInputStream;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder; import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.io.StreamCorruptedException; import java.io.StreamCorruptedException;
@ -70,8 +71,10 @@ public class ObjectDecoder extends LengthFieldBasedFrameDecoder {
return null; return null;
} }
return new CompactObjectInputStream( ObjectInputStream is = new CompactObjectInputStream(new ByteBufInputStream(frame), classResolver);
new ByteBufInputStream(frame), classResolver).readObject(); Object result = is.readObject();
is.close();
return result;
} }
@Override @Override