From f3e406123d7f52fcaa4344b63a9f28a5e1191f5d Mon Sep 17 00:00:00 2001 From: Serdyukov Alexander <30432511+SerdyukovAlexander@users.noreply.github.com> Date: Fri, 6 Dec 2024 11:22:09 +0500 Subject: [PATCH] =?UTF-8?q?8=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D1=8C=20?= =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B4=D1=8E=D0=BA=D0=BE=D0=B2=20=D0=9F=D1=80?= =?UTF-8?q?=D0=98-201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task01/src/com/example/task01/Task01Main.java | 39 +++++++++++++------ task02/src/com/example/task02/Task02Main.java | 30 ++++++++------ task03/src/com/example/task03/SampleData.java | 5 ++- task03/src/com/example/task03/Task03Main.java | 21 +++++----- 4 files changed, 59 insertions(+), 36 deletions(-) diff --git a/task01/src/com/example/task01/Task01Main.java b/task01/src/com/example/task01/Task01Main.java index 5dfc11b0..80cfdfd4 100644 --- a/task01/src/com/example/task01/Task01Main.java +++ b/task01/src/com/example/task01/Task01Main.java @@ -1,20 +1,35 @@ package com.example.task01; -import java.io.File; -import java.io.IOException; +import java.io.*; +import java.nio.channels.Pipe; -public class Task01Main { - public static void main(String[] args) throws IOException, InterruptedException { - //здесь вы можете вручную протестировать ваше решение, вызывая реализуемый метод и смотря результат - // например вот так: - - /* +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, InterruptedException + { + ProcessBuilder processBuilder = new ProcessBuilder(); + processBuilder.command("ffprobe", "-v", "error", "-of", "flat", "-show_format", file.getName()); + processBuilder.directory(file.getParentFile()); + + + Process process = processBuilder.start(); + process.waitFor(); + try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) { + while (reader.ready()) { + String line = reader.readLine(); + if (line.contains("format.tags.title")) { + line = line.split("=")[1].replace("\"", ""); + return line; + } + System.out.println(line); + } + + } + return "Not found"; } } diff --git a/task02/src/com/example/task02/Task02Main.java b/task02/src/com/example/task02/Task02Main.java index 750f7bab..08491f0a 100644 --- a/task02/src/com/example/task02/Task02Main.java +++ b/task02/src/com/example/task02/Task02Main.java @@ -1,23 +1,31 @@ package com.example.task02; +import java.nio.file.Files; import java.io.IOException; import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; import java.util.List; +import java.util.stream.Stream; -public class Task02Main { - public static void main(String[] args) throws IOException, InterruptedException { - //здесь вы можете вручную протестировать ваше решение, вызывая реализуемый метод и смотря результат - // например вот так: - - /* +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 + public static List listFiles(Path rootDir) throws IOException, InterruptedException + { + List output = new ArrayList<>(); - return null; + try(Stream stream = Files.walk(rootDir)) + { + stream.forEach(p -> { + if (!p.toFile().isDirectory()) + output.add(p); + }); + } + return output; } } diff --git a/task03/src/com/example/task03/SampleData.java b/task03/src/com/example/task03/SampleData.java index 0654af50..5b1778c9 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 740fff14..21b75f24 100644 --- a/task03/src/com/example/task03/Task03Main.java +++ b/task03/src/com/example/task03/Task03Main.java @@ -2,20 +2,19 @@ import java.io.IOException; import java.io.InputStream; +import java.io.*; -public class Task03Main { - public static void main(String[] args) throws IOException, ClassNotFoundException { - //здесь вы можете вручную протестировать ваше решение, вызывая реализуемый метод и смотря результат - // например вот так: - - /* +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; + public static SampleData deserialize(InputStream inputStream) throws IOException, ClassNotFoundException + { + ObjectInputStream stream = new ObjectInputStream(inputStream); + SampleData output = (SampleData)stream.readObject(); + return output; } }