From 295f1d5802e36bb3a03506baa3e5acd2325d5452 Mon Sep 17 00:00:00 2001 From: brutzman <brutzman@nps.edu> Date: Sun, 15 Aug 2021 13:22:34 -0700 Subject: [PATCH] handle IOException internally for simpler usage --- .../dis7/utilities/stream/PduRecorder.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/edu/nps/moves/dis7/utilities/stream/PduRecorder.java b/src/edu/nps/moves/dis7/utilities/stream/PduRecorder.java index b7c19c16bb..7144e700f6 100644 --- a/src/edu/nps/moves/dis7/utilities/stream/PduRecorder.java +++ b/src/edu/nps/moves/dis7/utilities/stream/PduRecorder.java @@ -86,17 +86,23 @@ public class PduRecorder implements PduReceiver /** Constructor to let the user specify all required parameters * - * @param outputPath local path to the directory to write log files to - * @param multicastAddress the multicast group address to receive data from (TODO allow unicast UDP) - * @param port the port to receive data through - * @throws IOException if something goes wrong during instantiation + * @param outputDirectory local path for directory where the log files are written + * @param multicastAddress multicast group address to receive data from (TODO allow unicast UDP) + * @param port UDP port to listen for data */ @SuppressWarnings("Convert2Lambda") - public PduRecorder(String outputPath, String multicastAddress, int port) throws IOException + public PduRecorder(String outputDirectory, String multicastAddress, int port) { - outputDirectoryPath = outputPath; - logFile = createUniquePduLogFile(new File(outputPath).toPath(), DEFAULT_FILE_PREFIX + DISLOG_FILE_EXTENSION ); - logFileWriter = new PrintWriter(new BufferedWriter(new FileWriter(logFile))); + try { + Path outputDirectoryPath = new File(outputDirectory).toPath(); + logFile = createUniquePduLogFile(outputDirectoryPath, DEFAULT_FILE_PREFIX + DISLOG_FILE_EXTENSION ); + logFileWriter = new PrintWriter(new BufferedWriter(new FileWriter(logFile))); + } + catch (IOException ex) + { + System.err.println("Exception when creating log file in directory=" + outputDirectory + "\n" + + " " + ex.getClass().getSimpleName() + ": " + ex.getLocalizedMessage()); + } disThreadedNetIF = new DisThreadedNetworkInterface(multicastAddress, port); -- GitLab