11package twg2 .io .files ;
22
3- /** A utility class for converting primitive types to bytes.
3+ /** A utility class for converting primitive types to/from bytes in big-endian order .
44 * For example converting an integer to 4 bytes and storing those 4 bytes
55 * at a specific location in a byte array.
66 * @author TeamworkGuy2
@@ -10,32 +10,33 @@ public final class Bytes {
1010
1111 private Bytes () { throw new AssertionError ("cannot instantiate Bytes" ); }
1212
13- /** Write a double to the specified byte array as 8 bytes
13+
14+ /** Write a double to the specified byte array as 8 bytes (big-endian order)
1415 * @param value the double to write
15- * @param b the byte array to write the long to
16+ * @param b the byte array to write the 'value' to
1617 * @param offset the offset into the array at which to write the 8 bytes
1718 */
18- public static final void writeDouble (double value , byte [] b , int offset ) {
19+ public static void writeDouble (double value , byte [] b , int offset ) {
1920 writeLong (Double .doubleToRawLongBits (value ), b , offset );
2021 }
2122
2223
23- /** Write a float to the specified byte array as 4 bytes
24+ /** Write a float to the specified byte array as 4 bytes (big-endian order)
2425 * @param value the float to write
25- * @param b the byte array to write the float to
26+ * @param b the byte array to write the 'value' to
2627 * @param offset the offset into the array at which to write the 4 bytes
2728 */
28- public static final void writeFloat (float value , byte [] b , int offset ) {
29+ public static void writeFloat (float value , byte [] b , int offset ) {
2930 writeInt (Float .floatToRawIntBits (value ), b , offset );
3031 }
3132
3233
33- /** Write a long to the specified byte array as 8 bytes
34+ /** Write a long to the specified byte array as 8 bytes (big-endian order)
3435 * @param value the long to write
35- * @param b the byte array to write the long to
36+ * @param b the byte array to write the 'value' to
3637 * @param offset the offset into the array at which to write the 8 bytes
3738 */
38- public static final void writeLong (long value , byte [] b , int offset ) {
39+ public static void writeLong (long value , byte [] b , int offset ) {
3940 b [offset ] = (byte )(value >>> 56 );
4041 b [offset +1 ] = (byte )(value >>> 48 );
4142 b [offset +2 ] = (byte )(value >>> 40 );
@@ -47,52 +48,52 @@ public static final void writeLong(long value, byte[] b, int offset) {
4748 }
4849
4950
50- /** Write an int to the specified byte array as 4 bytes
51+ /** Write an int to the specified byte array as 4 bytes (big-endian order)
5152 * @param value the integer to write
52- * @param b the byte array to write the integer to
53+ * @param b the byte array to write the 'value' to
5354 * @param offset the offset into the array at which to write the 4 bytes
5455 */
55- public static final void writeInt (int value , byte [] b , int offset ) {
56+ public static void writeInt (int value , byte [] b , int offset ) {
5657 b [offset ] = (byte )(value >>> 24 );
5758 b [offset +1 ] = (byte )(value >>> 16 );
5859 b [offset +2 ] = (byte )(value >>> 8 );
5960 b [offset +3 ] = (byte )(value );
6061 }
6162
6263
63- /** Write a short to the specified byte array as 2 bytes
64+ /** Write a short to the specified byte array as 2 bytes (big-endian order)
6465 * @param value the short to write
65- * @param b the byte array to write the short to
66+ * @param b the byte array to write the 'value' to
6667 * @param offset the offset into the array at which to write the 2 bytes
6768 */
68- public static final void writeShort (short value , byte [] b , int offset ) {
69+ public static void writeShort (short value , byte [] b , int offset ) {
6970 b [offset ] = (byte )(value >>> 8 );
7071 b [offset +1 ] = (byte )(value );
7172 }
7273
7374
74- /** Write a boolean to the specified byte array as 1 byte (1=true, 0=false)
75+ /** Write a boolean to the specified byte array as 1 byte (1=true, 0=false) (big-endian order)
7576 * @param value the boolean to write
76- * @param b the byte array to write the short to
77+ * @param b the byte array to write the 'value' to
7778 * @param offset the offset into the array at which to write the byte
7879 */
79- public static final void writeBoolean (boolean value , byte [] b , int offset ) {
80+ public static void writeBoolean (boolean value , byte [] b , int offset ) {
8081 b [offset ] = (byte )(value ? 1 : 0 );
8182 }
8283
8384
84- /** Read a double value from the specified location in the specified array
85+ /** Read a double value from the specified location in the specified array (assumes big-endian order)
8586 * @param b the array to read the double from
8687 * @param offset the offset into the array at which to read the 8 bytes
8788 * @return eight bytes read from the indices {@code [offset, offset+3]} and
8889 * converted to a double
8990 */
90- public static final double readDouble (byte [] b , int offset ) {
91+ public static double readDouble (byte [] b , int offset ) {
9192 return Double .longBitsToDouble (readLong (b , offset ));
9293 }
9394
9495
95- /** Read a float value from the specified location in the specified array
96+ /** Read a float value from the specified location in the specified array (assumes big-endian order)
9697 * @param b the array to read the float from
9798 * @param offset the offset into the array at which to read the 4 bytes
9899 * @return four bytes read from the indices {@code [offset, offset+3]} and
@@ -103,7 +104,7 @@ public static final float readFloat(byte[] b, int offset) {
103104 }
104105
105106
106- /** Read a long value from the specified location in the specified array
107+ /** Read a long value from the specified location in the specified array (assumes big-endian order)
107108 * @param b the array to read the long from
108109 * @param offset the offset into the array at which to read the 8 bytes
109110 * @return eight bytes read from the indices {@code [offset, offset+3]} and converted to
@@ -124,7 +125,7 @@ public static final long readLong(byte[] b, int offset) {
124125 }
125126
126127
127- /** Read an integer value from the specified location in the specified array
128+ /** Read an integer value from the specified location in the specified array (assumes big-endian order)
128129 * @param b the array to read the integer from
129130 * @param offset the offset into the array at which to read the 4 bytes
130131 * @return four bytes read from the indices {@code [offset, offset+3]} and converted to
@@ -135,7 +136,7 @@ public static final int readInt(byte[] b, int offset) {
135136 }
136137
137138
138- /** Read a short value from the specified location in the specified array
139+ /** Read a short value from the specified location in the specified array (assumes big-endian order)
139140 * @param b the array to read the short from
140141 * @param offset the offset into the array at which to read the 2 bytes
141142 * @return two bytes read from indices {@code offset} and {@code offset+1} and converted to
@@ -146,7 +147,7 @@ public static final short readShort(byte[] b, int offset) {
146147 }
147148
148149
149- /** Read a boolean value from the specified location in the specified byte array (1=true, 0=false)
150+ /** Read a boolean value from the specified location in the specified byte array (1=true, 0=false) (assumes big-endian order)
150151 * @param b the array to read the boolean from
151152 * @param offset the offset into the array at which to read the byte
152153 * @return two bytes read from indices {@code offset} and {@code offset+1} and converted to
0 commit comments