< prev index next >

src/java.base/share/classes/sun/misc/Unsafe.java

Print this page




 995      *
 996      * <p> The read will be atomic with respect to the largest power
 997      * of two that divides the GCD of the offset and the storage size.
 998      * For example, getLongUnaligned will make atomic reads of 2-, 4-,
 999      * or 8-byte storage units if the offset is zero mod 2, 4, or 8,
1000      * respectively.  There are no other guarantees of atomicity.
1001      * <p>
1002      * 8-byte atomicity is only guaranteed on platforms on which
1003      * support atomic accesses to longs.
1004      *
1005      * @param o Java heap object in which the value resides, if any, else
1006      *        null
1007      * @param offset The offset in bytes from the start of the object
1008      * @return the value fetched from the indicated object
1009      * @throws RuntimeException No defined exceptions are thrown, not even
1010      *         {@link NullPointerException}
1011      * @since 1.9
1012      */
1013     public final long getLongUnaligned(Object o, long offset) {
1014         if ((offset & 7) == 0) {
1015             return getLong(o, offset);
1016         } else if ((offset & 3) == 0) {
1017             return makeLong(getInt(o, offset),
1018                             getInt(o, offset + 4));
1019         } else if ((offset & 1) == 0) {
1020             return makeLong(getShort(o, offset),
1021                             getShort(o, offset + 2),
1022                             getShort(o, offset + 4),
1023                             getShort(o, offset + 6));
1024         } else {
1025             return makeLong(getByte(o, offset),
1026                             getByte(o, offset + 1),
1027                             getByte(o, offset + 2),
1028                             getByte(o, offset + 3),
1029                             getByte(o, offset + 4),
1030                             getByte(o, offset + 5),
1031                             getByte(o, offset + 6),
1032                             getByte(o, offset + 7));
1033         }
1034     }
1035     /**
1036      * As {@link #getLongUnaligned(Object, long)} but with an
1037      * additional argument which specifies the endianness of the value
1038      * as stored in memory.
1039      *
1040      * @param o Java heap object in which the variable resides
1041      * @param offset The offset in bytes from the start of the object
1042      * @param bigEndian The endianness of the value
1043      * @return the value fetched from the indicated object
1044      * @since 1.9
1045      */
1046     public final long getLongUnaligned(Object o, long offset, boolean bigEndian) {
1047         return convEndian(bigEndian, getLongUnaligned(o, offset));
1048     }
1049 
1050     /** @see #getLongUnaligned(Object, long) */
1051     public final int getIntUnaligned(Object o, long offset) {
1052         if ((offset & 3) == 0) {
1053             return getInt(o, offset);
1054         } else if ((offset & 1) == 0) {
1055             return makeInt(getShort(o, offset),
1056                            getShort(o, offset + 2));
1057         } else {
1058             return makeInt(getByte(o, offset),
1059                            getByte(o, offset + 1),
1060                            getByte(o, offset + 2),
1061                            getByte(o, offset + 3));
1062         }
1063     }
1064     /** @see #getLongUnaligned(Object, long, boolean) */
1065     public final int getIntUnaligned(Object o, long offset, boolean bigEndian) {
1066         return convEndian(bigEndian, getIntUnaligned(o, offset));
1067     }
1068 
1069     /** @see #getLongUnaligned(Object, long) */
1070     public final short getShortUnaligned(Object o, long offset) {
1071         if ((offset & 1) == 0) {
1072             return getShort(o, offset);
1073         } else {
1074             return makeShort(getByte(o, offset),
1075                              getByte(o, offset + 1));
1076         }
1077     }
1078     /** @see #getLongUnaligned(Object, long, boolean) */
1079     public final short getShortUnaligned(Object o, long offset, boolean bigEndian) {
1080         return convEndian(bigEndian, getShortUnaligned(o, offset));
1081     }
1082 
1083     /** @see #getLongUnaligned(Object, long) */
1084     public final char getCharUnaligned(Object o, long offset) {
1085         return (char)getShortUnaligned(o, offset);
1086     }
1087     /** @see #getLongUnaligned(Object, long, boolean) */
1088     public final char getCharUnaligned(Object o, long offset, boolean bigEndian) {
1089         return convEndian(bigEndian, getCharUnaligned(o, offset));
1090     }
1091 
1092     /**
1093      * Stores a value at some byte offset into a given Java object.
1094      * <p>
1095      * The specification of this method is the same as {@link


1102      * <p>
1103      * The write will be atomic with respect to the largest power of
1104      * two that divides the GCD of the offset and the storage size.
1105      * For example, putLongUnaligned will make atomic writes of 2-, 4-,
1106      * or 8-byte storage units if the offset is zero mod 2, 4, or 8,
1107      * respectively.  There are no other guarantees of atomicity.
1108      * <p>
1109      * 8-byte atomicity is only guaranteed on platforms on which
1110      * support atomic accesses to longs.
1111      *
1112      * @param o Java heap object in which the value resides, if any, else
1113      *        null
1114      * @param offset The offset in bytes from the start of the object
1115      * @param x the value to store
1116      * @throws RuntimeException No defined exceptions are thrown, not even
1117      *         {@link NullPointerException}
1118      * @since 1.9
1119      */
1120     public final void putLongUnaligned(Object o, long offset, long x) {
1121         if ((offset & 7) == 0) {
1122             putLong(o, offset, x);
1123         } else if ((offset & 3) == 0) {
1124             putLongParts(o, offset,
1125                          (int)(x >> 0),
1126                          (int)(x >>> 32));
1127         } else if ((offset & 1) == 0) {
1128             putLongParts(o, offset,
1129                          (short)(x >>> 0),
1130                          (short)(x >>> 16),
1131                          (short)(x >>> 32),
1132                          (short)(x >>> 48));
1133         } else {
1134             putLongParts(o, offset,
1135                          (byte)(x >>> 0),
1136                          (byte)(x >>> 8),
1137                          (byte)(x >>> 16),
1138                          (byte)(x >>> 24),
1139                          (byte)(x >>> 32),
1140                          (byte)(x >>> 40),
1141                          (byte)(x >>> 48),
1142                          (byte)(x >>> 56));
1143         }
1144     }
1145     /**
1146      * As {@link #putLongUnaligned(Object, long, long)} but with an additional
1147      * argument which specifies the endianness of the value as stored in memory.
1148      * @param o Java heap object in which the value resides
1149      * @param offset The offset in bytes from the start of the object
1150      * @param x the value to store
1151      * @param bigEndian The endianness of the value
1152      * @throws RuntimeException No defined exceptions are thrown, not even
1153      *         {@link NullPointerException}
1154      * @since 1.9
1155      */
1156     public final void putLongUnaligned(Object o, long offset, long x, boolean bigEndian) {
1157         putLongUnaligned(o, offset, convEndian(bigEndian, x));
1158     }
1159 
1160     /** @see #putLongUnaligned(Object, long, long) */
1161     public final void putIntUnaligned(Object o, long offset, int x) {
1162         if ((offset & 3) == 0) {
1163             putInt(o, offset, x);
1164         } else if ((offset & 1) == 0) {
1165             putIntParts(o, offset,
1166                         (short)(x >> 0),
1167                         (short)(x >>> 16));
1168         } else {
1169             putIntParts(o, offset,
1170                         (byte)(x >>> 0),
1171                         (byte)(x >>> 8),
1172                         (byte)(x >>> 16),
1173                         (byte)(x >>> 24));
1174         }
1175     }
1176     /** @see #putLongUnaligned(Object, long, long, boolean) */
1177     public final void putIntUnaligned(Object o, long offset, int x, boolean bigEndian) {
1178         putIntUnaligned(o, offset, convEndian(bigEndian, x));
1179     }
1180 
1181     /** @see #putLongUnaligned(Object, long, long) */
1182     public final void putShortUnaligned(Object o, long offset, short x) {
1183         if ((offset & 1) == 0) {
1184             putShort(o, offset, x);
1185         } else {
1186             putShortParts(o, offset,
1187                           (byte)(x >>> 0),
1188                           (byte)(x >>> 8));
1189         }
1190     }
1191     /** @see #putLongUnaligned(Object, long, long, boolean) */
1192     public final void putShortUnaligned(Object o, long offset, short x, boolean bigEndian) {
1193         putShortUnaligned(o, offset, convEndian(bigEndian, x));
1194     }
1195 
1196     /** @see #putLongUnaligned(Object, long, long) */
1197     public final void putCharUnaligned(Object o, long offset, char x) {
1198         putShortUnaligned(o, offset, (short)x);
1199     }
1200     /** @see #putLongUnaligned(Object, long, long, boolean) */
1201     public final void putCharUnaligned(Object o, long offset, char x, boolean bigEndian) {
1202         putCharUnaligned(o, offset, convEndian(bigEndian, x));
1203     }
1204 


1242     }
1243     private static int makeInt(byte i0, byte i1, byte i2, byte i3) {
1244         return ((toUnsignedInt(i0) << pickPos(24, 0))
1245               | (toUnsignedInt(i1) << pickPos(24, 8))
1246               | (toUnsignedInt(i2) << pickPos(24, 16))
1247               | (toUnsignedInt(i3) << pickPos(24, 24)));
1248     }
1249     private static short makeShort(byte i0, byte i1) {
1250         return (short)((toUnsignedInt(i0) << pickPos(8, 0))
1251                      | (toUnsignedInt(i1) << pickPos(8, 8)));
1252     }
1253 
1254     private static byte  pick(byte  le, byte  be) { return BE ? be : le; }
1255     private static short pick(short le, short be) { return BE ? be : le; }
1256     private static int   pick(int   le, int   be) { return BE ? be : le; }
1257 
1258     // These methods write integers to memory from smaller parts
1259     // provided by their caller.  The ordering in which these parts
1260     // are written is the native endianness of this platform.
1261     private void putLongParts(Object o, long offset, byte i0, byte i1, byte i2, byte i3, byte i4, byte i5, byte i6, byte i7) {
1262         putByte(o, offset + 0, pick(i0, i7));
1263         putByte(o, offset + 1, pick(i1, i6));
1264         putByte(o, offset + 2, pick(i2, i5));
1265         putByte(o, offset + 3, pick(i3, i4));
1266         putByte(o, offset + 4, pick(i4, i3));
1267         putByte(o, offset + 5, pick(i5, i2));
1268         putByte(o, offset + 6, pick(i6, i1));
1269         putByte(o, offset + 7, pick(i7, i0));
1270     }
1271     private void putLongParts(Object o, long offset, short i0, short i1, short i2, short i3) {
1272         putShort(o, offset + 0, pick(i0, i3));
1273         putShort(o, offset + 2, pick(i1, i2));
1274         putShort(o, offset + 4, pick(i2, i1));
1275         putShort(o, offset + 6, pick(i3, i0));
1276     }
1277     private void putLongParts(Object o, long offset, int i0, int i1) {
1278         putInt(o, offset + 0, pick(i0, i1));
1279         putInt(o, offset + 4, pick(i1, i0));
1280     }
1281     private void putIntParts(Object o, long offset, short i0, short i1) {
1282         putShort(o, offset + 0, pick(i0, i1));
1283         putShort(o, offset + 2, pick(i1, i0));
1284     }
1285     private void putIntParts(Object o, long offset, byte i0, byte i1, byte i2, byte i3) {
1286         putByte(o, offset + 0, pick(i0, i3));
1287         putByte(o, offset + 1, pick(i1, i2));
1288         putByte(o, offset + 2, pick(i2, i1));
1289         putByte(o, offset + 3, pick(i3, i0));
1290     }
1291     private void putShortParts(Object o, long offset, byte i0, byte i1) {
1292         putByte(o, offset + 0, pick(i0, i1));
1293         putByte(o, offset + 1, pick(i1, i0));
1294     }
1295 
1296     // Zero-extend an integer
1297     private static int toUnsignedInt(byte n)    { return n & 0xff; }
1298     private static int toUnsignedInt(short n)   { return n & 0xffff; }
1299     private static long toUnsignedLong(byte n)  { return n & 0xffl; }
1300     private static long toUnsignedLong(short n) { return n & 0xffffl; }
1301     private static long toUnsignedLong(int n)   { return n & 0xffffffffl; }
1302 
1303     // Maybe byte-reverse an integer
1304     private static char convEndian(boolean big, char n)   { return big == BE ? n : Character.reverseBytes(n); }
1305     private static short convEndian(boolean big, short n) { return big == BE ? n : Short.reverseBytes(n)    ; }
1306     private static int convEndian(boolean big, int n)     { return big == BE ? n : Integer.reverseBytes(n)  ; }
1307     private static long convEndian(boolean big, long n)   { return big == BE ? n : Long.reverseBytes(n)     ; }
1308 }


 995      *
 996      * <p> The read will be atomic with respect to the largest power
 997      * of two that divides the GCD of the offset and the storage size.
 998      * For example, getLongUnaligned will make atomic reads of 2-, 4-,
 999      * or 8-byte storage units if the offset is zero mod 2, 4, or 8,
1000      * respectively.  There are no other guarantees of atomicity.
1001      * <p>
1002      * 8-byte atomicity is only guaranteed on platforms on which
1003      * support atomic accesses to longs.
1004      *
1005      * @param o Java heap object in which the value resides, if any, else
1006      *        null
1007      * @param offset The offset in bytes from the start of the object
1008      * @return the value fetched from the indicated object
1009      * @throws RuntimeException No defined exceptions are thrown, not even
1010      *         {@link NullPointerException}
1011      * @since 1.9
1012      */
1013     public final long getLongUnaligned(Object o, long offset) {
1014         if ((offset & 7) == 0) {
1015             return getLong(o, offset << 1);
1016         } else if ((offset & 3) == 0) {
1017             return makeLong(getInt(o, (offset + 0) << 1),
1018                             getInt(o, (offset + 4) << 1));
1019         } else if ((offset & 1) == 0) {
1020             return makeLong(getShort(o, (offset + 0) << 1),
1021                             getShort(o, (offset + 2) << 1),
1022                             getShort(o, (offset + 4) << 1),
1023                             getShort(o, (offset + 6) << 1));
1024         } else {
1025             return makeLong(getByte(o, (offset + 0) << 1),
1026                             getByte(o, (offset + 1) << 1),
1027                             getByte(o, (offset + 2) << 1),
1028                             getByte(o, (offset + 3) << 1),
1029                             getByte(o, (offset + 4) << 1),
1030                             getByte(o, (offset + 5) << 1),
1031                             getByte(o, (offset + 6) << 1),
1032                             getByte(o, (offset + 7) << 1));
1033         }
1034     }
1035     /**
1036      * As {@link #getLongUnaligned(Object, long)} but with an
1037      * additional argument which specifies the endianness of the value
1038      * as stored in memory.
1039      *
1040      * @param o Java heap object in which the variable resides
1041      * @param offset The offset in bytes from the start of the object
1042      * @param bigEndian The endianness of the value
1043      * @return the value fetched from the indicated object
1044      * @since 1.9
1045      */
1046     public final long getLongUnaligned(Object o, long offset, boolean bigEndian) {
1047         return convEndian(bigEndian, getLongUnaligned(o, offset));
1048     }
1049 
1050     /** @see #getLongUnaligned(Object, long) */
1051     public final int getIntUnaligned(Object o, long offset) {
1052         if ((offset & 3) == 0) {
1053             return getInt(o, offset << 1);
1054         } else if ((offset & 1) == 0) {
1055             return makeInt(getShort(o, (offset + 0) << 1),
1056                            getShort(o, (offset + 2) << 1));
1057         } else {
1058             return makeInt(getByte(o, (offset + 0) << 1),
1059                            getByte(o, (offset + 1) << 1),
1060                            getByte(o, (offset + 2) << 1),
1061                            getByte(o, (offset + 3) << 1));
1062         }
1063     }
1064     /** @see #getLongUnaligned(Object, long, boolean) */
1065     public final int getIntUnaligned(Object o, long offset, boolean bigEndian) {
1066         return convEndian(bigEndian, getIntUnaligned(o, offset));
1067     }
1068 
1069     /** @see #getLongUnaligned(Object, long) */
1070     public final short getShortUnaligned(Object o, long offset) {
1071         if ((offset & 1) == 0) {
1072             return getShort(o, offset << 1);
1073         } else {
1074             return makeShort(getByte(o, (offset + 0) << 1),
1075                              getByte(o, (offset + 1) << 1));
1076         }
1077     }
1078     /** @see #getLongUnaligned(Object, long, boolean) */
1079     public final short getShortUnaligned(Object o, long offset, boolean bigEndian) {
1080         return convEndian(bigEndian, getShortUnaligned(o, offset));
1081     }
1082 
1083     /** @see #getLongUnaligned(Object, long) */
1084     public final char getCharUnaligned(Object o, long offset) {
1085         return (char)getShortUnaligned(o, offset);
1086     }
1087     /** @see #getLongUnaligned(Object, long, boolean) */
1088     public final char getCharUnaligned(Object o, long offset, boolean bigEndian) {
1089         return convEndian(bigEndian, getCharUnaligned(o, offset));
1090     }
1091 
1092     /**
1093      * Stores a value at some byte offset into a given Java object.
1094      * <p>
1095      * The specification of this method is the same as {@link


1102      * <p>
1103      * The write will be atomic with respect to the largest power of
1104      * two that divides the GCD of the offset and the storage size.
1105      * For example, putLongUnaligned will make atomic writes of 2-, 4-,
1106      * or 8-byte storage units if the offset is zero mod 2, 4, or 8,
1107      * respectively.  There are no other guarantees of atomicity.
1108      * <p>
1109      * 8-byte atomicity is only guaranteed on platforms on which
1110      * support atomic accesses to longs.
1111      *
1112      * @param o Java heap object in which the value resides, if any, else
1113      *        null
1114      * @param offset The offset in bytes from the start of the object
1115      * @param x the value to store
1116      * @throws RuntimeException No defined exceptions are thrown, not even
1117      *         {@link NullPointerException}
1118      * @since 1.9
1119      */
1120     public final void putLongUnaligned(Object o, long offset, long x) {
1121         if ((offset & 7) == 0) {
1122             putLong(o, offset << 1, x);
1123         } else if ((offset & 3) == 0) {
1124             putLongParts(o, offset,
1125                          (int)(x >> 0),
1126                          (int)(x >>> 32));
1127         } else if ((offset & 1) == 0) {
1128             putLongParts(o, offset,
1129                          (short)(x >>> 0),
1130                          (short)(x >>> 16),
1131                          (short)(x >>> 32),
1132                          (short)(x >>> 48));
1133         } else {
1134             putLongParts(o, offset,
1135                          (byte)(x >>> 0),
1136                          (byte)(x >>> 8),
1137                          (byte)(x >>> 16),
1138                          (byte)(x >>> 24),
1139                          (byte)(x >>> 32),
1140                          (byte)(x >>> 40),
1141                          (byte)(x >>> 48),
1142                          (byte)(x >>> 56));
1143         }
1144     }
1145     /**
1146      * As {@link #putLongUnaligned(Object, long, long)} but with an additional
1147      * argument which specifies the endianness of the value as stored in memory.
1148      * @param o Java heap object in which the value resides
1149      * @param offset The offset in bytes from the start of the object
1150      * @param x the value to store
1151      * @param bigEndian The endianness of the value
1152      * @throws RuntimeException No defined exceptions are thrown, not even
1153      *         {@link NullPointerException}
1154      * @since 1.9
1155      */
1156     public final void putLongUnaligned(Object o, long offset, long x, boolean bigEndian) {
1157         putLongUnaligned(o, offset, convEndian(bigEndian, x));
1158     }
1159 
1160     /** @see #putLongUnaligned(Object, long, long) */
1161     public final void putIntUnaligned(Object o, long offset, int x) {
1162         if ((offset & 3) == 0) {
1163             putInt(o, offset << 1, x);
1164         } else if ((offset & 1) == 0) {
1165             putIntParts(o, offset,
1166                         (short)(x >> 0),
1167                         (short)(x >>> 16));
1168         } else {
1169             putIntParts(o, offset,
1170                         (byte)(x >>> 0),
1171                         (byte)(x >>> 8),
1172                         (byte)(x >>> 16),
1173                         (byte)(x >>> 24));
1174         }
1175     }
1176     /** @see #putLongUnaligned(Object, long, long, boolean) */
1177     public final void putIntUnaligned(Object o, long offset, int x, boolean bigEndian) {
1178         putIntUnaligned(o, offset, convEndian(bigEndian, x));
1179     }
1180 
1181     /** @see #putLongUnaligned(Object, long, long) */
1182     public final void putShortUnaligned(Object o, long offset, short x) {
1183         if ((offset & 1) == 0) {
1184             putShort(o, offset << 1, x);
1185         } else {
1186             putShortParts(o, offset,
1187                           (byte)(x >>> 0),
1188                           (byte)(x >>> 8));
1189         }
1190     }
1191     /** @see #putLongUnaligned(Object, long, long, boolean) */
1192     public final void putShortUnaligned(Object o, long offset, short x, boolean bigEndian) {
1193         putShortUnaligned(o, offset, convEndian(bigEndian, x));
1194     }
1195 
1196     /** @see #putLongUnaligned(Object, long, long) */
1197     public final void putCharUnaligned(Object o, long offset, char x) {
1198         putShortUnaligned(o, offset, (short)x);
1199     }
1200     /** @see #putLongUnaligned(Object, long, long, boolean) */
1201     public final void putCharUnaligned(Object o, long offset, char x, boolean bigEndian) {
1202         putCharUnaligned(o, offset, convEndian(bigEndian, x));
1203     }
1204 


