Skip to content

Commit e3a6bab

Browse files
committed
Fix build issues
1 parent e4aa56b commit e3a6bab

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

src/main/java/at/favre/lib/bytes/Bytes.java

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ public int unsignedByteAt(int index) {
10021002
*/
10031003
public char charAt(int index) {
10041004
Util.checkIndexBounds(length(), index, 2, "char");
1005-
return ByteBuffer.wrap(internalArray()).order(byteOrder).position(index).getChar();
1005+
return ((ByteBuffer) ByteBuffer.wrap(internalArray()).order(byteOrder).position(index)).getChar();
10061006
}
10071007

10081008
/**
@@ -1015,7 +1015,7 @@ public char charAt(int index) {
10151015
*/
10161016
public short shortAt(int index) {
10171017
Util.checkIndexBounds(length(), index, 2, "short");
1018-
return ByteBuffer.wrap(internalArray()).order(byteOrder).position(index).getShort();
1018+
return ((ByteBuffer) ByteBuffer.wrap(internalArray()).order(byteOrder).position(index)).getShort();
10191019
}
10201020

10211021
/**
@@ -1028,7 +1028,7 @@ public short shortAt(int index) {
10281028
*/
10291029
public int intAt(int index) {
10301030
Util.checkIndexBounds(length(), index, 4, "int");
1031-
return ByteBuffer.wrap(internalArray()).order(byteOrder).position(index).getInt();
1031+
return ((ByteBuffer) ByteBuffer.wrap(internalArray()).order(byteOrder).position(index)).getInt();
10321032
}
10331033

10341034
/**
@@ -1041,7 +1041,7 @@ public int intAt(int index) {
10411041
*/
10421042
public long longAt(int index) {
10431043
Util.checkIndexBounds(length(), index, 8, "long");
1044-
return ByteBuffer.wrap(internalArray()).order(byteOrder).position(index).getLong();
1044+
return ((ByteBuffer) ByteBuffer.wrap(internalArray()).order(byteOrder).position(index)).getLong();
10451045
}
10461046

10471047
/**
@@ -1077,7 +1077,7 @@ public double entropy() {
10771077
return new Util.Entropy<>(toList()).entropy();
10781078
}
10791079

1080-
/* CONSERVATORS POSSIBLY REUSING THE INTERNAL ARRAY ***************************************************************/
1080+
/* CONVERTERS POSSIBLY REUSING THE INTERNAL ARRAY ***************************************************************/
10811081

10821082
/**
10831083
* Create a new instance which shares the same underlying array
@@ -1517,13 +1517,14 @@ public boolean equals(Byte[] anotherArray) {
15171517
}
15181518

15191519
/**
1520-
* Compares the inner array with the inner array of given ByteBuffer
1520+
* Compares the inner array with the inner array of given ByteBuffer.
1521+
* Will check for internal array and byte order.
15211522
*
15221523
* @param buffer to compare with
15231524
* @return true if both array have same length and every byte element is the same
15241525
*/
15251526
public boolean equals(ByteBuffer buffer) {
1526-
return buffer != null && Arrays.equals(internalArray(), buffer.array());
1527+
return buffer != null && byteOrder == buffer.order() && ByteBuffer.wrap(internalArray()).order(byteOrder).equals(buffer);
15271528
}
15281529

15291530
/**
@@ -1533,17 +1534,7 @@ public boolean equals(ByteBuffer buffer) {
15331534
* @return true if the internal array are equals (see {@link Arrays#equals(byte[], byte[])})
15341535
*/
15351536
public boolean equalsContent(Bytes other) {
1536-
return other != null && equalsContent(other.internalArray());
1537-
}
1538-
1539-
/**
1540-
* Checks only for internal array content
1541-
*
1542-
* @param array to compare to
1543-
* @return true if the internal array are equals (see {@link Arrays#equals(byte[], byte[])})
1544-
*/
1545-
public boolean equalsContent(byte[] array) {
1546-
return array != null && Arrays.equals(internalArray(), array);
1537+
return other != null && Arrays.equals(internalArray(), other.internalArray());
15471538
}
15481539

15491540
@Override

src/test/java/at/favre/lib/bytes/BytesMiscTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ public void testEqualsWithByteBuffer() throws Exception {
9090
assertTrue(Bytes.allocate(4).equals(ByteBuffer.wrap(new byte[4])));
9191
assertFalse(Bytes.allocate(4).equals(ByteBuffer.wrap(new byte[3])));
9292
assertFalse(Bytes.random(16).equals(ByteBuffer.wrap(new byte[16])));
93+
assertTrue(Bytes.allocate(16).byteOrder(ByteOrder.LITTLE_ENDIAN).equals(ByteBuffer.wrap(new byte[16]).order(ByteOrder.LITTLE_ENDIAN)));
94+
assertFalse(Bytes.wrap(new byte[]{3, 2}).byteOrder(ByteOrder.BIG_ENDIAN).equals(ByteBuffer.wrap(new byte[]{3, 2}).order(ByteOrder.LITTLE_ENDIAN)));
9395
}
9496

9597
@Test
@@ -99,7 +101,6 @@ public void testEqualsContent() throws Exception {
99101
assertTrue(Bytes.from(example_bytes_seven).mutable().equalsContent(Bytes.from(example_bytes_seven).byteOrder(ByteOrder.LITTLE_ENDIAN)));
100102
assertTrue(Bytes.from(example_bytes_seven).mutable().equalsContent(Bytes.from(example_bytes_seven)));
101103
assertTrue(Bytes.from(example_bytes_seven).readOnly().equalsContent(Bytes.from(example_bytes_seven)));
102-
assertTrue(Bytes.from(example_bytes_seven).readOnly().equalsContent(example_bytes_seven));
103104
}
104105

105106
@Test

0 commit comments

Comments
 (0)