aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/com/jantuomi/tunkki/utils/Utilities.java
blob: ddbdd5212d6bc28514a8e7098cd1d1afcbebb5dd (plain)
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
37
38
39
40
41
42
package com.jantuomi.tunkki.utils;

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

/**
 * Created by jan on 10.6.2016.
 */
public class Utilities {

    public static final String VERSION_FILE_PATH = "VERSION";

    private Utilities() {}

    public static String getBasePath() {
        Path currentRelativePath = Paths.get("");
        String s = currentRelativePath.toAbsolutePath().toString();
        return s;
    }

    public static String getVersionFromFile() {
        Path path = Paths.get(getBasePath(), VERSION_FILE_PATH);

        List<String> lines = null;
        try {
            lines = Files.readAllLines(path, StandardCharsets.UTF_8);
            StringBuilder builder = new StringBuilder();
            lines.stream().forEach(s -> builder.append(s));
            return builder.toString();
        } catch (IOException e) {
            return "Unknown version";
        }

    }
}