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
70 changes: 62 additions & 8 deletions task01/src/com/example/task01/Task01Main.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,74 @@
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";
// Создаем команду для выполнения в командной строке
List<String> command = new ArrayList<>();
command.add("ffprobe");
command.add("-v");
command.add("error");
command.add("-of");
command.add("flat");
command.add("-show_format");
command.add(file.getAbsolutePath());

// Создаем ProcessBuilder для запуска внешнего процесса
ProcessBuilder processBuilder = new ProcessBuilder(command);

// Запускаем процесс и ждем его завершения
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")) {
// Извлекаем значение из строки
return extractValueFromLine(line);
}
}
}

// Дожидаемся завершения процесса
int exitCode = process.waitFor();
if (exitCode != 0) {
throw new IOException("FFprobe завершился с ошибкой, код: " + exitCode);
}

return null; // Если название не найдено
}

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 автоматически закроет поток
}
}
}