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

This commit is contained in:
Jesse Wilson
2011-01-06 19:33:52 -08:00
committed by Android (Google) Code Review
3 changed files with 24 additions and 28 deletions

View File

@@ -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"

View File

@@ -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);
} catch(UnknownHostException e) {
return null;
return InetAddress.getByAddress(addressBytes);
} catch (UnknownHostException e) {
throw new AssertionError();
}
return inetAddress;
}
/**

View File

@@ -17,32 +17,33 @@
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 {
/**
* 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);
}
/**
* 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);
}
private static String formatFileSize(Context context, long number, boolean shorter) {
if (context == null) {
return "";
@@ -92,21 +93,21 @@ public final class Formatter {
getString(com.android.internal.R.string.fileSizeSuffix,
value, context.getString(suffix));
}
/**
* Returns a string in the canonical IP format ###.###.###.### from a packed integer containing
* 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();
}
}