Package io.netty.handler.codec

Examples of io.netty.handler.codec.CorruptedFrameException


      if (buf[i] >= 0) {

        int length = CodedInputStream.newInstance(buf, 0, i + 1).readRawVarint32();

        if (length < 0) {
          throw new CorruptedFrameException("negative length: " + length);
        }
        if (length == 0) {
          throw new CorruptedFrameException("Received a message of length 0.");
        }

        if (in.readableBytes() < length) {
          in.resetReaderIndex();
          return;
        } else {
          // need to make buffer copy, otherwise netty will try to refill this buffer if we move the readerIndex forward...
          // TODO: Can we avoid this copy?
          ByteBuf outBuf = in.copy(in.readerIndex(), length);
          in.skipBytes(length);
         
          if (RpcConstants.EXTRA_DEBUGGING)
            logger.debug(String.format(
                "ReaderIndex is %d after length header of %d bytes and frame body of length %d bytes.",
                in.readerIndex(), i + 1, length));
          out.add(outBuf);
          return;
        }
      }
    }

    // Couldn't find the byte whose MSB is off.
    throw new CorruptedFrameException("length wider than 32-bit");

  }
View Full Code Here


    if (buffer.readableBytes() > 0) {
     
      if(RpcConstants.EXTRA_DEBUGGING) logger.debug("Reading raw body, buffer has {} bytes available, is available {}.", buffer.readableBytes(), is.available());
      checkTag(is, RpcEncoder.RAW_BODY_TAG);
      dBodyLength = readRawVarint32(is);
      if(buffer.readableBytes() != dBodyLength) throw new CorruptedFrameException(String.format("Expected to receive a raw body of %d bytes but received a buffer with %d bytes.", dBodyLength, buffer.readableBytes()));
      dBody = buffer.slice();
      dBody.retain();
      if(RpcConstants.EXTRA_DEBUGGING) logger.debug("Read raw body of {}", dBody);
     
    }else{
View Full Code Here

  }

  private void checkTag(ByteBufInputStream is, int expectedTag) throws IOException {
    int actualTag = readRawVarint32(is);
    if (actualTag != expectedTag){
      throw new CorruptedFrameException(String.format("Expected to read a tag of %d but actually received a value of %d.  Happened after reading %d message.", expectedTag, actualTag, messageCounter.get()));
    }
  }
View Full Code Here

            for (int i = 0; i < 5; i++) {
              if (is.readByte() >= 0) {
                return result;
              }
            }
            throw new CorruptedFrameException("Encountered a malformed varint.");
          }
        }
      }
    }
    return result;
View Full Code Here

      if (buf[i] >= 0) {

        int length = CodedInputStream.newInstance(buf, 0, i + 1).readRawVarint32();

        if (length < 0) {
          throw new CorruptedFrameException("negative length: " + length);
        }
        if (length == 0) {
          throw new CorruptedFrameException("Received a message of length 0.");
        }

        if (in.readableBytes() < length) {
          in.resetReaderIndex();
          return;
        } else {
          // need to make buffer copy, otherwise netty will try to refill this buffer if we move the readerIndex forward...
          // TODO: Can we avoid this copy?
          ByteBuf outBuf = allocator.buffer(length);
          if(outBuf == null){
            logger.warn("Failure allocating buffer on incoming stream due to memory limits.  Current Allocation: {}.", allocator.getAllocatedMemory());
            in.resetReaderIndex();
            outOfMemoryHandler.handle();
            return;
          }
          outBuf.writeBytes(in, in.readerIndex(), length);
         
          in.skipBytes(length);
         
          if (RpcConstants.EXTRA_DEBUGGING)
            logger.debug(String.format(
                "ReaderIndex is %d after length header of %d bytes and frame body of length %d bytes.",
                in.readerIndex(), i + 1, length));
         
          out.add(outBuf);
          return;
        }
      }
    }

    // Couldn't find the byte whose MSB is off.
    throw new CorruptedFrameException("length wider than 32-bit");

  }
View Full Code Here

            buf[i] = in.readByte();
            if (buf[i] >= 0) {
                int length = CodedInputStream.newInstance(buf, 0, i + 1).readRawVarint32();
                if (length < 0) {
                    throw new CorruptedFrameException("negative length: " + length);
                }

                if (in.readableBytes() < length) {
                    in.resetReaderIndex();
                    return null;
                } else {
                    return in.readBytes(length);
                }
            }
        }

        // Couldn't find the byte whose MSB is off.
        throw new CorruptedFrameException("length wider than 32-bit");
    }
View Full Code Here

        // Check the magic number.
        int magicNumber = in.readUnsignedByte();
        if (magicNumber != 'F') {
            in.resetReaderIndex();
            throw new CorruptedFrameException(
                    "Invalid magic number: " + magicNumber);
        }

        // Wait until the whole data is available.
        int dataLength = in.readInt();
View Full Code Here

    private void protocolViolation(ChannelHandlerContext ctx, String reason) {
        checkpoint(State.CORRUPT);
        if (ctx.channel().isActive()) {
            ctx.flush().addListener(ChannelFutureListener.CLOSE);
        }
        throw new CorruptedFrameException(reason);
    }
View Full Code Here

            frame.setByte(i, frame.getByte(i) ^ maskingKey[i % 4]);
        }
    }

    private void protocolViolation(ChannelHandlerContext ctx, String reason) {
        protocolViolation(ctx, new CorruptedFrameException(reason));
    }
View Full Code Here

        logger.debug("Reading raw body, buffer has {} bytes available, is available {}.", buffer.readableBytes(), is.available());
      }
      checkTag(is, RpcEncoder.RAW_BODY_TAG);
      dBodyLength = readRawVarint32(is);
      if (buffer.readableBytes() != dBodyLength) {
        throw new CorruptedFrameException(String.format("Expected to receive a raw body of %d bytes but received a buffer with %d bytes.", dBodyLength, buffer.readableBytes()));
      }
      dBody = buffer.slice();
      dBody.retain();
      if (RpcConstants.EXTRA_DEBUGGING) {
        logger.debug("Read raw body of {}", dBody);
View Full Code Here

TOP

Related Classes of io.netty.handler.codec.CorruptedFrameException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.