/** * Provide the caller with a decoder to turn a source object into an instance of the input * type. * * @return The decoded object. */ public Function<SRC, IN> decoder() { return decoder(null); }
@SuppressWarnings("unchecked") private T read(ExcerptCommon ex) { try { int len = ex.readInt(); ByteBuffer bb = ByteBuffer.allocate(len); ex.read(bb); bb.flip(); return codec.decoder(null).apply(new Buffer(bb)); } finally { ex.finish(); } }
@Override public IN apply(Buffer buffer) { try { ByteArrayInputStream bin = new ByteArrayInputStream(buffer.asBytes()); InputStream zin = createInputStream(bin); Buffer newBuff = new Buffer(); while (zin.available() > 0) { newBuff.append((byte) zin.read()); } zin.close(); IN in = delegate.decoder(null).apply(newBuff.flip()); if (null != next) { next.accept(in); return null; } else { return in; } } catch (IOException e) { throw new IllegalStateException(e.getMessage(), e); } } };
protected ChannelStream(final Environment env, Codec<Buffer, IN, OUT> codec, long prefetch, Dispatcher eventsDispatcher) { Assert.notNull(eventsDispatcher, "Events Reactor cannot be null"); this.env = env; this.prefetch = prefetch; this.eventsDispatcher = eventsDispatcher; if (null != codec) { this.decoder = codec.decoder(new Consumer<IN>() { @Override public void accept(IN in) { doDecoded(in); } }); this.encoder = codec.encoder(); } else { this.decoder = null; this.encoder = null; } }