diff options
author | HÃ¥kon Hallingstad <hakon@verizonmedia.com> | 2021-10-15 14:53:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-15 14:53:53 +0200 |
commit | 3ae00246aefba327066bc1d34c397cb44fa8d4c6 (patch) | |
tree | 815d28104968e81161bc07dd384965917905ae08 | |
parent | c0302620c7121377a0734b6565734fffb4ec9bd6 (diff) | |
parent | 74d1824b79412e20640d176df846d04ce7a44a63 (diff) |
Merge pull request #19584 from vespa-engine/freva/write-nio
Read/write SignedIdentityDocument without going via File
-rw-r--r-- | vespa-athenz/src/main/java/com/yahoo/vespa/athenz/identityprovider/api/EntityBindingsMapper.java | 13 |
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); |