All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hubspot.imap.utils.parsers.string.WordParser Maven / Gradle / Ivy

There is a newer version: 0.6.1
Show newest version
package com.hubspot.imap.utils.parsers.string;

import com.hubspot.imap.utils.SoftReferencedAppendableCharSequence;
import io.netty.handler.codec.TooLongFrameException;

public class WordParser extends BaseStringParser {

  private final int maxWordLength;

  public WordParser(SoftReferencedAppendableCharSequence seq, int maxWordLength) {
    super(seq);
    this.maxWordLength = maxWordLength;
  }

  @Override
  public boolean process(byte value) throws Exception {
    char nextByte = (char) value;
    if (Character.isWhitespace(nextByte)) {
      return size == 0;
    } else {
      if (size >= maxWordLength) {
        throw new TooLongFrameException(
          "Word is larger than " + maxWordLength + " bytes."
        );
      }
      size++;
      seq.append(nextByte);
      return true;
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy