You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ch...@apache.org on 2018/11/22 11:56:13 UTC
ignite git commit: IGNITE-10370: Add try-with-resources to close
streams in DirectorySerializer.
Repository: ignite
Updated Branches:
refs/heads/master 547704808 -> 44d6c5f87
IGNITE-10370: Add try-with-resources to close streams in
DirectorySerializer.
this closes #5461
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/44d6c5f8
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/44d6c5f8
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/44d6c5f8
Branch: refs/heads/master
Commit: 44d6c5f87fd25b0eb038513521a48bebb43cf384
Parents: 5477048
Author: Anton Dmitriev <dm...@gmail.com>
Authored: Thu Nov 22 14:56:03 2018 +0300
Committer: Yury Babak <yb...@gridgain.com>
Committed: Thu Nov 22 14:56:03 2018 +0300
----------------------------------------------------------------------
.../ml/inference/util/DirectorySerializer.java | 35 +++++++++++---------
1 file changed, 19 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/44d6c5f8/modules/ml/src/main/java/org/apache/ignite/ml/inference/util/DirectorySerializer.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/inference/util/DirectorySerializer.java b/modules/ml/src/main/java/org/apache/ignite/ml/inference/util/DirectorySerializer.java
index 6695718..d7fad5f 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/inference/util/DirectorySerializer.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/inference/util/DirectorySerializer.java
@@ -49,12 +49,13 @@ public class DirectorySerializer {
Map<String, byte[]> data = new HashMap<>();
serialize(data, path, file);
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(data);
- oos.flush();
+ try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos)) {
+ oos.writeObject(data);
+ oos.flush();
- return baos.toByteArray();
+ return baos.toByteArray();
+ }
}
/**
@@ -67,18 +68,20 @@ public class DirectorySerializer {
*/
@SuppressWarnings("unchecked")
public static void deserialize(Path path, byte[] data) throws IOException, ClassNotFoundException {
- ByteArrayInputStream bais = new ByteArrayInputStream(data);
- ObjectInputStream ois = new ObjectInputStream(bais);
- Map<String, byte[]> files = (Map<String, byte[]>)ois.readObject();
+ try (ByteArrayInputStream bais = new ByteArrayInputStream(data);
+ ObjectInputStream ois = new ObjectInputStream(bais)) {
+ Map<String, byte[]> files = (Map<String, byte[]>)ois.readObject();
- for (Map.Entry<String, byte[]> file : files.entrySet()) {
- Path dst = path.resolve(file.getKey());
- File dstFile = dst.toFile();
- Files.createDirectories(dstFile.getParentFile().toPath());
- Files.createFile(dstFile.toPath());
- FileOutputStream fos = new FileOutputStream(dstFile);
- fos.write(file.getValue());
- fos.flush();
+ for (Map.Entry<String, byte[]> file : files.entrySet()) {
+ Path dst = path.resolve(file.getKey());
+ File dstFile = dst.toFile();
+ Files.createDirectories(dstFile.getParentFile().toPath());
+ Files.createFile(dstFile.toPath());
+ try (FileOutputStream fos = new FileOutputStream(dstFile)) {
+ fos.write(file.getValue());
+ fos.flush();
+ }
+ }
}
}