diff --git a/task01/src/com/example/task01/Task01Main.java b/task01/src/com/example/task01/Task01Main.java index 5dfc11b..9cc4741 100644 --- a/task01/src/com/example/task01/Task01Main.java +++ b/task01/src/com/example/task01/Task01Main.java @@ -1,20 +1,46 @@ package com.example.task01; +import java.io.BufferedReader; import java.io.File; import java.io.IOException; +import java.io.InputStreamReader; public class Task01Main { public static void main(String[] args) throws IOException, InterruptedException { - //здесь вы можете вручную протестировать ваше решение, вызывая реализуемый метод и смотря результат - // например вот так: - - /* System.out.println(extractSoundName(new File("task01/src/main/resources/3727.mp3"))); - */ } - public static String extractSoundName(File file) throws IOException, InterruptedException { - // your implementation here - return "sound name"; + public static String extractSoundName(File file) throws IOException { + ProcessBuilder processBuilder = new ProcessBuilder( + "C:\\Users\\user\\Desktop\\ffmpeg\\ffmpeg-8.0.1-full_build\\bin\\ffprobe.exe", + "-v", "error", + "-of", "flat", + "-show_format", + file.getAbsolutePath() + ); + + try { + Process process = processBuilder.start(); + StringBuilder output = new StringBuilder(); + + try (BufferedReader reader = new BufferedReader( + new InputStreamReader(process.getInputStream()))) { + String line; + while ((line = reader.readLine()) != null) { + output.append(line).append("\n"); + if (line.startsWith("format.tags.title=")) { + String title = line.substring(line.indexOf('"') + 1, line.lastIndexOf('"')); + + process.waitFor(); + return title; + } + } + } + + return null; + + } catch (InterruptedException e) { + throw new RuntimeException(e); + } } } diff --git a/task02/src/com/example/task02/Task02Main.java b/task02/src/com/example/task02/Task02Main.java index 750f7ba..70a37a6 100644 --- a/task02/src/com/example/task02/Task02Main.java +++ b/task02/src/com/example/task02/Task02Main.java @@ -1,23 +1,35 @@ package com.example.task02; import java.io.IOException; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; import java.nio.file.Path; +import java.util.ArrayList; import java.util.List; +import java.nio.file.Paths; public class Task02Main { public static void main(String[] args) throws IOException, InterruptedException { - //здесь вы можете вручную протестировать ваше решение, вызывая реализуемый метод и смотря результат - // например вот так: - - /* System.out.println(listFiles(Paths.get("task02/src/main/resources/"))); - */ - } public static List listFiles(Path rootDir) throws IOException, InterruptedException { - // your implementation here + List result = new ArrayList<>(); + + if (!Files.exists(rootDir) || !Files.isDirectory(rootDir)) { + return result; + } + + try (DirectoryStream stream = Files.newDirectoryStream(rootDir)) { + for (Path entry : stream) { + if (Files.isDirectory(entry)) { + result.addAll(listFiles(entry)); + } else if (Files.isRegularFile(entry)) { + result.add(entry); + } + } + } - return null; + return result; } } diff --git a/task03/src/com/example/task03/SampleData.java b/task03/src/com/example/task03/SampleData.java index 0654af5..61bc6b9 100644 --- a/task03/src/com/example/task03/SampleData.java +++ b/task03/src/com/example/task03/SampleData.java @@ -2,8 +2,9 @@ import java.util.Date; import java.util.Objects; +import java.io.Serializable; -public class SampleData { +public class SampleData implements Serializable{ static final long serialVersionUID = 132706691457162967L; String name; diff --git a/task03/src/com/example/task03/Task03Main.java b/task03/src/com/example/task03/Task03Main.java index 740fff1..a814418 100644 --- a/task03/src/com/example/task03/Task03Main.java +++ b/task03/src/com/example/task03/Task03Main.java @@ -2,20 +2,17 @@ import java.io.IOException; import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.FileInputStream; public class Task03Main { public static void main(String[] args) throws IOException, ClassNotFoundException { - //здесь вы можете вручную протестировать ваше решение, вызывая реализуемый метод и смотря результат - // например вот так: - - /* System.out.println(deserialize(new FileInputStream("task03/src/main/resources/example1.bin"))); - */ - } public static SampleData deserialize(InputStream inputStream) throws IOException, ClassNotFoundException { - // your implementation here - return null; + try(ObjectInputStream ois = new ObjectInputStream(inputStream)){ + return (SampleData) ois.readObject(); + } } }