You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2017/05/24 23:41:42 UTC
[25/31] geode git commit: Do NOT close HeapDataOutputStream that is
passed to Part
Do NOT close HeapDataOutputStream that is passed to Part
Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/3a156e08
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/3a156e08
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/3a156e08
Branch: refs/heads/feature/GEODE-2632-17
Commit: 3a156e0896f0986492e65687e66f6c7aa8a8b15f
Parents: a637f76
Author: Kirk Lund <kl...@apache.org>
Authored: Tue May 23 14:46:34 2017 -0700
Committer: Kirk Lund <kl...@apache.org>
Committed: Wed May 24 16:41:08 2017 -0700
----------------------------------------------------------------------
.../internal/cache/tier/sockets/Message.java | 53 +++++++-------------
1 file changed, 18 insertions(+), 35 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode/blob/3a156e08/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/Message.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/Message.java b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/Message.java
index 2ac6fea..1f9ef91 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/Message.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/Message.java
@@ -14,8 +14,6 @@
*/
package org.apache.geode.internal.cache.tier.sockets;
-import static org.apache.geode.internal.util.IOUtils.close;
-
import org.apache.geode.SerializationException;
import org.apache.geode.distributed.internal.DistributionConfig;
import org.apache.geode.internal.Assert;
@@ -111,26 +109,20 @@ public class Message {
private static final byte[] FALSE = defineFalse();
private static byte[] defineTrue() {
- HeapDataOutputStream hdos = new HeapDataOutputStream(10, null);
- try {
+ try (HeapDataOutputStream hdos = new HeapDataOutputStream(10, null)) {
BlobHelper.serializeTo(Boolean.TRUE, hdos);
return hdos.toByteArray();
} catch (IOException e) {
throw new IllegalStateException(e);
- } finally {
- close(hdos);
}
}
private static byte[] defineFalse() {
- HeapDataOutputStream hdos = new HeapDataOutputStream(10, null);
- try {
+ try (HeapDataOutputStream hdos = new HeapDataOutputStream(10, null)) {
BlobHelper.serializeTo(Boolean.FALSE, hdos);
return hdos.toByteArray();
} catch (IOException e) {
throw new IllegalStateException(e);
- } finally {
- close(hdos);
}
}
@@ -288,23 +280,17 @@ public class Message {
if (enableCaching) {
byte[] bytes = CACHED_STRINGS.get(str);
if (bytes == null) {
- HeapDataOutputStream hdos = new HeapDataOutputStream(str);
- try {
+ try (HeapDataOutputStream hdos = new HeapDataOutputStream(str)) {
bytes = hdos.toByteArray();
CACHED_STRINGS.put(str, bytes);
- } finally {
- close(hdos);
}
}
part.setPartState(bytes, false);
+
} else {
- HeapDataOutputStream hdos = new HeapDataOutputStream(str);
- try {
- this.messageModified = true;
- part.setPartState(hdos, false);
- } finally {
- close(hdos);
- }
+ // do NOT close the HeapDataOutputStream
+ this.messageModified = true;
+ part.setPartState(new HeapDataOutputStream(str), false);
}
this.currentPart++;
}
@@ -380,20 +366,18 @@ public class Message {
v = null;
}
- // create the HDOS with a flag telling it that it can keep any byte[] or ByteBuffers/ByteSources
- // passed to it.
+ // Create the HDOS with a flag telling it that it can keep any byte[] or ByteBuffers/ByteSources
+ // passed to it. Do NOT close the HeapDataOutputStream!
HeapDataOutputStream hdos = new HeapDataOutputStream(this.chunkSize, v, true);
try {
BlobHelper.serializeTo(o, hdos);
- this.messageModified = true;
- Part part = this.partsList[this.currentPart];
- part.setPartState(hdos, true);
- this.currentPart++;
} catch (IOException ex) {
throw new SerializationException("failed serializing object", ex);
- } finally {
- close(hdos);
}
+ this.messageModified = true;
+ Part part = this.partsList[this.currentPart];
+ part.setPartState(hdos, true);
+ this.currentPart++;
}
private void serializeAndAddPart(Object o, boolean zipValues) {
@@ -406,18 +390,17 @@ public class Message {
v = null;
}
+ // do NOT close the HeapDataOutputStream
HeapDataOutputStream hdos = new HeapDataOutputStream(this.chunkSize, v);
try {
BlobHelper.serializeTo(o, hdos);
- this.messageModified = true;
- Part part = this.partsList[this.currentPart];
- part.setPartState(hdos, true);
- this.currentPart++;
} catch (IOException ex) {
throw new SerializationException("failed serializing object", ex);
- } finally {
- close(hdos);
}
+ this.messageModified = true;
+ Part part = this.partsList[this.currentPart];
+ part.setPartState(hdos, true);
+ this.currentPart++;
}
public void addIntPart(int v) {