View Javadoc
1   package org.kuali.common.jute.net;
2   
3   import static java.net.NetworkInterface.getNetworkInterfaces;
4   import static java.util.Collections.list;
5   import static org.kuali.common.jute.base.Exceptions.illegalState;
6   
7   import java.util.Enumeration;
8   import java.util.List;
9   
10  import javax.inject.Provider;
11  
12  import com.google.common.collect.ImmutableList;
13  
14  public final class NetworkInterfacesProvider implements Provider<List<NetworkInterface>> {
15  
16      @Override
17      public List<NetworkInterface> get() {
18          try {
19              Enumeration<java.net.NetworkInterface> e = getNetworkInterfaces();
20              if (e == null) {
21                  return ImmutableList.of();
22              } else {
23                  return NetworkInterface.copyOf(list(e));
24              }
25          } catch (Exception e) {
26              throw illegalState(e);
27          }
28      }
29  
30  }