<commit_before>package io.sniffy.socket;

import io.sniffy.Sniffy;
import io.sniffy.util.ReflectionFieldCopier;
import io.sniffy.util.StackTraceExtractor;
import io.sniffy.util.ExceptionUtil;

import java.io.FileDescriptor;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.net.*;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

import static io.sniffy.socket.SocketsRegistry.SocketAddressStatus.CLOSED;

@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
class SnifferSocketImpl extends SocketImpl {

    private final static ReflectionFieldCopier socketCopier =
            new ReflectionFieldCopier(SocketImpl.class, "socket");
    private final static ReflectionFieldCopier serverSocketCopier =
            new ReflectionFieldCopier(SocketImpl.class, "serverSocket");
    private final static ReflectionFieldCopier fdCopier =
            new ReflectionFieldCopier(SocketImpl.class, "fd");
    private final static ReflectionFieldCopier addressCopier =
            new ReflectionFieldCopier(SocketImpl.class, "address");
    private final static ReflectionFieldCopier portCopier =
            new ReflectionFieldCopier(SocketImpl.class, "port");
    private final static ReflectionFieldCopier localportCopier =
            new ReflectionFieldCopier(SocketImpl.class, "localport");

    private static volatile ReflectionFieldCopier[] reflectionFieldCopiers;

    private final SocketImpl delegate;

    private InetSocketAddress address;

    private final static AtomicInteger counter = new AtomicInteger();

    private final int id = counter.getAndIncrement();

    protected SnifferSocketImpl(SocketImpl delegate) {
        this.delegate = delegate;
    }

    protected void logSocket(long millis) {
        logSocket(millis, 0, 0);
    }

    protected void logSocket(long millis, int bytesDown, int bytesUp) {
        if (Sniffy.hasSpies()) {
            if (null != address && (millis > 0 || bytesDown > 0 || bytesUp > 0)) {
                Sniffy.logSocket(id, address, millis, bytesDown, bytesUp);
            }
        }
    }

    protected void checkConnectionAllowed() throws ConnectException {
        checkConnectionAllowed(address);
    }

    protected void checkConnectionAllowed(InetSocketAddress inetSocketAddress) throws ConnectException {
        if (null != inetSocketAddress && CLOSED == SocketsRegistry.INSTANCE.resolveSocketAddressStatus(inetSocketAddress)) {
            throw new ConnectException(String.format("Connection to %s refused by Sniffy", inetSocketAddress));
        }
    }

<commit_msg>Collapse IF statements<commit_after>package io.sniffy.socket;

import io.sniffy.Sniffy;
import io.sniffy.util.ExceptionUtil;
import io.sniffy.util.ReflectionFieldCopier;

import java.io.FileDescriptor;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.net.*;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

import static io.sniffy.socket.SocketsRegistry.SocketAddressStatus.CLOSED;

@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
class SnifferSocketImpl extends SocketImpl {

    private final static ReflectionFieldCopier socketCopier =
            new ReflectionFieldCopier(SocketImpl.class, "socket");
    private final static ReflectionFieldCopier serverSocketCopier =
            new ReflectionFieldCopier(SocketImpl.class, "serverSocket");
    private final static ReflectionFieldCopier fdCopier =
            new ReflectionFieldCopier(SocketImpl.class, "fd");
    private final static ReflectionFieldCopier addressCopier =
            new ReflectionFieldCopier(SocketImpl.class, "address");
    private final static ReflectionFieldCopier portCopier =
            new ReflectionFieldCopier(SocketImpl.class, "port");
    private final static ReflectionFieldCopier localportCopier =
            new ReflectionFieldCopier(SocketImpl.class, "localport");

    private static volatile ReflectionFieldCopier[] reflectionFieldCopiers;

    private final SocketImpl delegate;

    private InetSocketAddress address;

    private final static AtomicInteger counter = new AtomicInteger();

    private final int id = counter.getAndIncrement();

    protected SnifferSocketImpl(SocketImpl delegate) {
        this.delegate = delegate;
    }

    protected void logSocket(long millis) {
        logSocket(millis, 0, 0);
    }

    protected void logSocket(long millis, int bytesDown, int bytesUp) {
        if (Sniffy.hasSpies() && null != address && (millis > 0 || bytesDown > 0 || bytesUp > 0)) {
            Sniffy.logSocket(id, address, millis, bytesDown, bytesUp);
        }
    }

    protected void checkConnectionAllowed() throws ConnectException {
        checkConnectionAllowed(address);
    }

    protected void checkConnectionAllowed(InetSocketAddress inetSocketAddress) throws ConnectException {
        if (null != inetSocketAddress && CLOSED == SocketsRegistry.INSTANCE.resolveSocketAddressStatus(inetSocketAddress)) {
            throw new ConnectException(String.format("Connection to %s refused by Sniffy", inetSocketAddress));
        }
    }


{'fraction_non_alphanumeric': 0.08042488619119878, 'fraction_numerical': 0.0018968133535660092, 'mean_word_length': 4.050766283524904, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2560918', 'n_tokens_mistral': 1422, 'n_tokens_neox': 1397, 'n_words': 339}