source: profileconnection/src/main/java/geniusweb/profileconnection/FileProfileConnector.java@ 52

Last change on this file since 52 was 52, checked in by ruud, 14 months ago

Fixed small issues in domaineditor.

File size: 1.1 KB
Line 
1package geniusweb.profileconnection;
2
3import java.io.File;
4import java.io.IOException;
5import java.nio.charset.StandardCharsets;
6import java.nio.file.Files;
7import java.nio.file.Path;
8
9import com.fasterxml.jackson.databind.ObjectMapper;
10
11import geniusweb.profile.Profile;
12import tudelft.utilities.listener.DefaultListenable;
13
14/**
15 * ProfileInterface based on a plain filesystem UTF8 file.
16 */
17public 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 @Override
40 public void close() {
41 }
42
43}
Note: See TracBrowser for help on using the repository browser.