Commit c580edfc authored by Dave Cridland's avatar Dave Cridland Committed by GitHub

Merge pull request #602 from wmz7year/optimizationClusterExternalizableUtil

	Optimization ClusterExternalizableUtil writeByteArray performance
parents 62579465 47e2af43
...@@ -373,8 +373,14 @@ public class ClusterExternalizableUtil implements ExternalizableUtilStrategy { ...@@ -373,8 +373,14 @@ public class ClusterExternalizableUtil implements ExternalizableUtilStrategy {
} else if (obj instanceof Date) { } else if (obj instanceof Date) {
out.writeByte(8); out.writeByte(8);
out.writeLong(((Date) obj).getTime()); out.writeLong(((Date) obj).getTime());
} else { } else if(obj instanceof byte[]){
out.writeByte(9); out.writeByte(9);
// write length
out.writeInt(((byte[]) obj).length);
// write byte array
out.write((byte[]) obj);
} else {
out.writeByte(10);
ByteArrayOutputStream bos = new ByteArrayOutputStream(); ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos); ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(obj); oos.writeObject(obj);
...@@ -404,6 +410,10 @@ public class ClusterExternalizableUtil implements ExternalizableUtilStrategy { ...@@ -404,6 +410,10 @@ public class ClusterExternalizableUtil implements ExternalizableUtilStrategy {
} else if (type == 8) { } else if (type == 8) {
return new Date(in.readLong()); return new Date(in.readLong());
} else if (type == 9) { } else if (type == 9) {
byte[] buf = new byte[in.readInt()];
in.readFully(buf);
return buf;
} else if (type == 10) {
int len = in.readInt(); int len = in.readInt();
byte[] buf = new byte[len]; byte[] buf = new byte[len];
in.readFully(buf); in.readFully(buf);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment