Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify CountingInputstreamWithCallback and remove unnecessary constructs #86

Merged
merged 1 commit into from
Nov 17, 2023
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 @@ -8,7 +8,8 @@
import java.io.InputStream;
import java.util.concurrent.atomic.AtomicLong;

import io.embrace.android.embracesdk.utils.Consumer;
import kotlin.Unit;
import kotlin.jvm.functions.Function1;

/**
* Counts the bytes read from an input stream and invokes a callback once the stream has reached
Expand All @@ -20,9 +21,9 @@ final class CountingInputStreamWithCallback extends FilterInputStream {
*/
private volatile long streamMark = -1;
/**
* The callback to be invoked with num of bytes after reaching the end of the stream.
* The callback to be invoked with raw bytes after reaching the end of the stream.
*/
private final Consumer<Long, byte[]> callback;
private final Function1<byte[], Unit> callback;

/**
* true if the callback has been invoked, false otherwise.
Expand All @@ -38,15 +39,14 @@ final class CountingInputStreamWithCallback extends FilterInputStream {

ByteArrayOutputStream os = new ByteArrayOutputStream();


/**
* Wraps another input stream, counting the number of bytes read.
*
* @param in the input stream to be wrapped
*/
CountingInputStreamWithCallback(InputStream in,
boolean shouldCaptureBody,
@NonNull Consumer<Long, byte[]> callback) {
@NonNull Function1<byte[], Unit> callback) {
super(in);
this.callback = callback;
this.shouldCaptureBody = shouldCaptureBody;
Expand Down Expand Up @@ -124,6 +124,6 @@ private void conditionallyCaptureBody(byte[] b, int off, int len) {

private void notifyCallback() {
callbackCompleted = true;
callback.accept(count.longValue(), os.toByteArray());
callback.invoke(os.toByteArray());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -659,11 +659,12 @@ private CountingInputStreamWithCallback countingInputStream(InputStream inputStr
return new CountingInputStreamWithCallback(
inputStream,
hasNetworkCaptureRules(),
(bytesCount, responseBody) -> {
(responseBody) -> {
if (startTime != null && endTime != null) {
cacheNetworkCallData(responseBody);
internalLogNetworkCall(startTime, endTime,true);
internalLogNetworkCall(startTime, endTime, true);
}
return null;
});
}

Expand Down

This file was deleted.

This file was deleted.