Java Code Examples for io.netty.util.internal.AppendableCharSequence#append()

The following examples show how to use io.netty.util.internal.AppendableCharSequence#append() . 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: StompSubframeDecoder.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
private String readLine(ByteBuf buffer, int initialBufferSize) {
    AppendableCharSequence buf = new AppendableCharSequence(initialBufferSize);
    int lineLength = 0;
    for (;;) {
        byte nextByte = buffer.readByte();
        if (nextByte == StompConstants.CR) {
            //do nothing
        } else if (nextByte == StompConstants.LF) {
            return buf.toString();
        } else {
            if (lineLength >= maxLineLength) {
                invalidLineLength();
            }
            lineLength ++;
            buf.append((char) nextByte);
        }
    }
}
 
Example 2
Source File: LiteralStringSizeParser.java    From NioImapClient with Apache License 2.0 6 votes vote down vote up
@Override
public Integer parse(ByteBuf in) {
  AppendableCharSequence seq = sequenceRef.get();

  seq.reset();
  boolean foundStart = false;

  for (;;) {
    char c = ((char) in.readUnsignedByte());

    if (c == '{') {
      foundStart = true;
    } else if (c == '}') {
      return Integer.parseInt(seq.toString());
    } else if (foundStart) {
      seq.append(c);
    }
  }
}
 
Example 3
Source File: StompSubframeDecoder.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
private boolean readHeader(StompHeaders headers, AppendableCharSequence buf, ByteBuf buffer) {
    buf.reset();
    int lineLength = 0;
    String key = null;
    boolean valid = false;
    for (;;) {
        byte nextByte = buffer.readByte();

        if (nextByte == StompConstants.COLON && key == null) {
            key = buf.toString();
            valid = true;
            buf.reset();
        } else if (nextByte == StompConstants.CR) {
            //do nothing
        } else if (nextByte == StompConstants.LF) {
            if (key == null && lineLength == 0) {
                return false;
            } else if (valid) {
                headers.add(key, buf.toString());
            } else if (validateHeaders) {
                invalidHeader(key, buf.toString());
            }
            return true;
        } else {
            if (lineLength >= maxLineLength) {
                invalidLineLength();
            }
            if (nextByte == StompConstants.COLON && key != null) {
                valid = false;
            }
            lineLength ++;
            buf.append((char) nextByte);
        }
    }
}
 
Example 4
Source File: LiteralStringParser.java    From NioImapClient with Apache License 2.0 5 votes vote down vote up
@Override
public String parse(ByteBuf in) {
  AppendableCharSequence seq = sequenceRef.get();

  seq.reset();
  size = 0;
  expectedSize = -1;
  for (;;) {
    char c = ((char) in.readUnsignedByte());
    if (c == '{' && expectedSize < 0) {
      in.readerIndex(in.readerIndex() - 1);
      expectedSize = sizeParser.parse(in);

      in.readerIndex(in.readerIndex() + 2); // Skip CRLF
    } else if (expectedSize >= 0) {
      seq.reset();
      seq.append(c);
      size++;

      while (size < expectedSize) {
        c = ((char) in.readUnsignedByte());
        seq.append(c);
        size++;
      }

      return seq.toString();
    } else if (Character.isWhitespace(c)) {
      continue;
    } else {
      in.readerIndex(in.readerIndex() - 1);
      return stringParser.parse(in);
    }
  }
}
 
Example 5
Source File: AtomOrStringParser.java    From NioImapClient with Apache License 2.0 5 votes vote down vote up
private void append(AppendableCharSequence seq, char c) {
  if (size >= maxStringLength) {
    throw new TooLongFrameException("String is larger than " + maxStringLength + " bytes.");
  }

  size++;
  seq.append(c);
}
 
Example 6
Source File: AtomOrStringParser.java    From NioImapClient with Apache License 2.0 5 votes vote down vote up
private void append(AppendableCharSequence seq, ByteBuf buffer, int length) {
  if (size + length >= maxStringLength) {
    throw new TooLongFrameException("String is larger than " + maxStringLength + " bytes.");
  }

  size += length;
  seq.append(buffer.readCharSequence(length - 1, StandardCharsets.UTF_8));
}
 
Example 7
Source File: FetchResponseTypeParser.java    From NioImapClient with Apache License 2.0 5 votes vote down vote up
@Override
public String parse(ByteBuf in) {
  AppendableCharSequence seq = sequenceRef.get();

  seq.reset();
  size = 0;
  for (;;) {
    char nextByte = (char) in.readUnsignedByte();
    if (Character.isWhitespace(nextByte)) {
      if (size > 0) {
        break;
      }
    } else if (!Character.isLetterOrDigit(nextByte) && nextByte != '.' && nextByte != '-') {
      in.readerIndex(in.readerIndex() - 1);
      break;
    } else {
      if (size >= maxWordLength) {
        throw new TooLongFrameException(
            "Word is larger than " + maxWordLength +
                " bytes.");
      }
      size++;
      seq.append(nextByte);
    }
  }

  return seq.toString();
}