From 5448763b9d9d7795be1d7794c37761712dcf5cb1 Mon Sep 17 00:00:00 2001 From: 0xboobface <0xboobface@gmail.com> Date: Fri, 3 Jan 2020 21:53:37 +0100 Subject: [PATCH] Fix possible NPE --- .../ctbrec/recorder/download/dash/FfmpegMuxer.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/ctbrec/recorder/download/dash/FfmpegMuxer.java b/common/src/main/java/ctbrec/recorder/download/dash/FfmpegMuxer.java index 971b89b6..47723943 100644 --- a/common/src/main/java/ctbrec/recorder/download/dash/FfmpegMuxer.java +++ b/common/src/main/java/ctbrec/recorder/download/dash/FfmpegMuxer.java @@ -6,6 +6,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.nio.file.Files; import java.util.Arrays; +import java.util.Optional; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -22,9 +23,16 @@ public class FfmpegMuxer { public FfmpegMuxer(File segmentDir, File targetFile) throws IOException { this.segmentDir = segmentDir; - String[] videoSegments = segmentDir.list((dir, name) -> name.startsWith("video_")); + if (!segmentDir.exists()) { + throw new IOException("Directory does not exist " + segmentDir); + } + if (!segmentDir.isDirectory()) { + throw new IOException(segmentDir + " is not a directory"); + } + + String[] videoSegments = Optional.ofNullable(segmentDir.list((dir, name) -> name.startsWith("video_"))).orElse(new String[0]); Arrays.sort(videoSegments); - String[] audioSegments = segmentDir.list((dir, name) -> name.startsWith("audio_")); + String[] audioSegments = Optional.ofNullable(segmentDir.list((dir, name) -> name.startsWith("audio_"))).orElse(new String[0]); Arrays.sort(audioSegments); File mp4VideoTrack = new File(segmentDir, "video.mp4");