[jbosscache-commits] JBoss Cache SVN: r5337 - core/trunk/src/main/java/org/jboss/cache/marshall.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Fri Feb 8 13:24:39 EST 2008


Author: manik.surtani at jboss.com
Date: 2008-02-08 13:24:39 -0500 (Fri, 08 Feb 2008)
New Revision: 5337

Modified:
   core/trunk/src/main/java/org/jboss/cache/marshall/VersionAwareMarshaller.java
Log:
push back header if it doesn't exist in the stream

Modified: core/trunk/src/main/java/org/jboss/cache/marshall/VersionAwareMarshaller.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/VersionAwareMarshaller.java	2008-02-08 15:58:29 UTC (rev 5336)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/VersionAwareMarshaller.java	2008-02-08 18:24:39 UTC (rev 5337)
@@ -13,6 +13,7 @@
 import org.jboss.cache.factories.annotations.Inject;
 import org.jboss.cache.factories.annotations.Start;
 import org.jboss.cache.marshall.io.ObjectStreamPool;
+import org.jboss.cache.marshall.io.ReusableObjectInputStream;
 import org.jboss.cache.marshall.io.ReusableObjectOutputStream;
 import org.jboss.cache.util.Util;
 import org.jboss.util.stream.MarshalledValueInputStream;
@@ -22,6 +23,8 @@
 import java.io.InputStream;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
+import java.io.PushbackInputStream;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.StringTokenizer;
@@ -237,7 +240,16 @@
          // we don't have a reusable implementation for non-byte-backed streams as yet.
          short versionId;
          Marshaller marshaller;
-         ObjectInputStream in = new MarshalledValueInputStream(is);
+         PushbackInputStream pis = new PushbackInputStream(is);
+         byte[] first4bytes = new byte[4];
+         pis.read(first4bytes);
+         boolean needToWriteHeader = !Arrays.equals(first4bytes, ReusableObjectInputStream.INIT_BYTES);
+         // first push back the bytes read
+         pis.unread(first4bytes);
+         if (needToWriteHeader) pis.unread(ReusableObjectInputStream.INIT_BYTES);
+
+         ObjectInputStream in = new MarshalledValueInputStream(pis);
+
          try
          {
             versionId = in.readShort();




More information about the jbosscache-commits mailing list