Java IPv6 Create decompressIpv6Address(String address)

Here you can find the source of decompressIpv6Address(String address)

Description

decompress input address into a canonical ipv6 address

License

Open Source License

Parameter

Parameter Description
address a parameter

Declaration


public static String decompressIpv6Address(String address) 

Method Source Code

//package com.java2s;

public class Main {
    /**/* w  w  w .j  a va2  s.c o  m*/
     * decompress input address into a canonical ipv6 address
     *
     * @param address
     * @return
     */

    public static String decompressIpv6Address(String address) {
        if (address == null) {
            return null;
        }

        address = address.trim();
        StringBuilder stdForm = new StringBuilder();
        String[] splitted = address.split(":");
        for (String str : splitted) {
            if ("".equals(str)) {
                for (int i = 0; i <= 8 - splitted.length; i++) {
                    stdForm.append("0000:");
                }
            } else {
                while (str.length() != 4)
                    str = "0" + str;
                stdForm.append(str + ":");
            }
        }
        return stdForm.substring(0, stdForm.length() - 1);
    }
}