Line | |
---|
1 | package geniusweb.profileconnection;
|
---|
2 |
|
---|
3 | import java.io.File;
|
---|
4 | import java.io.IOException;
|
---|
5 | import java.nio.charset.StandardCharsets;
|
---|
6 | import java.nio.file.Files;
|
---|
7 | import java.nio.file.Path;
|
---|
8 |
|
---|
9 | import com.fasterxml.jackson.databind.ObjectMapper;
|
---|
10 |
|
---|
11 | import geniusweb.profile.Profile;
|
---|
12 | import tudelft.utilities.listener.DefaultListenable;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * ProfileInterface based on a plain filesystem UTF8 file.
|
---|
16 | */
|
---|
17 | public class FileProfileConnector extends DefaultListenable<Profile>
|
---|
18 | implements ProfileInterface {
|
---|
19 | private final static ObjectMapper jackson = new ObjectMapper();
|
---|
20 | private final Profile profile;
|
---|
21 |
|
---|
22 | /**
|
---|
23 | *
|
---|
24 | * @param filename the filename of the file containing the profile
|
---|
25 | * @throws IOException if the profile is not proper json
|
---|
26 | */
|
---|
27 | public FileProfileConnector(String filename) throws IOException {
|
---|
28 | Path path = new File(filename).toPath();
|
---|
29 | String serialized = new String(Files.readAllBytes(path),
|
---|
30 | StandardCharsets.UTF_8);
|
---|
31 | profile = jackson.readValue(serialized, Profile.class);
|
---|
32 | }
|
---|
33 |
|
---|
34 | @Override
|
---|
35 | public Profile getProfile() {
|
---|
36 | return profile;
|
---|
37 | }
|
---|
38 |
|
---|
39 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.