Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private final ResourceConfiguration configuration;
- private static final List<Folder> folders = new ArrayList<Folder>();
- public FolderRepositoryImpl(ResourceConfiguration configuration) {
- this.configuration = configuration;
- }
- /**
- * Jeżeli starczy czasu to będzie można ładnie rozłożyć te rzeczy z RepositoryImpl.
- */
- @PostConstruct
- private void init() {
- ObjectMapper objectMapper = new ObjectMapper();
- File inputFile = new File(configuration.getFileName());
- try (FileInputStream fis = new FileInputStream(inputFile)) {
- int iByteCount = fis.read();
- //populate the folders list only if the input file is not empty
- if (iByteCount != -1) {
- JsonNode jsonNode = objectMapper.readValue(inputFile, JsonNode.class);
- Iterator<Map.Entry<String, JsonNode>> iterator = jsonNode.fields();
- while (iterator.hasNext()) {
- Map.Entry<String, JsonNode> currentIterator = iterator.next();
- String key = currentIterator.getKey();
- Folder folder = objectMapper.readValue(currentIterator.getValue().toString(), Folder.class);
- folder.setPath(key);
- folders.add(folder);
- }
- }
- } catch (IOException e) {
- System.out.println("Cannot read Folder Data file.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement