Example usage for io.netty.buffer ByteBuf touch

List of usage examples for io.netty.buffer ByteBuf touch

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf touch.

Prototype

@Override
    public abstract ByteBuf touch();

Source Link

Usage

From source file:com.linecorp.armeria.internal.http.ByteBufHttpData.java

License:Apache License

@Override
public ByteBufHttpData replace(ByteBuf content) {
    requireNonNull(content, "content");
    content.touch();
    return new ByteBufHttpData(content, endOfStream);
}

From source file:ratpack.session.clientside.internal.ClientSideSessionStore.java

License:Apache License

private ByteBuf deserialize(ImmutableList<Cookie> sessionCookies) throws Exception {
    if (sessionCookies.isEmpty()) {
        return Unpooled.EMPTY_BUFFER;
    }/*w w w. j a va  2s.  co m*/

    StringBuilder sessionCookie = new StringBuilder();
    for (Cookie cookie : sessionCookies) {
        sessionCookie.append(cookie.value());
    }
    String[] parts = sessionCookie.toString().split(SESSION_SEPARATOR);
    if (parts.length != 2) {
        return Unpooled.buffer(0, 0);
    }
    ByteBuf payload = null;
    ByteBuf digest = null;
    ByteBuf expectedDigest = null;
    ByteBuf decryptedPayload = null;
    try {
        payload = fromBase64(bufferAllocator, parts[0]);
        digest = fromBase64(bufferAllocator, parts[1]);
        expectedDigest = signer.sign(payload, bufferAllocator);
        if (ByteBufUtil.equals(digest, expectedDigest)) {
            decryptedPayload = crypto.decrypt(payload.resetReaderIndex(), bufferAllocator);
        } else {
            decryptedPayload = Unpooled.buffer(0, 0);
        }
    } finally {
        if (payload != null) {
            payload.touch().release();
        }
        if (digest != null) {
            digest.release();
        }
        if (expectedDigest != null) {
            expectedDigest.release();
        }
    }
    return decryptedPayload.touch();
}