Skip to content
Open

. #379

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
49 changes: 42 additions & 7 deletions task01/src/com/example/task01/Task01Main.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,55 @@
package com.example.task01;

import java.io.File;
import java.io.IOException;
import java.io.*;
import java.util.*;

public class Task01Main {
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("src/main/resources/3724.mp3")));

}
// Адаптируем путь к файлу, чтобы тесты проходили и команда срабатывала
// ProcessBuilder строит по сути "запрос" в терминал, в него указываем наши команды
// Process отправляет эти команды
// Дальше преобразуем, чтобы работать с полученными данными


public static String extractSoundName(File file) throws IOException, InterruptedException {
// your implementation here
return "sound name";
String ffprobePath = "/opt/homebrew/bin/ffprobe";
String absolutePath = "/Users/admin/IdeaProjects/8-java-io2/task01/" + file.toString();
ProcessBuilder process = new ProcessBuilder(ffprobePath, "-v", "error", "-of", "flat", "-show_format", absolutePath);
Process pr = process.start();
List<String> output = new ArrayList<String>();

try (BufferedReader reader = new BufferedReader(new InputStreamReader(pr.getInputStream()))){
String line;
int i = 0;

while ((line = reader.readLine()) != null){
output.add(line);
}
}


pr.waitFor();

StringBuilder name = new StringBuilder();
for (int i = 0; i < output.size(); i++){
if (output.get(i).startsWith("format.tags.title=")){
String temp = output.get(i);

char[] chars = temp.toCharArray();

for (i = 19; i < chars.length - 1; i++){
name.append(chars[i]);
}
}

}
return name.toString();
}
}
40 changes: 35 additions & 5 deletions task02/src/com/example/task02/Task02Main.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,53 @@
package com.example.task02;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Files;
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 {
//здесь вы можете вручную протестировать ваше решение, вызывая реализуемый метод и смотря результат
// например вот так:

/*

System.out.println(listFiles(Paths.get("task02/src/main/resources/")));
*/


}

public static List<Path> listFiles(Path rootDir) throws IOException, InterruptedException {
// your implementation here
// Path adaptedPath = Paths.get("/Users/admin/IdeaProjects/8-java-io2/" + rootDir);
List<Path> result = new ArrayList<Path>();

return null;
}
if (Files.isRegularFile(rootDir)){
result.add(rootDir);
return result;
}

try (Stream<Path> stream = Files.list(rootDir)){
stream.forEach(item ->{
if (Files.isDirectory(item)) {
try {
result.addAll(listFiles(item));
} catch (IOException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
else {
result.add(item);
}
});

}
return result;
}
}

3 changes: 2 additions & 1 deletion 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
15 changes: 10 additions & 5 deletions task03/src/com/example/task03/Task03Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@

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")));
*/

// 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 ois = new ObjectInputStream(inputStream)){
SampleData deserialized = (SampleData) ois.readObject();
return (SampleData) deserialized;
} catch (IOException | ClassNotFoundException e){
return null;
}
}
}