aboutsummaryrefslogtreecommitdiffstats
path: root/config/src/main/java/com/yahoo/config/subscription/FileSource.java
blob: 9d3c6041f4be41c8441d291feb56738d47e957c2 (plain) (blame)
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
33
34
35
36
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config.subscription;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.List;

/**
 * Source specifying config from one local file
 *
 * @author Vegard Havdal
 * @author jonmv
 */
public class FileSource implements ConfigSource {

    private final File file;

    public FileSource(File file) {
        this.file = file;
        validateFile();
    }

    public long getLastModified() {
        return file.lastModified();
    }

    public List<String> getContent() throws IOException {
        return Files.readAllLines(file.toPath());
    }

    public void validateFile() {
        if ( ! file.isFile()) throw new IllegalArgumentException("Not a file: " + file);
    }

}