Example usage for io.netty.util.internal AppendableCharSequence append

List of usage examples for io.netty.util.internal AppendableCharSequence append

Introduction

In this page you can find the example usage for io.netty.util.internal AppendableCharSequence append.

Prototype

@Override
    public AppendableCharSequence append(CharSequence csq) 

Source Link

Usage

From source file:openbns.commons.net.codec.sts.HttpObjectDecoder.java

License:Apache License

private AppendableCharSequence readHeader(ByteBuf buffer) {
    AppendableCharSequence sb = this.sb;
    sb.reset();//  www. j  av a2 s  . c  o  m
    int headerSize = this.headerSize;

    loop: for (;;) {
        char nextByte = (char) buffer.readByte();
        headerSize++;

        switch (nextByte) {
        case StsConstants.CR:
            nextByte = (char) buffer.readByte();
            headerSize++;
            if (nextByte == StsConstants.LF) {
                break loop;
            }
            break;
        case StsConstants.LF:
            break loop;
        }

        // Abort decoding if the header part is too large.
        if (headerSize >= maxHeaderSize) {
            // TODO: Respond with Bad Request and discard the traffic
            //    or close the connection.
            //       No need to notify the upstream handlers - just log.
            //       If decoding a response, just throw an exception.
            throw new TooLongFrameException("HTTP header is larger than " + maxHeaderSize + " bytes.");
        }

        sb.append(nextByte);
    }

    this.headerSize = headerSize;
    return sb;
}

From source file:openbns.commons.net.codec.sts.HttpObjectDecoder.java

License:Apache License

private AppendableCharSequence readLine(ByteBuf buffer, int maxLineLength) {
    AppendableCharSequence sb = this.sb;
    sb.reset();/*from   ww w .  j  ava 2s. c  om*/
    int lineLength = 0;
    while (true) {
        byte nextByte = buffer.readByte();
        if (nextByte == StsConstants.CR) {
            nextByte = buffer.readByte();
            if (nextByte == StsConstants.LF) {
                return sb;
            }
        } else if (nextByte == StsConstants.LF) {
            return sb;
        } else {
            if (lineLength >= maxLineLength) {
                // TODO: Respond with Bad Request and discard the traffic
                //    or close the connection.
                //       No need to notify the upstream handlers - just log.
                //       If decoding a response, just throw an exception.
                throw new TooLongFrameException("An HTTP line is larger than " + maxLineLength + " bytes.");
            }
            lineLength++;
            sb.append((char) nextByte);
        }
    }
}