<commit_before>package no.ntnu.okse.protocol.stomp.listeners;

import asia.stampy.client.message.send.SendMessage;
import asia.stampy.common.gateway.HostPort;
import asia.stampy.common.gateway.StampyMessageListener;
import asia.stampy.common.message.StampyMessage;
import asia.stampy.common.message.StompMessageType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.invoke.MethodHandles;
import java.nio.charset.Charset;

public class MIMEtypeListener implements StampyMessageListener {
    private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

    class CharsetException extends Exception {
        CharsetException(String msg) {
            super(msg);
        }
    }

    private String getCharSet(String contentType){
        String charset = null;
        String[] values = contentType.split(";");
        for (String value : values) {
            value = value.trim();

            if (value.toLowerCase().startsWith("charset=")) {
                charset = value.substring("charset=".length());
            }
        }
        return charset;
    }

    @Override
    public StompMessageType[] getMessageTypes() {
        return new StompMessageType[]{StompMessageType.SEND};
    }

    @Override
    public boolean isForMessage(StampyMessage<?> message) {
        return true;
    }

    @Override
    public void messageReceived(StampyMessage<?> stampyMessage, HostPort hostPort) throws Exception {
        test(stampyMessage, hostPort);
    }

    private void test(StampyMessage<?> stampyMessage, HostPort hostPort) throws CharsetException{
        SendMessage sendMessage = (SendMessage) stampyMessage;
        String charset = getCharSet(sendMessage.getHeader().getContentType());
        if(charset == null || charset.equals("")){
            throw new CharsetException("Invalid charset given with the message");<commit_msg>Added an if for empty charsets<commit_after>package no.ntnu.okse.protocol.stomp.listeners;

import asia.stampy.client.message.send.SendMessage;
import asia.stampy.common.gateway.HostPort;
import asia.stampy.common.gateway.StampyMessageListener;
import asia.stampy.common.message.StampyMessage;
import asia.stampy.common.message.StompMessageType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.invoke.MethodHandles;
import java.nio.charset.Charset;

public class MIMEtypeListener implements StampyMessageListener {
    private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

    class CharsetException extends Exception {
        CharsetException(String msg) {
            super(msg);
        }
    }

    private String getCharSet(String contentType){
        String charset = null;
        if(contentType == null)
            return "";
        String[] values = contentType.split(";");
        for (String value : values) {
            value = value.trim();

            if (value.toLowerCase().startsWith("charset=")) {
                charset = value.substring("charset=".length());
            }
        }
        return charset;
    }

    @Override
    public StompMessageType[] getMessageTypes() {
        return new StompMessageType[]{StompMessageType.SEND};
    }

    @Override
    public boolean isForMessage(StampyMessage<?> message) {
        return true;
    }

    @Override
    public void messageReceived(StampyMessage<?> stampyMessage, HostPort hostPort) throws Exception {
        test(stampyMessage, hostPort);
    }

    private void test(StampyMessage<?> stampyMessage, HostPort hostPort) throws CharsetException{
        SendMessage sendMessage = (SendMessage) stampyMessage;
        String charset = getCharSet(sendMessage.getHeader().getContentType());
        if(charset == null || charset.equals("")){
            throw new CharsetException("Invalid charset given with the message");
{'fraction_non_alphanumeric': 0.10154241645244216, 'fraction_numerical': 0.0010282776349614395, 'mean_word_length': 3.318534961154273, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '1221131', 'n_tokens_mistral': 1098, 'n_tokens_neox': 1077, 'n_words': 229}