<commit_before>package com.philemonworks.selfdiagnose.check;

import com.philemonworks.selfdiagnose.*;
import org.apache.log4j.Logger;
import org.springframework.util.StringUtils;

import java.io.IOException;
import java.net.*;

public class CheckListeningOnHostPort extends PatternMatchingTask {
    private final static Logger log = Logger.getLogger(CheckListeningOnHostPort.class);

    private static final int TIMEOUT = 1000;
    private String url;
    private String hostName;
    private int port;
    private String description;

    private CheckListeningOnHostPort() {
    }

    public CheckListeningOnHostPort(String url, String description) {
        this.url = url;
        this.description = description;
        if (StringUtils.hasText(url)) {
            try {
                URI uri = new URI(url);
                if (uri.getHost() == null) {
                    uri = new URI("http://" + url);
                }
                if (uri.getPort() == -1) {
                    String scheme = uri.getScheme();
                    if (StringUtils.countOccurrencesOf(scheme, "http") > 0) {
                        port = 80;
                    } else if (StringUtils.countOccurrencesOf(scheme, "https") > 0) {
                        port = 443;
                    }
                } else {
                    port = uri.getPort();
                }
                    hostName = uri.getHost();
                    port = uri.getPort();
                } catch(URISyntaxException e){
                    log.error(String.format("Url %s given is not valid, Exception message is : %s", url, e.getMessage()));
                }
            }
        }<commit_msg>Fixed port out of range issue<commit_after>package com.philemonworks.selfdiagnose.check;

import com.philemonworks.selfdiagnose.*;
import org.apache.log4j.Logger;
import org.springframework.util.StringUtils;

import java.io.IOException;
import java.net.*;

public class CheckListeningOnHostPort extends PatternMatchingTask {
    private final static Logger log = Logger.getLogger(CheckListeningOnHostPort.class);

    private static final int TIMEOUT = 1000;
    private String url;
    private String hostName;
    private int port;
    private String description;

    private CheckListeningOnHostPort() {
    }

    public CheckListeningOnHostPort(String url, String description) {
        this.url = url;
        this.description = description;
        if (StringUtils.hasText(url)) {
            try {
                URI uri = new URI(url);
                if (uri.getHost() == null) {
                    uri = new URI("http://" + url);
                }
                if (uri.getPort() == -1) {
                    String scheme = uri.getScheme();
                    if (StringUtils.countOccurrencesOf(scheme, "https") > 0) {
                        port = 443;
                    } else if (StringUtils.countOccurrencesOf(scheme, "http") > 0) {
                        port = 80;
                    }
                } else {
                    port = uri.getPort();
                }
                    hostName = uri.getHost();
                } catch(URISyntaxException e){
                    log.error(String.format("Url %s given is not valid, Exception message is : %s", url, e.getMessage()));
                }
            }
        }
{'fraction_non_alphanumeric': 0.09850299401197604, 'fraction_numerical': 0.007784431137724551, 'mean_word_length': 1.6813804173354736, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '3406335', 'n_tokens_mistral': 918, 'n_tokens_neox': 845, 'n_words': 215}