Skip to content

Commit 6f699cb

Browse files
author
Tanechka
committed
Lesson10 DataStream
1 parent ba409e3 commit 6f699cb

4 files changed

Lines changed: 64 additions & 1 deletion

File tree

src/ru/javawebinar/basejava/model/Resume.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ public String getUuid() {
4040
return uuid;
4141
}
4242

43+
public String getFullName() {
44+
return fullName;
45+
}
46+
47+
public Map<ContactType, String> getContacts() {
48+
return contacts;
49+
}
50+
51+
public Map<SectionType, Section> getSections() {
52+
return sections;
53+
}
54+
4355
public String getContact(ContactType type) {
4456
return contacts.get(type);
4557
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package ru.javawebinar.basejava.storage.serializer;
2+
3+
import ru.javawebinar.basejava.model.ContactType;
4+
import ru.javawebinar.basejava.model.Resume;
5+
6+
import java.io.*;
7+
import java.util.Map;
8+
9+
public class DataStreamSerializer implements StreamSerializer {
10+
11+
@Override
12+
public void doWrite(Resume r, OutputStream os) throws IOException {
13+
try (DataOutputStream dos = new DataOutputStream(os)) {
14+
dos.writeUTF(r.getUuid());
15+
dos.writeUTF(r.getFullName());
16+
Map<ContactType, String> contacts = r.getContacts();
17+
dos.writeInt(contacts.size());
18+
for (Map.Entry<ContactType, String> entry : contacts.entrySet()) {
19+
dos.writeUTF(entry.getKey().name());
20+
dos.writeUTF(entry.getValue());
21+
}
22+
// TODO implements sections
23+
}
24+
}
25+
26+
@Override
27+
public Resume doRead(InputStream is) throws IOException {
28+
try (DataInputStream dis = new DataInputStream(is)) {
29+
String uuid = dis.readUTF();
30+
String fullName = dis.readUTF();
31+
Resume resume = new Resume(uuid, fullName);
32+
int size = dis.readInt();
33+
for (int i = 0; i < size; i++) {
34+
resume.addContact(ContactType.valueOf(dis.readUTF()), dis.readUTF());
35+
}
36+
// TODO implements sections
37+
return resume;
38+
}
39+
}
40+
}

test/ru/javawebinar/basejava/storage/AllStorageTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
ObjectFileStorageTest.class,
1515
ObjectPathStorageTest.class,
1616
XmlPathStorageTest.class,
17-
JsonPathStorageTest.class
17+
JsonPathStorageTest.class,
18+
DataPathStorageTest.class
1819
})
1920
public class AllStorageTest {
2021
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package ru.javawebinar.basejava.storage;
2+
3+
import ru.javawebinar.basejava.storage.serializer.DataStreamSerializer;
4+
5+
public class DataPathStorageTest extends AbstractStorageTest {
6+
7+
public DataPathStorageTest() {
8+
super(new PathStorage(STORAGE_DIR.getAbsolutePath(), new DataStreamSerializer()));
9+
}
10+
}

0 commit comments

Comments
 (0)