From a908675b020075414e9509f58af7dea835bb780f Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Sun, 29 Dec 2019 18:38:28 +0100 Subject: [PATCH] Added Videocut exception. Managed video duration error. --- .../devinsy/videocut/VideoCutException.java | 72 +++++++++++++++++++ src/fr/devinsy/videocut/VideoCutUtils.java | 12 +++- 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 src/fr/devinsy/videocut/VideoCutException.java diff --git a/src/fr/devinsy/videocut/VideoCutException.java b/src/fr/devinsy/videocut/VideoCutException.java new file mode 100644 index 0000000..39b7055 --- /dev/null +++ b/src/fr/devinsy/videocut/VideoCutException.java @@ -0,0 +1,72 @@ +/** + * Copyright (C) 2019 Christian Pierre MOMON + * + * This file is part of Videocut. + * + * Videocut is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Videocut is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Videocut. If not, see + */ +package fr.devinsy.videocut; + +/** + * The Class JugaException. + * + * @author Christian Pierre MOMON (christian.momon@devinsy.fr) + */ +public class VideoCutException extends Exception +{ + private static final long serialVersionUID = 5920490740327255439L; + + /** + * Instantiates a new Juga exception. + */ + public VideoCutException() + { + super(); + } + + /** + * Instantiates a new Juga exception. + * + * @param message + * the message + */ + public VideoCutException(final String message) + { + super(message); + } + + /** + * Instantiates a new Juga exception. + * + * @param message + * the message + * @param cause + * the cause + */ + public VideoCutException(final String message, final Throwable cause) + { + super(message, cause); + } + + /** + * Instantiates a new Juga exception. + * + * @param cause + * the cause + */ + public VideoCutException(final Throwable cause) + { + super(cause); + } +} diff --git a/src/fr/devinsy/videocut/VideoCutUtils.java b/src/fr/devinsy/videocut/VideoCutUtils.java index 4fc9621..547f436 100644 --- a/src/fr/devinsy/videocut/VideoCutUtils.java +++ b/src/fr/devinsy/videocut/VideoCutUtils.java @@ -19,6 +19,7 @@ package fr.devinsy.videocut; import org.apache.commons.io.FilenameUtils; +import org.apache.commons.lang3.StringUtils; import fr.devinsy.util.cmdexec.CmdExec; import fr.devinsy.util.cmdexec.CmdExecException; @@ -144,6 +145,7 @@ public class VideoCutUtils * @return the double * @throws CmdExecException * the cmd exec exception + * @throws VideoCutException */ public static double videoDuration(final String videoFileName) throws CmdExecException { @@ -157,7 +159,15 @@ public class VideoCutUtils System.out.println("log=[" + log + "]"); - result = Double.parseDouble(log); + if (StringUtils.isBlank(log)) + { + result = 0; + } + else + { + result = Double.parseDouble(log); + } + System.out.println("ret=[" + result + "]"); //