summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorValerij Fredriksen <valerijf@yahooinc.com>2021-10-15 13:59:01 +0200
committerValerij Fredriksen <valerijf@yahooinc.com>2021-10-15 13:59:01 +0200
commit74d1824b79412e20640d176df846d04ce7a44a63 (patch)
tree2e30770a15bae80eb08b3e99e2ab9f9974fc4c40
parent5f8e1a37f9b0cbf04eb9a008aac17bf1d80cbf45 (diff)
Read/write SignedIdentityDocument without going via File
-rw-r--r--vespa-athenz/src/main/java/com/yahoo/vespa/athenz/identityprovider/api/EntityBindingsMapper.java13
1 files changed, 8 insertions, 5 deletions
diff --git a/vespa-athenz/src/main/java/com/yahoo/vespa/athenz/identityprovider/api/EntityBindingsMapper.java b/vespa-athenz/src/main/java/com/yahoo/vespa/athenz/identityprovider/api/EntityBindingsMapper.java
index acc558405dd..08afdd91542 100644
--- a/vespa-athenz/src/main/java/com/yahoo/vespa/athenz/identityprovider/api/EntityBindingsMapper.java
+++ b/vespa-athenz/src/main/java/com/yahoo/vespa/athenz/identityprovider/api/EntityBindingsMapper.java
@@ -8,10 +8,11 @@ import com.yahoo.vespa.athenz.api.AthenzService;
import com.yahoo.vespa.athenz.identityprovider.api.bindings.SignedIdentityDocumentEntity;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
-import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import static com.yahoo.vespa.athenz.identityprovider.api.VespaUniqueInstanceId.fromDottedString;
@@ -64,8 +65,8 @@ public class EntityBindingsMapper {
}
public static SignedIdentityDocument readSignedIdentityDocumentFromFile(Path file) {
- try {
- SignedIdentityDocumentEntity entity = mapper.readValue(file.toFile(), SignedIdentityDocumentEntity.class);
+ try (InputStream inputStream = Files.newInputStream(file)) {
+ SignedIdentityDocumentEntity entity = mapper.readValue(inputStream, SignedIdentityDocumentEntity.class);
return EntityBindingsMapper.toSignedIdentityDocument(entity);
} catch (IOException e) {
throw new UncheckedIOException(e);
@@ -75,8 +76,10 @@ public class EntityBindingsMapper {
public static void writeSignedIdentityDocumentToFile(Path file, SignedIdentityDocument document) {
try {
SignedIdentityDocumentEntity entity = EntityBindingsMapper.toSignedIdentityDocumentEntity(document);
- Path tempFile = Paths.get(file.toAbsolutePath().toString() + ".tmp");
- mapper.writeValue(tempFile.toFile(), entity);
+ Path tempFile = file.resolveSibling(file.getFileName() + ".tmp");
+ try (OutputStream outputStream = Files.newOutputStream(tempFile)) {
+ mapper.writeValue(outputStream, entity);
+ }
Files.move(tempFile, file, StandardCopyOption.ATOMIC_MOVE);
} catch (IOException e) {
throw new UncheckedIOException(e);