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
36 changes: 33 additions & 3 deletions task01/src/com/example/task01/Task01Main.java
Original file line number Diff line number Diff line change
@@ -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";
}
}
29 changes: 22 additions & 7 deletions task02/src/com/example/task02/Task02Main.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
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 {
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) {
List<Path> result = new ArrayList<>();
collectFiles(new File(rootDir.toString()), result);
return result;
}

public static List<Path> listFiles(Path rootDir) throws IOException, InterruptedException {
// your implementation here

return null;
private static void collectFiles(File dir, List<Path> 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);
}
}
}
}
}
}
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
13 changes: 8 additions & 5 deletions task03/src/com/example/task03/Task03Main.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
}