Skip to content

Commit 126be64

Browse files
author
Tanechka
committed
Lesson08 HW08
1 parent c4011b8 commit 126be64

2 files changed

Lines changed: 85 additions & 0 deletions

File tree

‎src/ru/javawebinar/basejava/exception/StorageException.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ public StorageException(String message, String uuid) {
88
this.uuid = uuid;
99
}
1010

11+
public StorageException(String message, String uuid, Exception e) {
12+
super(message, e);
13+
this.uuid = uuid;
14+
}
15+
1116
public String getUuid() {
1217
return uuid;
1318
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package ru.javawebinar.basejava.storage;
2+
3+
import ru.javawebinar.basejava.exception.StorageException;
4+
import ru.javawebinar.basejava.model.Resume;
5+
6+
import java.io.File;
7+
import java.io.IOException;
8+
import java.util.List;
9+
import java.util.Objects;
10+
11+
/**
12+
* gkislin
13+
* 22.07.2016
14+
*/
15+
public abstract class AbstractFileStorage extends AbstractStorage<File> {
16+
private File directory;
17+
18+
protected AbstractFileStorage(File directory) {
19+
Objects.requireNonNull(directory, "directory must not be null");
20+
if (!directory.isDirectory()) {
21+
throw new IllegalArgumentException(directory.getAbsolutePath() + " is not directory");
22+
}
23+
if (!directory.canRead() || !directory.canWrite()) {
24+
throw new IllegalArgumentException(directory.getAbsolutePath() + " is not readable/writable");
25+
}
26+
this.directory = directory;
27+
}
28+
29+
@Override
30+
public void clear() {
31+
32+
}
33+
34+
@Override
35+
public int size() {
36+
return 0;
37+
}
38+
39+
@Override
40+
protected File getSearchKey(String uuid) {
41+
return new File(directory, uuid);
42+
}
43+
44+
@Override
45+
protected void doUpdate(Resume r, File file) {
46+
47+
}
48+
49+
@Override
50+
protected boolean isExist(File file) {
51+
return file.exists();
52+
}
53+
54+
@Override
55+
protected void doSave(Resume r, File file) {
56+
try {
57+
file.createNewFile();
58+
doWrite(r, file);
59+
} catch (IOException e) {
60+
throw new StorageException("IO error", file.getName(), e);
61+
}
62+
}
63+
64+
protected abstract void doWrite(Resume r, File file) throws IOException;
65+
66+
@Override
67+
protected Resume doGet(File file) {
68+
return null;
69+
}
70+
71+
@Override
72+
protected void doDelete(File file) {
73+
74+
}
75+
76+
@Override
77+
protected List<Resume> doCopyAll() {
78+
return null;
79+
}
80+
}

0 commit comments

Comments
 (0)