Java InetAddress Create getInetAddress(long ip)

Here you can find the source of getInetAddress(long ip)

Description

get Inet Address

License

Open Source License

Declaration

public static InetAddress getInetAddress(long ip) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.net.InetAddress;

public class Main {
    private static byte[] ipWorkBytes = new byte[4];

    public static InetAddress getInetAddress(long ip) {
        synchronized (ipWorkBytes) {
            byte[] ipBytes = ipWorkBytes;
            long ipAdd = ip;

            ipBytes[0] = (byte) (ipAdd >> 24);
            ipBytes[1] = (byte) (ipAdd >> 16);
            ipBytes[2] = (byte) (ipAdd >> 8);
            ipBytes[3] = (byte) (ipAdd);
            try {
                return InetAddress.getByAddress(ipBytes);
            } catch (Exception e) {
                return null;
            }/*from   w  w  w  . j av  a2s.  c  o  m*/
        }
    }
}

Related

  1. getInetAddress()
  2. getInetAddress()
  3. getInetAddress()
  4. getInetAddress(final int[] octets, final int offset, final int length)
  5. getInetAddress(final String addressOrName)
  6. getInetAddress(Socket socket)
  7. getInetAddress(String dottedNotation)
  8. getInetAddress(String host)
  9. getInetAddress(String hostName)