forked from JavaOPs/basejava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXmlStreamSerializer.java
More file actions
32 lines (25 loc) · 967 Bytes
/
XmlStreamSerializer.java
File metadata and controls
32 lines (25 loc) · 967 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.urise.webapp.storage.serializer;
import com.urise.webapp.model.*;
import com.urise.webapp.util.XmlParser;
import java.io.*;
import java.nio.charset.StandardCharsets;
public class XmlStreamSerializer implements StreamSerializer {
private XmlParser xmlParser;
public XmlStreamSerializer() {
this.xmlParser = new XmlParser(Resume.class, Organization.class, Link.class,
OrganizationSection.class, TextSection.class, ListSection.class,
Organization.Position.class);
}
@Override
public void doWrite(Resume r, OutputStream os) throws IOException {
try (Writer w = new OutputStreamWriter(os, StandardCharsets.UTF_8)) {
xmlParser.marshall(r, w);
}
}
@Override
public Resume doRead(InputStream is) throws IOException {
try (Reader r = new InputStreamReader(is, StandardCharsets.UTF_8)) {
return xmlParser.unmarshall(r);
}
}
}