• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nats-io / nats.java / #2091

01 Aug 2025 02:39PM UTC coverage: 95.515% (-0.09%) from 95.606%
#2091

push

github

web-flow
Merge pull request #1378 from nats-io/nats-inet-address

Create NatsInetAddress to allow replacement of InetAddress

8 of 19 new or added lines in 5 files covered. (42.11%)

4 existing lines in 2 files now uncovered.

11861 of 12418 relevant lines covered (95.51%)

0.96 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

30.0
/src/main/java/io/nats/client/support/NatsInetAddress.java
1
// Copyright 2025 The NATS Authors
2
// Licensed under the Apache License, Version 2.0 (the "License");
3
// you may not use this file except in compliance with the License.
4
// You may obtain a copy of the License at:
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software
9
// distributed under the License is distributed on an "AS IS" BASIS,
10
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
// See the License for the specific language governing permissions and
12
// limitations under the License.
13

14
package io.nats.client.support;
15

16
import java.net.InetAddress;
17
import java.net.UnknownHostException;
18

NEW
19
public final class NatsInetAddress {
×
20
    private static NatsInetAddressProvider PROVIDER = new NatsInetAddressProvider() {};
1✔
21

22
    /**
23
     * Set the provider. Null will reset to system default
24
     * @param provider the provider
25
     */
26
    public static void setProvider(final NatsInetAddressProvider provider) {
NEW
27
        PROVIDER = provider == null ? new NatsInetAddressProvider() {} : provider;
×
NEW
28
    }
×
29

30
    public static InetAddress getByAddress(String host, byte[] addr) throws UnknownHostException {
NEW
31
        return PROVIDER.getByAddress(host, addr);
×
32
    }
33

34
    public static InetAddress getByName(String host) throws UnknownHostException {
35
        return PROVIDER.getByName(host);
1✔
36
    }
37

38
    public static InetAddress[] getAllByName(String host) throws UnknownHostException {
39
        return PROVIDER.getAllByName(host);
1✔
40
    }
41

42
    public static InetAddress getLoopbackAddress() {
NEW
43
        return PROVIDER.getLoopbackAddress();
×
44
    }
45

46
    public static InetAddress getByAddress(byte[] addr) throws UnknownHostException {
NEW
47
        return PROVIDER.getByAddress(addr);
×
48
    }
49

50
    public static InetAddress getLocalHost() throws UnknownHostException {
NEW
51
        return PROVIDER.getLocalHost();
×
52
    }
53
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc