Skip to content
Merged
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 @@ -15,7 +15,9 @@ final class ByteCountingInputStream extends InputStream {
@Override
public int read() throws IOException {
int data = source.read();
readBytes++;
if (data >= 0) {
readBytes++;
}
return data;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.datadog.profiling.uploader;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import org.junit.jupiter.api.Test;

public class ByteCountingInputStreamTest {

@Test
public void testDoesNotCountAfterEof() throws IOException {
byte[] data = {1, 2, 3};

ByteCountingInputStream in = new ByteCountingInputStream(new ByteArrayInputStream(data));
for (byte datum : data) {
int b = in.read();
assertEquals(datum, b);
}
assertEquals(data.length, (int) in.getReadBytes());

// read past EOF
assertEquals(-1, in.read());
assertEquals(data.length, (int) in.getReadBytes());
}
}