Java Convert via ByteBuffer longToIPv4(Long ip)

Here you can find the source of longToIPv4(Long ip)

Description

long To I Pv

License

Apache License

Declaration

public static String longToIPv4(Long ip) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;

public class Main {
    public static String longToIPv4(Long ip) {
        ByteBuffer buffer = ByteBuffer.allocate(Integer.SIZE / 8);
        buffer.putInt(ip.intValue());//from  w ww .j  a  va  2  s.c  o m
        try {
            InetAddress addr = InetAddress.getByAddress(buffer.array());
            return addr.getHostAddress();
        } catch (UnknownHostException e) {
            return null;
        }
    }
}

Related

  1. longToBytes(long x)
  2. longToBytes(long x, byte[] dest, int offset)
  3. longToBytesNoLeadZeroes(long val)
  4. longToFourBytesFlip(long l)
  5. longToHeight(long x)
  6. longToLE(long lVal)
  7. longToShorts2(long value)
  8. shortToByteArray(short inShort)
  9. shortToBytes(short s)