Java Code Examples for io.netty.util.Signal#expect()

The following examples show how to use io.netty.util.Signal#expect() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReplayingDecoder.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
@Override
final void channelInputClosed(ChannelHandlerContext ctx, List<Object> out) throws Exception {
    try {
        replayable.terminate();
        if (cumulation != null) {
            callDecode(ctx, internalBuffer(), out);
            decodeLast(ctx, replayable, out);
        } else {
            replayable.setCumulation(Unpooled.EMPTY_BUFFER);
            decodeLast(ctx, replayable, out);
        }
    } catch (Signal replay) {
        // Ignore
        replay.expect(REPLAY);
    }
}
 
Example 2
Source File: AllBytesParser.java    From NioImapClient with Apache License 2.0 5 votes vote down vote up
@Override
public String parse(ByteBuf buffer) {
  AppendableCharSequence sequence = sequenceReference.get();

  int readerIndex = buffer.readerIndex();
  try {
    super.parse(buffer);
  } catch (Signal e) {
    e.expect(REPLAYING_SIGNAL);
    buffer.readerIndex(readerIndex + size);
    return sequence.toString();
  }

  return sequence.toString();
}
 
Example 3
Source File: BufferedBodyParser.java    From NioImapClient with Apache License 2.0 4 votes vote down vote up
@Override
public Optional<byte[]> parse(ByteBuf in) {
  for (;;) {
    switch (state) {
      case START:
        char c = ((char) in.readUnsignedByte());
        if (c == '{') {
          in.readerIndex(in.readerIndex() - 1);
          expectedSize = sizeParser.parse(in);
          state = State.SKIP_CRLF;
          return Optional.empty();
        } else if (Character.isWhitespace(c)) {
          continue;
        } else {
          in.readerIndex(in.readerIndex() - 1);
          state = State.PARSE_STRING;
          continue;
        }
      case SKIP_CRLF:
        in.readBytes(2);
        state = State.PARSE_SIZE;
        continue;
      case PARSE_STRING:
        return Optional.of(stringParser.parse(in).getBytes(StandardCharsets.UTF_8));
      case PARSE_SIZE:
        if (buf == null) {
          buf = PooledByteBufAllocator.DEFAULT.buffer(expectedSize);
        }

        pos = in.readerIndex();
        try {
          while (size < expectedSize) {
            buf.writeByte((char) in.readUnsignedByte());
            inc();
          }
        } catch (Signal e) {
          e.expect(REPLAYING_SIGNAL);
          in.readerIndex(pos);
          return Optional.empty();
        }

        byte[] result = new byte[buf.readableBytes()];
        buf.getBytes(buf.readerIndex(), result);
        reset();

        return Optional.of(result);
    }
  }

}