<commit_before>package timely.netty.tcp;

import static java.nio.charset.StandardCharsets.UTF_8;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import timely.api.annotation.AnnotationResolver;
import timely.api.request.TcpRequest;

public class TcpDecoder extends ByteToMessageDecoder {

    private static final Logger LOG = LoggerFactory.getLogger(TcpDecoder.class);

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {

        ByteBuf buf = in.readBytes(in.readableBytes());
        if (buf == Unpooled.EMPTY_BUFFER) {
            return;
        }
        final String input;
        if (buf.hasArray()) {
            input = new String(buf.array(), UTF_8);
        } else {
            input = buf.toString(UTF_8);
        }
        if (StringUtils.isEmpty(input)) {
            LOG.warn("Received no input");
            return;
        }
        LOG.trace("Received input {}", input);

        String[] parts = input.split(" ");
        String operation = null;
        if (parts.length == 0 && !StringUtils.isEmpty(input)) {
            operation = input;
        } else {
            operation = parts[0];
        }
        TcpRequest tcp = null;
        try {
            tcp = (TcpRequest) AnnotationResolver.getClassForTcpOperation(operation);
        } catch (Exception e) {
            LOG.error("Error getting class for operation: " + operation, e);
        }
        if (null == tcp) {
            LOG.error("Unknown tcp operation: " + parts[0]);
            return;
        }
        tcp.parse(input);
        out.add(tcp);
        LOG.trace("Converted {} to {}", input, tcp);
    }

}
<commit_msg>closes #43, release reference to ByteBuf created in TcpDecoder.<commit_after>package timely.netty.tcp;

import static java.nio.charset.StandardCharsets.UTF_8;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import timely.api.annotation.AnnotationResolver;
import timely.api.request.TcpRequest;

public class TcpDecoder extends ByteToMessageDecoder {

    private static final Logger LOG = LoggerFactory.getLogger(TcpDecoder.class);

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {

        ByteBuf buf = in.readBytes(in.readableBytes());
        try {
            if (buf == Unpooled.EMPTY_BUFFER) {
                return;
            }
            final String input;
            if (buf.hasArray()) {
                input = new String(buf.array(), UTF_8);
            } else {
                input = buf.toString(UTF_8);
            }
            if (StringUtils.isEmpty(input)) {
                LOG.warn("Received no input");
                return;
            }
            LOG.trace("Received input {}", input);

            String[] parts = input.split(" ");
            String operation = null;
            if (parts.length == 0 && !StringUtils.isEmpty(input)) {
                operation = input;
            } else {
                operation = parts[0];
            }
            TcpRequest tcp = null;
            try {
                tcp = (TcpRequest) AnnotationResolver.getClassForTcpOperation(operation);
            } catch (Exception e) {
                LOG.error("Error getting class for operation: " + operation, e);
            }
            if (null == tcp) {
                LOG.error("Unknown tcp operation: " + parts[0]);
                return;
            }
            tcp.parse(input);
            out.add(tcp);
            LOG.trace("Converted {} to {}", input, tcp);
        } finally {
            buf.release();
        }
    }

}

{'fraction_non_alphanumeric': 0.11078646213781349, 'fraction_numerical': 0.004869734599464329, 'mean_word_length': 2.088721804511278, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6982695', 'n_tokens_mistral': 1151, 'n_tokens_neox': 1124, 'n_words': 253}