diff --git a/task01/src/com/example/task01/Task01Main.java b/task01/src/com/example/task01/Task01Main.java index 5dfc11b..d6e0fe4 100644 --- a/task01/src/com/example/task01/Task01Main.java +++ b/task01/src/com/example/task01/Task01Main.java @@ -1,20 +1,50 @@ 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"; + ProcessBuilder pb = new ProcessBuilder(); + pb.command("C:\\Users\\User\\Downloads\\ffmpeg-8.0.1-essentials_build\\bin\\ffprobe.exe", + "-v", "error", + "-of" ,"flat", + "-show_format", + file.getAbsolutePath()); + pb.directory(new File("E:\\kek\\8-java-io2")); + Process process = pb.start(); + String soundName = null; + try{ BufferedReader bfreader = new BufferedReader( + new InputStreamReader(process.getInputStream())); + + String line; + + while ((line = bfreader.readLine()) != null){ + if (line.startsWith("format.tags.title=")) { + soundName = line.substring("format.tags.title=".length()); + if(soundName.startsWith("\"") && soundName.endsWith("\"")){ + soundName = soundName.substring(1, soundName.length()-1); + } + break; + } + } + } catch (IOException e) { + throw new RuntimeException(e); + } + int exValue = process.waitFor(); + if(exValue != 0){ + throw new RuntimeException("ffprobe завершился с ошибкой: " + exValue); + } + return soundName != null ? soundName : "Unknown"; } } diff --git a/task02/src/com/example/task02/Task02Main.java b/task02/src/com/example/task02/Task02Main.java index 750f7ba..2569fd3 100644 --- a/task02/src/com/example/task02/Task02Main.java +++ b/task02/src/com/example/task02/Task02Main.java @@ -1,7 +1,10 @@ package com.example.task02; +import java.io.File; 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 { @@ -9,15 +12,27 @@ 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) { + List result = new ArrayList<>(); + collectFiles(new File(rootDir.toString()), result); + return result; + } - public static List listFiles(Path rootDir) throws IOException, InterruptedException { - // your implementation here - - return null; + private static void collectFiles(File dir, List result) { + if (dir.isDirectory()) { + File[] files = dir.listFiles(); // может вернуть null + if (files != null) { + for (File file : files) { + if (file.isFile()) { + result.add(file.toPath()); + } else if (file.isDirectory()) { + collectFiles(file, result); + } + } + } + } } } diff --git a/task03/src/com/example/task03/SampleData.java b/task03/src/com/example/task03/SampleData.java index 0654af5..70bbc0b 100644 --- a/task03/src/com/example/task03/SampleData.java +++ b/task03/src/com/example/task03/SampleData.java @@ -1,9 +1,10 @@ package com.example.task03; +import java.io.Serializable; import java.util.Date; import java.util.Objects; -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..7ea7cf8 100644 --- a/task03/src/com/example/task03/Task03Main.java +++ b/task03/src/com/example/task03/Task03Main.java @@ -1,21 +1,24 @@ package com.example.task03; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; 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 obj = new ObjectInputStream(inputStream); + Object read = obj.readObject(); + return (SampleData) read; + } catch (IOException e) { + throw new RuntimeException(e); + } } }