Skip to content

Commit

Permalink
Sort members
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Nov 26, 2024
1 parent d979860 commit 3324123
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,6 @@ public final class ZipEightByteInteger implements Serializable {

private static final BigInteger HIGHEST_BIT = BigInteger.ONE.shiftLeft(63);

/**
* package private for tests only.
*/
static BigInteger toUnsignedBigInteger(final long value) {
if (value >= 0L) {
return BigInteger.valueOf(value);
} else {
return BigInteger.valueOf(value & Long.MAX_VALUE).add(HIGHEST_BIT);
}
}

/**
* Gets value as eight bytes in big-endian byte order.
*
Expand Down Expand Up @@ -110,6 +99,17 @@ public static BigInteger getValue(final byte[] bytes, final int offset) {
return toUnsignedBigInteger(getLongValue(bytes, offset));
}

/**
* package private for tests only.
*/
static BigInteger toUnsignedBigInteger(final long value) {
if (value >= 0L) {
return BigInteger.valueOf(value);
} else {
return BigInteger.valueOf(value & Long.MAX_VALUE).add(HIGHEST_BIT);
}
}

private final long value;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@
*/
public class ZipEightByteIntegerTest {

/**
* Test {@link ZipEightByteInteger#toUnsignedBigInteger(long)}.
*/
@Test
public void testToUnsignedBigInteger() {
assertEquals(BigInteger.valueOf(Long.MAX_VALUE), ZipEightByteInteger.toUnsignedBigInteger(Long.MAX_VALUE));
assertEquals(BigInteger.valueOf(Long.MAX_VALUE).shiftLeft(1), ZipEightByteInteger.toUnsignedBigInteger(0XFFFFFFFFFFFFFFFEL));
}

/**
* Test conversion from bytes.
*/
Expand All @@ -60,6 +51,16 @@ public void testBIFromMaxValue() {
assertEquals("18446744073709551615", zipEightByteInteger.getValue().toString());
}

/**
* Test conversion from bytes.
*/
@Test
public void testBILongFromBytes() {
final byte[] val = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
final ZipEightByteInteger zl = new ZipEightByteInteger(val);
assertEquals(0XFFFFFFFFFFFFFFFFL, zl.getLongValue(), "longValue from bytes");
}

/**
* Test conversion to bytes.
*/
Expand Down Expand Up @@ -108,16 +109,6 @@ public void testLongFromBytes() {
assertEquals(0xAB12345678L, zl.getLongValue(), "longValue from bytes");
}

/**
* Test conversion from bytes.
*/
@Test
public void testBILongFromBytes() {
final byte[] val = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
final ZipEightByteInteger zl = new ZipEightByteInteger(val);
assertEquals(0XFFFFFFFFFFFFFFFFL, zl.getLongValue(), "longValue from bytes");
}

/**
* Test conversion to bytes.
*/
Expand Down Expand Up @@ -155,4 +146,13 @@ public void testToString() {
new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF });
assertEquals("ZipEightByteInteger value: 18446744073709551615", zipEightByteInteger.toString());
}

/**
* Test {@link ZipEightByteInteger#toUnsignedBigInteger(long)}.
*/
@Test
public void testToUnsignedBigInteger() {
assertEquals(BigInteger.valueOf(Long.MAX_VALUE), ZipEightByteInteger.toUnsignedBigInteger(Long.MAX_VALUE));
assertEquals(BigInteger.valueOf(Long.MAX_VALUE).shiftLeft(1), ZipEightByteInteger.toUnsignedBigInteger(0XFFFFFFFFFFFFFFFEL));
}
}
10 changes: 5 additions & 5 deletions src/test/java/org/apache/commons/compress/utils/IOUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public void testCopy_inputStreamToOutputStream_nullOut() {
assertThrows(NullPointerException.class, () -> IOUtils.copy(in, (OutputStream) null));
}

@Test
public void testCopyOnZeroBufferSize() throws IOException {
assertEquals(0, IOUtils.copy(new ByteArrayInputStream(ByteUtils.EMPTY_BYTE_ARRAY), new ByteArrayOutputStream(), 0));
}

@Test
public void testCopyRangeDoesntCopyMoreThanAskedFor() throws IOException {
try (ByteArrayInputStream in = new ByteArrayInputStream(new byte[] { 1, 2, 3, 4, 5 });
Expand All @@ -106,11 +111,6 @@ public void testCopyRangeThrowsOnZeroBufferSize() {
() -> IOUtils.copyRange(new ByteArrayInputStream(ByteUtils.EMPTY_BYTE_ARRAY), 5, new ByteArrayOutputStream(), 0));
}

@Test
public void testCopyOnZeroBufferSize() throws IOException {
assertEquals(0, IOUtils.copy(new ByteArrayInputStream(ByteUtils.EMPTY_BYTE_ARRAY), new ByteArrayOutputStream(), 0));
}

@Test
public void testReadFullyOnChannelReadsFully() throws IOException {
final ByteBuffer b = ByteBuffer.allocate(20);
Expand Down

0 comments on commit 3324123

Please sign in to comment.