@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { if (in.readableBytes() < 4) { return; } in.markReaderIndex(); int msgSize = in.readInt(); checkSize(msgSize); if (in.readableBytes() < msgSize) { // Incomplete message in buffer. in.resetReaderIndex(); return; } try { ByteBuffer nioBuffer = maybeDecrypt(in.nioBuffer(in.readerIndex(), msgSize)); Input kryoIn = new Input(new ByteBufferInputStream(nioBuffer)); Object msg = kryos.get().readClassAndObject(kryoIn); LOG.trace("Decoded message of type {} ({} bytes)", msg != null ? msg.getClass().getName() : msg, msgSize); out.add(msg); } finally { in.skipBytes(msgSize); } }
public synchronized Object read (Connection connection, ByteBuffer buffer) { byteBufferInputStream.setByteBuffer(buffer); return json.fromJson(Object.class, byteBufferInputStream); }
ByteBufferInputStream is = new ByteBufferInputStream(); is.setByteBuffer(buffer); BufferedImage img = ImageIO.read(is); if(img == null)
ByteBuffer current = super.getByteBuffer(); if (null != current) { current.clear(); if (null != buffer) { super.setByteBuffer(buffer); break; } else {
if (hasRemaining() || (null == super.getByteBuffer())) { bufferChange(); if (!super.getByteBuffer().hasRemaining()) { int read = super.read(); position += read; return read; int read = super.read(); position += read; return read;
ByteBufferInputStream is = new ByteBufferInputStream(); is.setByteBuffer(buffer); BufferedImage img = ImageIO.read(is); if(img == null)
ByteBuffer currentBuffer = super.getByteBuffer(); if (null != currentBuffer) { byteBufferProvider.releaseByteBuffer(currentBuffer); releasedBuffers++; super.setByteBuffer(null);
if (hasRemaining() && (null == super.getByteBuffer())) { bufferChange(); int bufferRemaining = super.getByteBuffer().remaining(); if (bufferRemaining >= len) { int read = super.read(b, off, len); position += read; return read; int res = 0; if (bufferRemaining > 0) { super.getByteBuffer().get(b, off, bufferRemaining); res = bufferRemaining; position += bufferRemaining;
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { if (in.readableBytes() < 4) { return; } in.markReaderIndex(); int msgSize = in.readInt(); checkSize(msgSize); if (in.readableBytes() < msgSize) { // Incomplete message in buffer. in.resetReaderIndex(); return; } try { ByteBuffer nioBuffer = maybeDecrypt(in.nioBuffer(in.readerIndex(), msgSize)); Input kryoIn = new Input(new ByteBufferInputStream(nioBuffer)); Object msg = kryos.get().readClassAndObject(kryoIn); LOG.debug("Decoded message of type {} ({} bytes)", msg != null ? msg.getClass().getName() : msg, msgSize); out.add(msg); } finally { in.skipBytes(msgSize); } }
ByteBufferInputStream is = new ByteBufferInputStream(); is.setByteBuffer(buffer); BufferedImage img = ImageIO.read(is); if(img == null)
public Object read (Connection connection, ByteBuffer buffer) { byteBufferInputStream.setByteBuffer(buffer); return json.fromJson(Object.class, byteBufferInputStream); }
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { if (in.readableBytes() < 4) { return; } in.markReaderIndex(); int msgSize = in.readInt(); checkSize(msgSize); if (in.readableBytes() < msgSize) { // Incomplete message in buffer. in.resetReaderIndex(); return; } try { ByteBuffer nioBuffer = maybeDecrypt(in.nioBuffer(in.readerIndex(), msgSize)); Input kryoIn = new Input(new ByteBufferInputStream(nioBuffer)); Object msg = kryos.get().readClassAndObject(kryoIn); LOG.debug("Decoded message of type {} ({} bytes)", msg != null ? msg.getClass().getName() : msg, msgSize); out.add(msg); } finally { in.skipBytes(msgSize); } }
Input input = new Input(new ByteBufferInputStream(data)); return (LogHandshake) getKryo().readClassAndObject(input);
Input input = new Input(new ByteBufferInputStream(data)); return (LogHandshake) getKryo().readClassAndObject(input);
/** * Tests if the data deserialzied from empty buffer is <code>null</code>. * * @throws SerializationException * Serialization Exception */ @Test public void emptyBufferSerialization() throws SerializationException { // I need to create a new buffer, because clear on the buffer will not actually erase the // data in the buffer, but only move the pointers ByteBuffer newByteBuffer = ByteBuffer.allocateDirect(1024); ByteBufferInputStream byteBufferInputStream = new ByteBufferInputStream(newByteBuffer); Input input = new Input(byteBufferInputStream); Object data = serializer.deserialize(input); assertThat(data, is(nullValue())); }
/** * Tests if the data de-serialzed from buffer with random data is <code>null</code>. * * @throws SerializationException * Serialization Exception */ @Test public void radomBufferDataSerialization() throws SerializationException { for (int i = 0; i < 64; i++) { byteBuffer.putInt(i); } byteBuffer.flip(); ByteBufferInputStream byteBufferInputStream = new ByteBufferInputStream(byteBuffer); Input input = new Input(byteBufferInputStream); Object data = serializer.deserialize(input); assertThat(data, is(nullValue())); }
/** * Performs the serialization of the given object to bytes and then performs de-serialization * from those bytes and returns the de-serialized object back. * * @param original * Original object. * @return De-serialized objects from bytes gotten from the serialization of original. * @throws SerializationException * If serialization fails. */ @SuppressWarnings("unchecked") private <T> T serializeBackAndForth(Object original) throws SerializationException { ByteBufferOutputStream byteBufferOutputStream = new ByteBufferOutputStream(byteBuffer); Output output = new Output(byteBufferOutputStream); serializer.serialize(original, output); byteBuffer.flip(); ByteBufferInputStream byteBufferInputStream = new ByteBufferInputStream(byteBuffer); Input input = new Input(byteBufferInputStream); return (T) serializer.deserialize(input); }
/** * Performs the serialization of the given object to bytes and then performs de-serialization * from those bytes and returns the de-serialized object back. * * @param original * Original object. * @return De-serialized objects from bytes gotten from the serialization of original. * @throws SerializationException * If serialization fails. */ @SuppressWarnings("unchecked") private <T> T serializeBackAndForth(Object original) throws SerializationException { ByteBufferOutputStream byteBufferOutputStream = new ByteBufferOutputStream(byteBuffer); Output output = new Output(byteBufferOutputStream); serializer.serialize(original, output); byteBuffer.flip(); ByteBufferInputStream byteBufferInputStream = new ByteBufferInputStream(byteBuffer); Input input = new Input(byteBufferInputStream); return (T) serializer.deserialize(input); }