IGNITE-2206: IgfsPaths simplification.

Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/23df4bbc
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/23df4bbc
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/23df4bbc

Branch: refs/heads/ignite-2206
Commit: 23df4bbc150e965413e3308b0398cb29208ea929
Parents: 32ffef6
Author: vozerov-gridgain <voze...@gridgain.com>
Authored: Wed Dec 23 17:00:07 2015 +0300
Committer: vozerov-gridgain <voze...@gridgain.com>
Committed: Wed Dec 23 17:00:07 2015 +0300

----------------------------------------------------------------------
 .../internal/processors/igfs/IgfsPaths.java     | 63 ++++++--------------
 1 file changed, 18 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/23df4bbc/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsPaths.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsPaths.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsPaths.java
index 986f59f..cd34655 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsPaths.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsPaths.java
@@ -92,7 +92,13 @@ public class IgfsPaths implements Externalizable {
 
     /** {@inheritDoc} */
     @Override public void writeExternal(ObjectOutput out) throws IOException {
-        writePayload(out);
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+        try (ObjectOutput oo = new ObjectOutputStream(baos)) {
+            oo.writeObject(payload);
+        }
+
+        U.writeByteArray(out, baos.toByteArray());
 
         U.writeEnum(out, dfltMode);
 
@@ -101,7 +107,10 @@ public class IgfsPaths implements Externalizable {
             out.writeInt(pathModes.size());
 
             for (T2<IgfsPath, IgfsMode> pathMode : pathModes) {
+                assert pathMode.getKey() != null;
+
                 pathMode.getKey().writeExternal(out);
+
                 U.writeEnum(out, pathMode.getValue());
             }
         }
@@ -109,31 +118,16 @@ public class IgfsPaths implements Externalizable {
             out.writeBoolean(false);
     }
 
-    /**
-     * Write payload.
-     *
-     * @param out Output stream.
-     * @throws IOException If failed.
-     */
-    private void writePayload(ObjectOutput out) throws IOException {
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, 
ClassNotFoundException {
+        byte[] factoryBytes = U.readByteArray(in);
 
-        ObjectOutput oo = new ObjectOutputStream(baos);
+        assert factoryBytes != null;
 
-        try {
-            oo.writeObject(payload);
-        }
-        finally {
-            oo.close();
+        try (ObjectInput oi = new ObjectInputStream(new 
ByteArrayInputStream(factoryBytes))) {
+            payload = oi.readObject();
         }
 
-        U.writeByteArray(out, baos.toByteArray());
-    }
-
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, 
ClassNotFoundException {
-        readPayload(in);
-
         dfltMode = IgfsMode.fromOrdinal(in.readByte());
 
         if (in.readBoolean()) {
@@ -143,32 +137,11 @@ public class IgfsPaths implements Externalizable {
 
             for (int i = 0; i < size; i++) {
                 IgfsPath path = new IgfsPath();
-                path.readExternal(in);
 
-                T2<IgfsPath, IgfsMode> entry = new T2<>(path, 
IgfsMode.fromOrdinal(in.readByte()));
+                path.readExternal(in);
 
-                pathModes.add(entry);
+                pathModes.add(new T2<>(path, 
IgfsMode.fromOrdinal(in.readByte())));
             }
         }
     }
-
-    /**
-     * Read payload.
-     *
-     * @param in Input stream.
-     * @throws IOException If failed.
-     * @throws ClassNotFoundException If failed.
-     */
-    private void readPayload(ObjectInput in) throws IOException, 
ClassNotFoundException {
-        byte[] factoryBytes = U.readByteArray(in);
-
-        ObjectInput oi = new ObjectInputStream(new 
ByteArrayInputStream(factoryBytes));
-
-        try {
-            payload = oi.readObject();
-        }
-        finally {
-            oi.close();
-        }
-    }
 }
\ No newline at end of file

Reply via email to