diff --git a/task01/src/com/example/task01/Task01Main.java b/task01/src/com/example/task01/Task01Main.java index 5dfc11b..927bef2 100644 --- a/task01/src/com/example/task01/Task01Main.java +++ b/task01/src/com/example/task01/Task01Main.java @@ -1,7 +1,6 @@ package com.example.task01; -import java.io.File; -import java.io.IOException; +import java.io.*; public class Task01Main { public static void main(String[] args) throws IOException, InterruptedException { @@ -14,7 +13,27 @@ public static void main(String[] args) throws IOException, InterruptedException } public static String extractSoundName(File file) throws IOException, InterruptedException { - // your implementation here - return "sound name"; + + String title = null; + + ProcessBuilder processBuilder = new ProcessBuilder(); + processBuilder.command("ffprobe", "-v", "error", "-of", "flat", "-show_format", file.getName()); + processBuilder.directory(file.getParentFile()); + + Process process = processBuilder.start(); + + try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) { + String line; + while ((line = reader.readLine()) != null) { + if (line.startsWith("format.tags.title")) { + title = line.split("=")[1].replace("\"", ""); + break; + } + } + } + + process.waitFor(); + + return title; } } diff --git a/task02/src/com/example/task02/Task02Main.java b/task02/src/com/example/task02/Task02Main.java index 750f7ba..8188da1 100644 --- a/task02/src/com/example/task02/Task02Main.java +++ b/task02/src/com/example/task02/Task02Main.java @@ -1,7 +1,9 @@ package com.example.task02; import java.io.IOException; -import java.nio.file.Path; +import java.nio.file.*; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; import java.util.List; public class Task02Main { @@ -16,8 +18,17 @@ public static void main(String[] args) throws IOException, InterruptedException } public static List listFiles(Path rootDir) throws IOException, InterruptedException { - // your implementation here - return null; + List result = new ArrayList<>(); + + Files.walkFileTree(rootDir, new SimpleFileVisitor() { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { + result.add(file); + return FileVisitResult.CONTINUE; + } + }); + + return result; } } diff --git a/task03/src/com/example/task03/SampleData.java b/task03/src/com/example/task03/SampleData.java index 0654af5..5b1778c 100644 --- a/task03/src/com/example/task03/SampleData.java +++ b/task03/src/com/example/task03/SampleData.java @@ -1,10 +1,11 @@ package com.example.task03; +import java.io.Serializable; import java.util.Date; import java.util.Objects; -public class SampleData { - static final long serialVersionUID = 132706691457162967L; +public class SampleData implements Serializable { + private static final long serialVersionUID = 132706691457162967L; String name; int value; diff --git a/task03/src/com/example/task03/Task03Main.java b/task03/src/com/example/task03/Task03Main.java index 740fff1..c56f2b8 100644 --- a/task03/src/com/example/task03/Task03Main.java +++ b/task03/src/com/example/task03/Task03Main.java @@ -2,6 +2,7 @@ import java.io.IOException; import java.io.InputStream; +import java.io.ObjectInputStream; public class Task03Main { public static void main(String[] args) throws IOException, ClassNotFoundException { @@ -15,7 +16,13 @@ public static void main(String[] args) throws IOException, ClassNotFoundExceptio } public static SampleData deserialize(InputStream inputStream) throws IOException, ClassNotFoundException { - // your implementation here - return null; + + SampleData deserializedData; + + try (ObjectInputStream objectInputStream = new ObjectInputStream(inputStream)) { + deserializedData = (SampleData) objectInputStream.readObject(); + } + + return deserializedData; } }