Rename StreamRedirectThread to StreamRedirector

... since it isn't a thread, but a Runnable
This commit is contained in:
0xb00bface 2020-10-31 15:10:44 +01:00
parent 2dbc6015d2
commit 808f96c04f
12 changed files with 38 additions and 38 deletions

View File

@ -15,7 +15,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ctbrec.OS;
import ctbrec.io.StreamRedirectThread;
import ctbrec.io.StreamRedirector;
import javafx.geometry.Insets;
import javafx.scene.control.Alert;
import javafx.scene.control.Label;
@ -133,8 +133,8 @@ public class DesktopIntegration {
msg.replace("-", "\\\\-").replace("\\s", "\\\\ "),
"--icon=dialog-information"
});
new Thread(new StreamRedirectThread(p.getInputStream(), System.out)).start(); // NOSONAR
new Thread(new StreamRedirectThread(p.getErrorStream(), System.err)).start(); // NOSONAR
new Thread(new StreamRedirector(p.getInputStream(), System.out)).start(); // NOSONAR
new Thread(new StreamRedirector(p.getErrorStream(), System.err)).start(); // NOSONAR
} catch (IOException e1) {
LOG.error("Notification failed", e1);
}

View File

@ -17,7 +17,7 @@ import org.slf4j.LoggerFactory;
import ctbrec.Config;
import ctbrec.OS;
import ctbrec.Settings.ProxyType;
import ctbrec.io.StreamRedirectThread;
import ctbrec.io.StreamRedirector;
public class ExternalBrowser implements AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(ExternalBrowser.class);
@ -49,11 +49,11 @@ public class ExternalBrowser implements AutoCloseable {
p = new ProcessBuilder(OS.getBrowserCommand()).start();
if (LOG.isTraceEnabled()) {
new Thread(new StreamRedirectThread(p.getInputStream(), System.out)).start();
new Thread(new StreamRedirectThread(p.getErrorStream(), System.err)).start();
new Thread(new StreamRedirector(p.getInputStream(), System.out)).start();
new Thread(new StreamRedirector(p.getErrorStream(), System.err)).start();
} else {
new Thread(new StreamRedirectThread(p.getInputStream(), OutputStream.nullOutputStream())).start();
new Thread(new StreamRedirectThread(p.getErrorStream(), OutputStream.nullOutputStream())).start();
new Thread(new StreamRedirector(p.getInputStream(), OutputStream.nullOutputStream())).start();
new Thread(new StreamRedirector(p.getErrorStream(), OutputStream.nullOutputStream())).start();
}
LOG.debug("Browser started");

View File

@ -25,7 +25,7 @@ import ctbrec.Config;
import ctbrec.Model;
import ctbrec.OS;
import ctbrec.Recording;
import ctbrec.io.StreamRedirectThread;
import ctbrec.io.StreamRedirector;
import ctbrec.io.UrlUtil;
import ctbrec.recorder.download.StreamSource;
import ctbrec.ui.controls.Dialogs;
@ -165,12 +165,12 @@ public class Player {
// create threads, which read stdout and stderr of the player process. these are needed,
// because otherwise the internal buffer for these streams fill up and block the process
Thread std = new Thread(new StreamRedirectThread(playerProcess.getInputStream(), OutputStream.nullOutputStream()));
Thread std = new Thread(new StreamRedirector(playerProcess.getInputStream(), OutputStream.nullOutputStream()));
//Thread std = new Thread(new StreamRedirectThread(playerProcess.getInputStream(), System.out));
std.setName("Player stdout pipe");
std.setDaemon(true);
std.start();
Thread err = new Thread(new StreamRedirectThread(playerProcess.getErrorStream(), OutputStream.nullOutputStream()));
Thread err = new Thread(new StreamRedirector(playerProcess.getErrorStream(), OutputStream.nullOutputStream()));
//Thread err = new Thread(new StreamRedirectThread(playerProcess.getErrorStream(), System.err));
err.setName("Player stderr pipe");
err.setDaemon(true);

View File

@ -7,7 +7,7 @@ import org.slf4j.LoggerFactory;
import ctbrec.OS;
import ctbrec.event.EventHandlerConfiguration.ActionConfiguration;
import ctbrec.io.StreamRedirectThread;
import ctbrec.io.StreamRedirector;
public class ExecuteProgram extends Action {
@ -38,11 +38,11 @@ public class ExecuteProgram extends Action {
// create threads, which read stdout and stderr of the player process. these are needed,
// because otherwise the internal buffer for these streams fill up and block the process
Thread std = new Thread(new StreamRedirectThread(process.getInputStream(), System.out));
Thread std = new Thread(new StreamRedirector(process.getInputStream(), System.out));
std.setName("Player stdout pipe");
std.setDaemon(true);
std.start();
Thread err = new Thread(new StreamRedirectThread(process.getErrorStream(), System.err));
Thread err = new Thread(new StreamRedirector(process.getErrorStream(), System.err));
err.setName("Player stderr pipe");
err.setDaemon(true);
err.start();

View File

@ -6,13 +6,13 @@ import java.io.OutputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class StreamRedirectThread implements Runnable {
private static final Logger LOG = LoggerFactory.getLogger(StreamRedirectThread.class);
public class StreamRedirector implements Runnable {
private static final Logger LOG = LoggerFactory.getLogger(StreamRedirector.class);
private InputStream in;
private OutputStream out;
public StreamRedirectThread(InputStream in, OutputStream out) {
public StreamRedirector(InputStream in, OutputStream out) {
super();
this.in = in;
this.out = out;

View File

@ -13,7 +13,7 @@ import org.slf4j.LoggerFactory;
import ctbrec.OS;
import ctbrec.io.DevNull;
import ctbrec.io.StreamRedirectThread;
import ctbrec.io.StreamRedirector;
public class VideoLengthDetector {
private static final Logger LOG = LoggerFactory.getLogger(VideoLengthDetector.class);
@ -39,8 +39,8 @@ public class VideoLengthDetector {
Process ffmpeg = Runtime.getRuntime().exec(cmdline, new String[0], videoFile.getParentFile());
int exitCode = 1;
ByteArrayOutputStream stdErrBuffer = new ByteArrayOutputStream();
Thread stdout = new Thread(new StreamRedirectThread(ffmpeg.getInputStream(), new DevNull()));
Thread stderr = new Thread(new StreamRedirectThread(ffmpeg.getErrorStream(), stdErrBuffer));
Thread stdout = new Thread(new StreamRedirector(ffmpeg.getInputStream(), new DevNull()));
Thread stderr = new Thread(new StreamRedirector(ffmpeg.getErrorStream(), stdErrBuffer));
stdout.start();
stderr.start();
exitCode = ffmpeg.waitFor();

View File

@ -12,7 +12,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ctbrec.OS;
import ctbrec.io.StreamRedirectThread;
import ctbrec.io.StreamRedirector;
import ctbrec.recorder.download.ProcessExitedUncleanException;
public class FfmpegMuxer {
@ -99,8 +99,8 @@ public class FfmpegMuxer {
// @formatter:on
LOG.debug("Command line: {}", Arrays.toString(cmdline));
Process ffmpeg = Runtime.getRuntime().exec(cmdline);
Thread stdout = new Thread(new StreamRedirectThread(ffmpeg.getInputStream(), muxLogStream));
Thread stderr = new Thread(new StreamRedirectThread(ffmpeg.getErrorStream(), muxLogStream));
Thread stdout = new Thread(new StreamRedirector(ffmpeg.getInputStream(), muxLogStream));
Thread stderr = new Thread(new StreamRedirector(ffmpeg.getErrorStream(), muxLogStream));
stdout.start();
stderr.start();
int exitCode = ffmpeg.waitFor();

View File

@ -24,7 +24,7 @@ import ctbrec.Model;
import ctbrec.OS;
import ctbrec.Recording;
import ctbrec.io.HttpClient;
import ctbrec.io.StreamRedirectThread;
import ctbrec.io.StreamRedirector;
import ctbrec.recorder.download.ProcessExitedUncleanException;
/**
@ -73,8 +73,8 @@ public class FFmpegDownload extends AbstractHlsDownload {
File ffmpegLog = File.createTempFile(targetFile.getName(), ".log");
ffmpegLog.deleteOnExit();
try (FileOutputStream mergeLogStream = new FileOutputStream(ffmpegLog)) {
Thread stdout = new Thread(new StreamRedirectThread(ffmpeg.getInputStream(), mergeLogStream));
Thread stderr = new Thread(new StreamRedirectThread(ffmpeg.getErrorStream(), mergeLogStream));
Thread stdout = new Thread(new StreamRedirector(ffmpeg.getInputStream(), mergeLogStream));
Thread stderr = new Thread(new StreamRedirector(ffmpeg.getErrorStream(), mergeLogStream));
stdout.start();
stderr.start();
exitCode = ffmpeg.waitFor();

View File

@ -40,7 +40,7 @@ import ctbrec.Recording;
import ctbrec.io.BandwidthMeter;
import ctbrec.io.HttpClient;
import ctbrec.io.HttpException;
import ctbrec.io.StreamRedirectThread;
import ctbrec.io.StreamRedirector;
import ctbrec.recorder.ProgressListener;
import ctbrec.recorder.download.HttpHeaderFactory;
import ctbrec.recorder.download.ProcessExitedUncleanException;
@ -153,8 +153,8 @@ public class MergedFfmpegHlsDownload extends AbstractHlsDownload {
File ffmpegLog = File.createTempFile(target.getName(), ".log");
ffmpegLog.deleteOnExit();
try (FileOutputStream mergeLogStream = new FileOutputStream(ffmpegLog)) {
Thread stdout = new Thread(new StreamRedirectThread(ffmpeg.getInputStream(), mergeLogStream));
Thread stderr = new Thread(new StreamRedirectThread(ffmpeg.getErrorStream(), mergeLogStream));
Thread stdout = new Thread(new StreamRedirector(ffmpeg.getInputStream(), mergeLogStream));
Thread stderr = new Thread(new StreamRedirector(ffmpeg.getErrorStream(), mergeLogStream));
stdout.start();
stderr.start();
exitCode = ffmpeg.waitFor();

View File

@ -14,7 +14,7 @@ import org.slf4j.LoggerFactory;
import ctbrec.Config;
import ctbrec.OS;
import ctbrec.Recording;
import ctbrec.io.StreamRedirectThread;
import ctbrec.io.StreamRedirector;
import ctbrec.recorder.RecordingManager;
public class CreateContactSheet extends AbstractPlaceholderAwarePostProcessor {
@ -85,8 +85,8 @@ public class CreateContactSheet extends AbstractPlaceholderAwarePostProcessor {
File ffmpegLog = File.createTempFile("create_contact_sheet_" + rec.getId() + '_', ".log");
ffmpegLog.deleteOnExit();
try (FileOutputStream mergeLogStream = new FileOutputStream(ffmpegLog)) {
Thread stdout = new Thread(new StreamRedirectThread(ffmpeg.getInputStream(), mergeLogStream));
Thread stderr = new Thread(new StreamRedirectThread(ffmpeg.getErrorStream(), mergeLogStream));
Thread stdout = new Thread(new StreamRedirector(ffmpeg.getInputStream(), mergeLogStream));
Thread stderr = new Thread(new StreamRedirector(ffmpeg.getErrorStream(), mergeLogStream));
stdout.start();
stderr.start();
exitCode = ffmpeg.waitFor();

View File

@ -14,7 +14,7 @@ import ctbrec.Config;
import ctbrec.OS;
import ctbrec.Recording;
import ctbrec.io.IoUtils;
import ctbrec.io.StreamRedirectThread;
import ctbrec.io.StreamRedirector;
import ctbrec.recorder.RecordingManager;
import ctbrec.recorder.download.ProcessExitedUncleanException;
@ -76,8 +76,8 @@ public class Remux extends AbstractPostProcessor {
File ffmpegLog = new File(video.getParentFile(), video.getName() + ".ffmpeg.log");
rec.getAssociatedFiles().add(ffmpegLog.getCanonicalPath());
try (FileOutputStream mergeLogStream = new FileOutputStream(ffmpegLog)) {
Thread stdout = new Thread(new StreamRedirectThread(ffmpeg.getInputStream(), mergeLogStream));
Thread stderr = new Thread(new StreamRedirectThread(ffmpeg.getErrorStream(), mergeLogStream));
Thread stdout = new Thread(new StreamRedirector(ffmpeg.getInputStream(), mergeLogStream));
Thread stderr = new Thread(new StreamRedirector(ffmpeg.getErrorStream(), mergeLogStream));
stdout.start();
stderr.start();
exitCode = ffmpeg.waitFor();

View File

@ -13,7 +13,7 @@ import org.slf4j.LoggerFactory;
import ctbrec.Config;
import ctbrec.OS;
import ctbrec.Recording;
import ctbrec.io.StreamRedirectThread;
import ctbrec.io.StreamRedirector;
import ctbrec.recorder.RecordingManager;
import ctbrec.recorder.download.ProcessExitedUncleanException;
@ -61,11 +61,11 @@ public class Script extends AbstractPlaceholderAwarePostProcessor {
}
private void startLogging(Process process, FileOutputStream logStream) {
Thread std = new Thread(new StreamRedirectThread(process.getInputStream(), logStream));
Thread std = new Thread(new StreamRedirector(process.getInputStream(), logStream));
std.setName("Process stdout pipe");
std.setDaemon(true);
std.start();
Thread err = new Thread(new StreamRedirectThread(process.getErrorStream(), logStream));
Thread err = new Thread(new StreamRedirector(process.getErrorStream(), logStream));
err.setName("Process stderr pipe");
err.setDaemon(true);
err.start();