diff options
Diffstat (limited to 'security-utils/src/main/java/com/yahoo/vespa/jdk8compat/Files.java')
-rw-r--r-- | security-utils/src/main/java/com/yahoo/vespa/jdk8compat/Files.java | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/security-utils/src/main/java/com/yahoo/vespa/jdk8compat/Files.java b/security-utils/src/main/java/com/yahoo/vespa/jdk8compat/Files.java new file mode 100644 index 00000000000..cc3bd698cd5 --- /dev/null +++ b/security-utils/src/main/java/com/yahoo/vespa/jdk8compat/Files.java @@ -0,0 +1,24 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.jdk8compat; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.OpenOption; +import java.nio.file.Path; + +/** + * Backport of new {@link java.nio.file.Files} methods added after JDK8 + * + * @author bjorncs + */ +public interface Files { + + static String readString(Path path) throws IOException { + byte[] bytes = java.nio.file.Files.readAllBytes(path); + return new String(bytes, StandardCharsets.UTF_8); + } + + static Path writeString(Path path, CharSequence string, OpenOption... options) throws IOException { + return java.nio.file.Files.write(path, string.toString().getBytes(), options); + } +} |