Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1e356e80 authored by Jesse Wilson's avatar Jesse Wilson Committed by Android (Google) Code Review
Browse files

Merge "Deprecate a method that formats only IPv4 addresses."

parents e1cf8073 07481ccd
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -190640,10 +190640,10 @@
 synchronized="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 deprecated="deprecated"
 visibility="public"
>
<parameter name="addr" type="int">
<parameter name="ipv4Address" type="int">
</parameter>
</method>
<method name="formatShortFileSize"
+4 −9
Original line number Diff line number Diff line
@@ -125,24 +125,19 @@ public class NetworkUtils {

    /**
     * Convert a IPv4 address from an integer to an InetAddress.
     * @param hostAddr is an Int corresponding to the IPv4 address in network byte order
     * @return the IP address as an {@code InetAddress}, returns null if
     * unable to convert or if the int is an invalid address.
     * @param hostAddress an int corresponding to the IPv4 address in network byte order
     */
    public static InetAddress intToInetAddress(int hostAddress) {
        InetAddress inetAddress;
        byte[] addressBytes = { (byte)(0xff & hostAddress),
                                (byte)(0xff & (hostAddress >> 8)),
                                (byte)(0xff & (hostAddress >> 16)),
                                (byte)(0xff & (hostAddress >> 24)) };

        try {
           inetAddress = InetAddress.getByAddress(addressBytes);
           return InetAddress.getByAddress(addressBytes);
        } catch (UnknownHostException e) {
           return null;
           throw new AssertionError();
        }

        return inetAddress;
    }

    /**
+18 −17
Original line number Diff line number Diff line
@@ -17,10 +17,11 @@
package android.text.format;

import android.content.Context;
import android.net.NetworkUtils;

/**
 * Utility class to aid in formatting common values that are not covered
 * by the standard java.util.Formatter.
 * by {@link java.util.Formatter}
 */
public final class Formatter {

@@ -28,8 +29,8 @@ public final class Formatter {
     * Formats a content size to be in the form of bytes, kilobytes, megabytes, etc
     *
     * @param context Context to use to load the localized units
     * @param number size value to be formated
     * @return formated string with the number
     * @param number size value to be formatted
     * @return formatted string with the number
     */
    public static String formatFileSize(Context context, long number) {
        return formatFileSize(context, number, false);
@@ -37,7 +38,7 @@ public final class Formatter {

    /**
     * Like {@link #formatFileSize}, but trying to generate shorter numbers
     * (showing fewer digits of precisin).
     * (showing fewer digits of precision).
     */
    public static String formatShortFileSize(Context context, long number) {
        return formatFileSize(context, number, true);
@@ -98,15 +99,15 @@ public final class Formatter {
     * the IP address.  The IP address is expected to be in little-endian format (LSB first). That
     * is, 0x01020304 will return "4.3.2.1".
     *
     * @param addr the IP address as a packed integer with LSB first.
     * @param ipv4Address the IP address as a packed integer with LSB first.
     * @return string with canonical IP address format.
     *
     * @deprecated this method doesn't support IPv6 addresses. Prefer {@link
     *     java.net.InetAddress#getHostAddress()}, which supports both IPv4 and
     *     IPv6 addresses.
     */
    public static String formatIpAddress(int addr) {
        StringBuffer buf = new StringBuffer();
        buf.append(addr  & 0xff).append('.').
            append((addr >>>= 8) & 0xff).append('.').
            append((addr >>>= 8) & 0xff).append('.').
            append((addr >>>= 8) & 0xff);
        return buf.toString();
    @Deprecated
    public static String formatIpAddress(int ipv4Address) {
        return NetworkUtils.intToInetAddress(ipv4Address).getHostAddress();
    }
}