Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 64 additions & 8 deletions task01/src/com/example/task01/Task01Main.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,76 @@
package com.example.task01;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

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";
// Проверка, что файл существует
if (!file.exists()) {
throw new IOException("File does not exist: " + file.getAbsolutePath());
}

// Определяем путь к ffprobe в зависимости от ОС
String ffprobePath;
String os = System.getProperty("os.name").toLowerCase();

ffprobePath = "C:\\ffmpeg-2025-12-07-git-c4d22f2d2c-full_build\\bin\\ffprobe.exe";

// Создаем команду для запуска ffprobe
ProcessBuilder processBuilder = new ProcessBuilder(
ffprobePath,
"-v", "error", // Только ошибки
"-of", "flat", // Формат вывода
"-show_format", // Показать информацию о формате
file.getAbsolutePath() // Путь к mp3-файлу
);

// Запускаем процесс
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=")) {
// Извлекаем значение
String title = line.substring("format.tags.title=".length());
// Убираем кавычки
title = title.replaceAll("^\"|\"$", "");
process.waitFor();
return title;
}
}
process.waitFor();
}
return "Unknown";
}

private static String extractValueFromLine(String line) {
// Находим позицию знака равенства
int equalsIndex = line.indexOf('=');
if (equalsIndex == -1) {
return null;
}

// Берем часть строки после знака равенства
String valuePart = line.substring(equalsIndex + 1).trim();

// Убираем кавычки если они есть
if (valuePart.startsWith("\"") && valuePart.endsWith("\"")) {
valuePart = valuePart.substring(1, valuePart.length() - 1);
}

return valuePart;
}
}
}
34 changes: 26 additions & 8 deletions task02/src/com/example/task02/Task02Main.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,41 @@
package com.example.task02;

import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.*;
import java.util.ArrayList;
import java.util.List;

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<Path> listFiles(Path rootDir) throws IOException, InterruptedException {
// your implementation here
List<Path> fileList = new ArrayList<>();
traverseDirectory(rootDir, fileList);
return fileList;
}

return null;
private static void traverseDirectory(Path directory, List<Path> fileList) throws IOException {
// Используем DirectoryStream для обхода содержимого каталога
// Это эффективнее чем File.listFiles() и работает с символическими ссылками
try (DirectoryStream<Path> stream = Files.newDirectoryStream(directory)) {
for (Path entry : stream) {
if (Files.isDirectory(entry)) {
// Рекурсивный вызов для подкаталогов
traverseDirectory(entry, fileList);
} else if (Files.isRegularFile(entry)) {
// Добавляем только обычные файлы (не директории и не симлинки)
fileList.add(entry);
}
// Игнорируем символические ссылки и специальные файлы
}
} catch (AccessDeniedException e) {
// Пропускаем директории без прав доступа
System.err.println("Нет доступа к директории: " + directory);
}
}
}
}
5 changes: 3 additions & 2 deletions task03/src/com/example/task03/SampleData.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -39,4 +40,4 @@ public String toString() {
", date=" + date +
'}';
}
}
}
16 changes: 9 additions & 7 deletions task03/src/com/example/task03/Task03Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;

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;
// Создаем ObjectInputStream для десериализации
try (ObjectInputStream ois = new ObjectInputStream(inputStream)) {
// Читаем и возвращаем объект SampleData
return (SampleData) ois.readObject();
}
// try-with-resources автоматически закроет поток
}
}
}