@Test public void testInterfaceSerialization() throws Exception { PipedOutputStream pipeOut = new PipedOutputStream(); PipedInputStream pipeIn = new PipedInputStream(pipeOut); CompactObjectOutputStream out = new CompactObjectOutputStream(pipeOut); CompactObjectInputStream in = new CompactObjectInputStream(pipeIn, ClassResolvers.cacheDisabled(null)); out.writeObject(List.class); Assert.assertSame(List.class, in.readObject()); }
/** * Creates a new {@link ObjectInput}. * * @param in the {@link InputStream} where the serialized form will be read from * @param classLoader the {@link ClassLoader} which will load the class of the serialized object * @param maxObjectSize the maximum byte length of the serialized object. if the length of the * received object is greater than this value, a {@link StreamCorruptedException} will be * raised. */ public ObjectDecoderInputStream(InputStream in, ClassLoader classLoader, int maxObjectSize) { if (in == null) { throw new NullPointerException("in"); } if (maxObjectSize <= 0) { throw new IllegalArgumentException("maxObjectSize: " + maxObjectSize); } if (in instanceof DataInputStream) { this.in = (DataInputStream) in; } else { this.in = new DataInputStream(in); } this.classResolver = ClassResolvers.weakCachingResolver(classLoader); this.maxObjectSize = maxObjectSize; }
private <In, Out> Channel listen(int port, NetworkEndpointFactory<In, Out> endpointFactory) { ServerBootstrap bootstrap = new ServerBootstrap(channelFactory); bootstrap.setPipelineFactory( () -> Channels.pipeline( new ObjectEncoder(), new ObjectDecoder(ClassResolvers.softCachingResolver(getClass().getClassLoader())), new LoggingHandler(NettyNetworkServer.class, logLevel), new NettyNetworkEndpointAdapter<>(endpointFactory.createEndpoint()), new AddToChannelGroupHandler(allChannels))); bootstrap.setOption("child.tcpNoDelay", true); bootstrap.setOption("child.keepAlive", true); Channel channel = bootstrap.bind(new InetSocketAddress(port)); allChannels.add(channel); return channel; }