@@ -13,38 +13,38 @@ public abstract class AbstractFileStorage extends AbstractStorage{
1313private File directory ;
1414
1515protected AbstractFileStorage (File directory ){
16- Objects .requireNonNull (directory ,"directory must not null" );
17- if (directory .isDirectory ()){
18- throw new IllegalArgumentException (directory .getAbsolutePath () + " is not directory" );
16+ Objects .requireNonNull (directory ,"directory must not null" );
17+ if (directory .isDirectory ()) {
18+ throw new IllegalArgumentException (directory .getAbsolutePath () + " is not directory" );
1919 }
20- if (directory .canRead ()|| directory .canWrite ()){
21- throw new IllegalArgumentException (directory .getAbsolutePath () + " is not readable/writable" );
20+ if (directory .canRead () || directory .canWrite ()) {
21+ throw new IllegalArgumentException (directory .getAbsolutePath () + " is not readable/writable" );
2222 }
23- this .directory = directory ;
23+ this .directory = directory ;
2424 }
2525
2626@ Override
2727protected void doUpdate (Resume resume , Object searchKey ){
2828//как doSave только в существующий
29- File f = (File )searchKey ;
29+ File f = (File )searchKey ;
3030try {
31- doWrite (resume ,f );
31+ doWrite (resume ,f );
3232 } catch (IOException e ){
3333throw new StorageException ("IO error" , f .getName (), e );
3434 }
3535 }
3636
3737@ Override
3838protected boolean isExist (Object file ){
39- return ((File )file ).exists ();
39+ return ( (File )file ).exists ();
4040 }
4141
4242@ Override
4343protected void doSave (Resume resume , Object file ){
44- File f =((File )file );
44+ File f = ((File )file );
4545try {
4646f .createNewFile ();
47- doWrite (resume ,f );
47+ doWrite (resume ,f );
4848 } catch (IOException e ){
4949throw new StorageException ("IO error" , f .getName (), e );
5050 }
@@ -54,35 +54,31 @@ protected void doSave(Resume resume, Object file){
5454
5555@ Override
5656protected Resume doGet (Object searchKey ){
57- //абстрактный останется
58-
59-
60- return null ;
57+ return doRead ((File )searchKey );
6158 }
6259
6360@ Override
6461protected void doDelete (Object searchKey ){
65- File f = (File )searchKey ;
62+ File f = (File )searchKey ;
6663f .delete ();
6764//удаляет файл
6865 }
6966
7067@ Override
7168protected Object getSearchKey (String uuid ){
72- return new File (directory ,uuid );
69+ return new File (directory ,uuid );
7370 }
7471
7572@ Override
7673protected List <Resume > doCopyAll (){
7774//читает все файлы и делает do Read и возвращает list
78- List <Resume > resumes = new ArrayList <>();
79- try {
80- for (File f : directory .listFiles ()){
81- resumes .add (doRead (f ));
82- }
75+ File [] arrFiles = directory .listFiles ();
76+ if (arrFiles == null ){
77+ throw new StorageException ("Resume files not founded in directory " + directory .getAbsolutePath () , "" );
8378 }
84- catch (NullPointerException e ){
85- throw new StorageException ("FileStorage got empty list of files" ,"" ,e );
79+ List <Resume > resumes = new ArrayList <>();
80+ for (File f : arrFiles ){
81+ resumes .add (doRead (f ));
8682 }
8783return resumes ;
8884 }
@@ -92,7 +88,7 @@ protected List<Resume> doCopyAll(){
9288@ Override
9389public void clear (){
9490//получить все файлыиз каталога и удалить
95- for (File f :
91+ for (File f :
9692directory .listFiles ()){
9793f .delete ();
9894 }
0 commit comments