diff --git a/task01/src/com/example/task01/Task01Main.java b/task01/src/com/example/task01/Task01Main.java index 5dfc11b0..2690e944 100644 --- a/task01/src/com/example/task01/Task01Main.java +++ b/task01/src/com/example/task01/Task01Main.java @@ -1,7 +1,8 @@ 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 { @@ -11,10 +12,30 @@ public static void main(String[] args) throws IOException, InterruptedException /* System.out.println(extractSoundName(new File("task01/src/main/resources/3727.mp3"))); */ + System.out.println(extractSoundName(new File("C:\\Users\\Олег\\8-java-io2\\task01\\src\\main\\resources\\3727.mp3"))); } public static String extractSoundName(File file) throws IOException, InterruptedException { - // your implementation here - return "sound name"; + String ffprobe = "C:\\Users\\Олег\\Downloads\\ffmpeg-master-latest-win64-gpl\\ffmpeg-master-latest-win64-gpl\\bin\\ffprobe.exe"; + + ProcessBuilder processBuilder = new ProcessBuilder(); + processBuilder.command(ffprobe, "-v", "error", "-of", "flat", "-show_format", file.getAbsolutePath()) + .redirectErrorStream(true); + + Process process = processBuilder.start(); + String line; + String title; + try(BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))){ + line = reader.readLine(); + while(line != null) { + if (line.contains("title")) { + title = line.split("=")[1].replace("\"", ""); + return title; + } + line = reader.readLine(); + } + } + + return null; } } diff --git a/task02/src/com/example/task02/Task02Main.java b/task02/src/com/example/task02/Task02Main.java index 750f7bab..40f8db1b 100644 --- a/task02/src/com/example/task02/Task02Main.java +++ b/task02/src/com/example/task02/Task02Main.java @@ -1,8 +1,13 @@ package com.example.task02; - +import java.io.File; import java.io.IOException; import java.nio.file.Path; import java.util.List; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.stream.Stream; public class Task02Main { public static void main(String[] args) throws IOException, InterruptedException { @@ -13,11 +18,17 @@ 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 fileList = new ArrayList<>(); + + try (Stream paths = Files.walk(rootDir)) { + paths.filter(Files::isRegularFile) + .forEach(fileList::add); + } - return null; + return fileList; } } diff --git a/task03/src/com/example/task03/SampleData.java b/task03/src/com/example/task03/SampleData.java index 0654af50..90b801fc 100644 --- a/task03/src/com/example/task03/SampleData.java +++ b/task03/src/com/example/task03/SampleData.java @@ -1,9 +1,9 @@ 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 740fff14..98e38c54 100644 --- a/task03/src/com/example/task03/Task03Main.java +++ b/task03/src/com/example/task03/Task03Main.java @@ -1,8 +1,8 @@ package com.example.task03; - +import java.io.FileInputStream; 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 +15,8 @@ public static void main(String[] args) throws IOException, ClassNotFoundExceptio } public static SampleData deserialize(InputStream inputStream) throws IOException, ClassNotFoundException { - // your implementation here - return null; + try(ObjectInputStream ois = new ObjectInputStream(inputStream)){ + return (SampleData) ois.readObject(); + } } }