1242     }
1243     private static int makeInt(byte i0, byte i1, byte i2, byte i3) {
1244         return ((toUnsignedInt(i0) << pickPos(24, 0))
1245               | (toUnsignedInt(i1) << pickPos(24, 8))
1246               | (toUnsignedInt(i2) << pickPos(24, 16))
1247               | (toUnsignedInt(i3) << pickPos(24, 24)));
1248     }
1249     private static short makeShort(byte i0, byte i1) {
1250         return (short)((toUnsignedInt(i0) << pickPos(8, 0))
1251                      | (toUnsignedInt(i1) << pickPos(8, 8)));
1252     }
1253 
1254     private static byte  pick(byte  le, byte  be) { return BE ? be : le; }
1255     private static short pick(short le, short be) { return BE ? be : le; }
1256     private static int   pick(int   le, int   be) { return BE ? be : le; }
1257 
1258     // These methods write integers to memory from smaller parts
1259     // provided by their caller.  The ordering in which these parts
1260     // are written is the native endianness of this platform.
1261     private void putLongParts(Object o, long offset, byte i0, byte i1, byte i2, byte i3, byte i4, byte i5, byte i6, byte i7) {
1262         putByte(o, (offset + 0) << 1, pick(i0, i7));
1263         putByte(o, (offset + 1) << 1, pick(i1, i6));
1264         putByte(o, (offset + 2) << 1, pick(i2, i5));
1265         putByte(o, (offset + 3) << 1, pick(i3, i4));
1266         putByte(o, (offset + 4) << 1, pick(i4, i3));
1267         putByte(o, (offset + 5) << 1, pick(i5, i2));
1268         putByte(o, (offset + 6) << 1, pick(i6, i1));
1269         putByte(o, (offset + 7) << 1, pick(i7, i0));
1270     }
1271     private void putLongParts(Object o, long offset, short i0, short i1, short i2, short i3) {
1272         putShort(o, (offset + 0) << 1, pick(i0, i3));
1273         putShort(o, (offset + 2) << 1, pick(i1, i2));
1274         putShort(o, (offset + 4) << 1, pick(i2, i1));
1275         putShort(o, (offset + 6) << 1, pick(i3, i0));
1276     }
1277     private void putLongParts(Object o, long offset, int i0, int i1) {
1278         putInt(o, (offset + 0) << 1, pick(i0, i1));
1279         putInt(o, (offset + 4) << 1, pick(i1, i0));
1280     }
1281     private void putIntParts(Object o, long offset, short i0, short i1) {
1282         putShort(o, (offset + 0) << 1, pick(i0, i1));
1283         putShort(o, (offset + 2) << 1, pick(i1, i0));
1284     }
1285     private void putIntParts(Object o, long offset, byte i0, byte i1, byte i2, byte i3) {
1286         putByte(o, (offset + 0) << 1, pick(i0, i3));
1287         putByte(o, (offset + 1) << 1, pick(i1, i2));
1288         putByte(o, (offset + 2) << 1, pick(i2, i1));
1289         putByte(o, (offset + 3) << 1, pick(i3, i0));
1290     }
1291     private void putShortParts(Object o, long offset, byte i0, byte i1) {
1292         putByte(o, (offset + 0) << 1, pick(i0, i1));
1293         putByte(o, (offset + 1) << 1, pick(i1, i0));
1294     }
1295 
1296     // Zero-extend an integer
1297     private static int toUnsignedInt(byte n)    { return n & 0xff; }
1298     private static int toUnsignedInt(short n)   { return n & 0xffff; }
1299     private static long toUnsignedLong(byte n)  { return n & 0xffl; }
1300     private static long toUnsignedLong(short n) { return n & 0xffffl; }
1301     private static long toUnsignedLong(int n)   { return n & 0xffffffffl; }
1302 
1303     // Maybe byte-reverse an integer
1304     private static char convEndian(boolean big, char n)   { return big == BE ? n : Character.reverseBytes(n); }
1305     private static short convEndian(boolean big, short n) { return big == BE ? n : Short.reverseBytes(n)    ; }
1306     private static int convEndian(boolean big, int n)     { return big == BE ? n : Integer.reverseBytes(n)  ; }
1307     private static long convEndian(boolean big, long n)   { return big == BE ? n : Long.reverseBytes(n)     ; }
1308 }
< prev index next >