aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorClyhtsuriva <61652557+clyhtsuriva@users.noreply.github.com>2021-06-27 13:45:55 +0000
committerGitHub <noreply@github.com>2021-06-27 13:45:55 +0000
commit51ee4fe5f80e6dc6d9a25c4e95f53c8c122a9434 (patch)
tree9695b8cbd65fa1e914b30597b64c79e484cacdcd /src/main/java
parente13eea333d7af2786dbbbb5ed60cea4593d5ee12 (diff)
parentf5117515ab26658e93d9efc2d99651c332840782 (diff)
Merge pull request #11 from Said-Belhadj/feature/STZ-0010
STZ-0010 : Extension check
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/musichub/main/Main.java2
-rw-r--r--src/main/java/musichub/util/PathValidation.java14
2 files changed, 13 insertions, 3 deletions
diff --git a/src/main/java/musichub/main/Main.java b/src/main/java/musichub/main/Main.java
index e7ca721..1fa5c52 100644
--- a/src/main/java/musichub/main/Main.java
+++ b/src/main/java/musichub/main/Main.java
@@ -94,7 +94,7 @@ public class Main {
System.out.println("Song content: ");
String content = scan.nextLine();
if (!isPathValid(content)) {
- String logMsg = "The music file was not found with the path you've provided.";
+ String logMsg = "The music file was not found with the path you've provided or the extension is not .wav";
LogHandler.write(logMsg, "WARNING"); //write a line in the log file
System.out.println(logMsg + "\nType h for available commands");
choice = scan.nextLine();
diff --git a/src/main/java/musichub/util/PathValidation.java b/src/main/java/musichub/util/PathValidation.java
index df11388..ea00c24 100644
--- a/src/main/java/musichub/util/PathValidation.java
+++ b/src/main/java/musichub/util/PathValidation.java
@@ -25,15 +25,25 @@ public final class PathValidation {
}
/**
- * Method that checks the validity of a given path
+ * Method that checks the validity of a given path and file.
*
* @param inputPath the path given by the user
* @return a boolean
*/
public static boolean isPathValid(String inputPath) {
+ boolean isExtensionValid = false;
+
+ int index = inputPath.lastIndexOf('.');
+ if (index > 0) {
+ String extension = inputPath.substring(index + 1);
+ if (extension.equals("wav")) {
+ isExtensionValid = true;
+ }
+ }
+
Path path = Paths.get(inputPath);
- return Files.exists(path);
+ return (Files.exists(path) & isExtensionValid);
}
} \ No newline at end of file