Use Number.reverseBytes() instead of custom impl

This commit is contained in:
Trustin Lee 2013-01-10 18:47:21 +09:00
parent 340da3e97b
commit 5bd8b41a58

View File

@ -241,7 +241,7 @@ public final class ByteBufUtil {
* Toggles the endianness of the specified 16-bit short integer. * Toggles the endianness of the specified 16-bit short integer.
*/ */
public static short swapShort(short value) { public static short swapShort(short value) {
return (short) (value << 8 | value >>> 8 & 0xff); return Short.reverseBytes(value);
} }
/** /**
@ -259,16 +259,14 @@ public final class ByteBufUtil {
* Toggles the endianness of the specified 32-bit integer. * Toggles the endianness of the specified 32-bit integer.
*/ */
public static int swapInt(int value) { public static int swapInt(int value) {
return swapShort((short) value) << 16 | return Integer.reverseBytes(value);
swapShort((short) (value >>> 16)) & 0xffff;
} }
/** /**
* Toggles the endianness of the specified 64-bit long integer. * Toggles the endianness of the specified 64-bit long integer.
*/ */
public static long swapLong(long value) { public static long swapLong(long value) {
return (long) swapInt((int) value) << 32 | return Long.reverseBytes(value);
swapInt((int) (value >>> 32)) & 0xffffffffL;
} }
private static int firstIndexOf(ByteBuf buffer, int fromIndex, int toIndex, byte value) { private static int firstIndexOf(ByteBuf buffer, int fromIndex, int toIndex, byte value) {