导航菜单

页面标题

页面副标题

xDrip+ v04633772025.07.16 - ServerAddress.java 源代码

正在查看: xDrip+ v04633772025.07.16 应用的 ServerAddress.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.mongodb;

import java.io.Serializable;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;

public class ServerAddress implements Serializable {
    private static final long serialVersionUID = 4027873363095395504L;
    private final String host;
    private final int port;

    public static String defaultHost() {
        return "127.0.0.1";
    }

    public static int defaultPort() {
        return 27017;
    }

    public ServerAddress() {
        this(defaultHost(), defaultPort());
    }

    public ServerAddress(String str) {
        this(str, defaultPort());
    }

    public ServerAddress(String str, int i) {
        String trim = (str == null ? defaultHost() : str).trim();
        trim = trim.length() == 0 ? defaultHost() : trim;
        if (trim.startsWith("[")) {
            int indexOf = str.indexOf("]");
            if (indexOf == -1) {
                throw new IllegalArgumentException("an IPV6 address must be encosed with '[' and ']' according to RFC 2732.");
            }
            int indexOf2 = str.indexOf("]:");
            if (indexOf2 != -1) {
                if (i != defaultPort()) {
                    throw new IllegalArgumentException("can't specify port in construct and via host");
                }
                i = Integer.parseInt(str.substring(indexOf2 + 2));
            }
            trim = str.substring(0, indexOf + 1);
        } else {
            int indexOf3 = trim.indexOf(":");
            if (indexOf3 > 0) {
                if (i != defaultPort()) {
                    throw new IllegalArgumentException("can't specify port in construct and via host");
                }
                try {
                    i = Integer.parseInt(trim.substring(indexOf3 + 1));
                    trim = trim.substring(0, indexOf3).trim();
                } catch (NumberFormatException unused) {
                    throw new MongoException("host and port should be specified in host:port format");
                }
            }
        }
        this.host = trim.toLowerCase();
        this.port = i;
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }
        ServerAddress serverAddress = (ServerAddress) obj;
        return this.port == serverAddress.port && this.host.equals(serverAddress.host);
    }

    public int hashCode() {
        return (this.host.hashCode() * 31) + this.port;
    }

    public String getHost() {
        return this.host;
    }

    public int getPort() {
        return this.port;
    }

    public InetSocketAddress getSocketAddress() {
        try {
            return new InetSocketAddress(InetAddress.getByName(this.host), this.port);
        } catch (UnknownHostException e) {
            throw new MongoSocketException(e.getMessage(), this, e);
        }
    }

    public String toString() {
        return this.host + ":" + this.port;
    }

    public boolean sameHost(String str) {
        int indexOf = str.indexOf(":");
        int defaultPort = defaultPort();
        if (indexOf > 0) {
            defaultPort = Integer.parseInt(str.substring(indexOf + 1));
            str = str.substring(0, indexOf);
        }
        return getPort() == defaultPort && getHost().equalsIgnoreCase(str);
    }
}