Skip to content
This repository was archived by the owner on Sep 30, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,24 @@ public class ByteAggregator {
private final ByteArrayOutputStream byteArrayOutputStream;
private final WritableByteChannel channel;

public ByteAggregator(long contentLength) {
public ByteAggregator(int contentLength) {
if (contentLength < 0) {
contentLength = 1024;
}

byteArrayOutputStream = new ByteArrayOutputStream((int) contentLength);
byteArrayOutputStream = new ByteArrayOutputStream(contentLength);
channel = Channels.newChannel(byteArrayOutputStream);

}

/**
* @deprecated Use the {@link ByteAggregator#ByteAggregator(int)} constructor instead
*/
@Deprecated
public ByteAggregator(long contentLength) {
this(Math.toIntExact(contentLength));
}

public void write(ByteBuffer buffer) throws IOException {
channel.write(buffer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class ByteAggregatorTest {

@Test
public void constructorShouldNotThrowExceptionWhenSuppliedWithNegativeLength() throws Exception {
assertNotNull(new ByteAggregator(-100));
public void constructorShouldNotThrowExceptionWhenSuppliedWithNegativeLength() {
assertDoesNotThrow(() -> new ByteAggregator(-100));
}


@Test
@SuppressWarnings("deprecation")
public void constructorShouldThrowExceptionWhenSuppliedWithABigLongNumber() {
assertThrows(ArithmeticException.class, () -> new ByteAggregator((long) Integer.MAX_VALUE + 3));
}
}