Author: manik.surtani(a)jboss.com
Date: 2008-02-11 17:00:17 -0500 (Mon, 11 Feb 2008)
New Revision: 5342
Modified:
core/trunk/src/main/java/org/jboss/cache/marshall/VersionAwareMarshaller.java
core/trunk/src/main/java/org/jboss/cache/marshall/io/ReusableObjectInputStream.java
core/trunk/src/main/java/org/jboss/cache/marshall/io/ReusableObjectOutputStream.java
Log:
make sure we add object stream headers so streams from reusable streams are compatible
with JDK object streams
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-11
13:54:22 UTC (rev 5341)
+++
core/trunk/src/main/java/org/jboss/cache/marshall/VersionAwareMarshaller.java 2008-02-11
22:00:17 UTC (rev 5342)
@@ -13,7 +13,6 @@
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;
@@ -23,8 +22,6 @@
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;
@@ -240,15 +237,17 @@
// we don't have a reusable implementation for non-byte-backed streams as
yet.
short versionId;
Marshaller marshaller;
- 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);
+// 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);
+ ObjectInputStream in = new MarshalledValueInputStream(is);
try
{
Modified:
core/trunk/src/main/java/org/jboss/cache/marshall/io/ReusableObjectInputStream.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/marshall/io/ReusableObjectInputStream.java 2008-02-11
13:54:22 UTC (rev 5341)
+++
core/trunk/src/main/java/org/jboss/cache/marshall/io/ReusableObjectInputStream.java 2008-02-11
22:00:17 UTC (rev 5342)
@@ -1,5 +1,6 @@
package org.jboss.cache.marshall.io;
+import org.jboss.cache.CacheException;
import org.jboss.util.stream.MarshalledValueInputStream;
import java.io.ByteArrayInputStream;
@@ -86,9 +87,10 @@
*/
public void init(byte[] b)
{
+ if (b.length < 4) throw new CacheException("No header bytes!");
buf = b;
count = buf.length;
- pos = 0;
+ pos = 4;
}
}
Modified:
core/trunk/src/main/java/org/jboss/cache/marshall/io/ReusableObjectOutputStream.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/marshall/io/ReusableObjectOutputStream.java 2008-02-11
13:54:22 UTC (rev 5341)
+++
core/trunk/src/main/java/org/jboss/cache/marshall/io/ReusableObjectOutputStream.java 2008-02-11
22:00:17 UTC (rev 5342)
@@ -96,7 +96,9 @@
public void init()
{
if (buf == null) buf = new byte[defaultBufferSize];
- count = 0;
+ // write the header bytes
+ System.arraycopy(ReusableObjectInputStream.INIT_BYTES, 0, buf, 0, 4);
+ count = 4;
}
}
}