33import ru .javawebinar .basejava .exception .StorageException ;
44import ru .javawebinar .basejava .model .Resume ;
55
6- import java .io .File ;
7- import java .io .IOException ;
6+ import java .io .*;
87import java .util .ArrayList ;
98import java .util .List ;
109import java .util .Objects ;
1615public abstract class AbstractFileStorage extends AbstractStorage <File > {
1716 private File directory ;
1817
18+ protected abstract void doWrite (Resume r , OutputStream os ) throws IOException ;
19+
20+ protected abstract Resume doRead (InputStream is ) throws IOException ;
21+
1922 protected AbstractFileStorage (File directory ) {
2023 Objects .requireNonNull (directory , "directory must not be null" );
2124 if (!directory .isDirectory ()) {
@@ -54,7 +57,7 @@ protected File getSearchKey(String uuid) {
5457 @ Override
5558 protected void doUpdate (Resume r , File file ) {
5659 try {
57- doWrite (r , file );
60+ doWrite (r , new BufferedOutputStream ( new FileOutputStream ( file )) );
5861 } catch (IOException e ) {
5962 throw new StorageException ("File write error" , r .getUuid (), e );
6063 }
@@ -75,14 +78,10 @@ protected void doSave(Resume r, File file) {
7578 doUpdate (r , file );
7679 }
7780
78- protected abstract void doWrite (Resume r , File file ) throws IOException ;
79-
80- protected abstract Resume doRead (File file ) throws IOException ;
81-
8281 @ Override
8382 protected Resume doGet (File file ) {
8483 try {
85- return doRead (file );
84+ return doRead (new BufferedInputStream ( new FileInputStream ( file )) );
8685 } catch (IOException e ) {
8786 throw new StorageException ("File read error" , file .getName (), e );
8887 }
@@ -107,4 +106,4 @@ protected List<Resume> doCopyAll() {
107106 }
108107 return list ;
109108 }
110- }
109+ }
0 commit comments