refactor: integrate StudentCsvParser into FileDataSource

This commit is contained in:
Ершов Владислав
2026-08-30 22:38:01 +07:00
parent ba59fa12da
commit cb5068465d
@@ -0,0 +1,39 @@
package ru.project.datasource;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Collector;
import ru.project.student.Student;
import ru.project.collection.MyList;
import ru.project.collection.MyLinkedList;
public class FileDataSource implements DataSource{
private final String fileName;
public FileDataSource(String fileName) {
this.fileName = fileName;
}
@Override
public MyList<Student> create() {
MyList<Student> resultList = new MyLinkedList<>();
try {
StudentCsvReader reader = new StudentCsvReader(fileName);
while reader.hasNext() {
result.append(reader.next());
}
}
catch (IllegalArgumentException e){
System.out.println(e.getMessage());
return null;
}
catch (NoSuchElementException e){
System.out.println("No such element");
return null;
}
}
}