Skip to content

Commit

Permalink
Better logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
mihxil committed Jan 24, 2025
1 parent 42fc355 commit cbfcc50
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import lombok.Setter;

import java.io.*;
import java.util.function.BiConsumer;

import org.meeuw.functional.Consumers;


/**
Expand All @@ -15,10 +18,17 @@ public class FileInputStreamTee extends TruncatedObservableInputStream {

private final OutputStream fileOutputStream;

public FileInputStreamTee(OutputStream fileOutputStream, InputStream wrapped) {
private final BiConsumer<Long, Boolean> consumer;

public FileInputStreamTee(OutputStream fileOutputStream, InputStream wrapped, BiConsumer<Long, Boolean> consumer) {
super(wrapped);
this.fileOutputStream = fileOutputStream;
this.consumer = consumer;
}
public FileInputStreamTee(OutputStream fileOutputStream, InputStream wrapped) {
this(fileOutputStream, wrapped, Consumers.biNop());
}


@Override
void write(byte[] buffer, int offset, int effectiveLength) throws IOException {
Expand All @@ -34,6 +44,7 @@ void write(int value) throws IOException {
@Override
void closed(long count, boolean truncated) throws IOException {
fileOutputStream.close();
this.consumer.accept(count, truncated);
}

}

0 comments on commit cbfcc50

Please sign in to comment.