Fix Execution; Removed dep to commons-io;

This commit is contained in:
extio-de
2025-01-25 18:10:09 +01:00
parent 77637436f2
commit 8be692c237
2 changed files with 37 additions and 8 deletions

View File

@@ -52,11 +52,6 @@
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId> <artifactId>commons-lang3</artifactId>
</dependency> </dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.17.0</version>
</dependency>
<dependency> <dependency>
<groupId>de.extio</groupId> <groupId>de.extio</groupId>

View File

@@ -9,6 +9,7 @@ import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@@ -25,7 +26,6 @@ import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.apache.commons.io.output.TeeOutputStream;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -178,7 +178,11 @@ public class Execution {
} }
final var streams = streamFuncs.stream().map(streamFunc -> streamFunc.open().get()).toList(); final var streams = streamFuncs.stream().map(streamFunc -> streamFunc.open().get()).toList();
final var outStream = streams.size() == 1 ? streams.getFirst() : new TeeOutputStream(streams.get(0), streams.get(1)); if (streams.stream().anyMatch(Objects::isNull)) {
return;
}
final var outStream = new ProxyOutputStream(streams);
try { try {
consumer.accept(outStream); consumer.accept(outStream);
} }
@@ -236,10 +240,40 @@ public class Execution {
}); });
} }
private static class ProxyOutputStream extends OutputStream {
private final List<OutputStream> streams;
ProxyOutputStream(final List<OutputStream> streams) {
this.streams = streams;
}
@Override
public void write(final int b) throws IOException {
for (final var stream : this.streams) {
stream.write(b);
}
}
@Override
public void flush() throws IOException {
for (final var stream : this.streams) {
stream.flush();
}
}
@Override
public void close() throws IOException {
for (final var stream : this.streams) {
stream.close();
}
}
}
public record WorkPacket(Path file, String text) { public record WorkPacket(Path file, String text) {
} }
private record StreamFunc(Supplier<OutputStream> open, Consumer<OutputStream> afterClose) { private record StreamFunc(Supplier<OutputStream> open, Consumer<OutputStream> afterClose) {
} }
} }