[jboss-jira] [JBoss JIRA] Commented: (JBCACHE-1289) VersionAwareMarshalle.objectFromStream implemention uses unreliable InputStream.available
Elias Ross (JIRA)
jira-events at lists.jboss.org
Thu Feb 7 18:05:04 EST 2008
[ http://jira.jboss.com/jira/browse/JBCACHE-1289?page=comments#action_12398835 ]
Elias Ross commented on JBCACHE-1289:
-------------------------------------
The following change seems to work ok:
Index: C:/src/workspace/JBossCacheSvn/src/main/java/org/jboss/cache/marshall/VersionAwareMarshaller.java
===================================================================
--- C:/src/workspace/JBossCacheSvn/src/main/java/org/jboss/cache/marshall/VersionAwareMarshaller.java (revision 5309)
+++ C:/src/workspace/JBossCacheSvn/src/main/java/org/jboss/cache/marshall/VersionAwareMarshaller.java (working copy)
@@ -16,10 +16,16 @@
import org.jboss.cache.marshall.io.ObjectStreamPool;
import org.jboss.cache.marshall.io.ReusableObjectOutputStream;
import org.jboss.cache.util.Util;
+import org.jboss.util.stream.MarshalledValueInputStream;
+import static java.io.ObjectStreamConstants.STREAM_MAGIC;
+import static java.io.ObjectStreamConstants.STREAM_VERSION;
+import static java.io.ObjectStreamConstants.TC_BLOCKDATA;
+
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import java.io.PushbackInputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
@@ -207,12 +213,27 @@
}
}
+ private final static byte[] INIT_BYTES = {(byte) ((STREAM_MAGIC >>> 8) & 0xFF),
+ (byte) ((STREAM_MAGIC) & 0xFF),
+ (byte) ((STREAM_VERSION >>> 8)),
+ (byte) ((STREAM_VERSION) & 0xFF),
+ TC_BLOCKDATA, 0};
+
+ @Override
public Object objectFromStream(InputStream is) throws Exception
{
+ /* available() may return < really available!
int avbl = is.available();
byte[] bytes = new byte[avbl];
is.read(bytes, 0, avbl);
return objectFromByteBuffer(bytes);
+ */
+ PushbackInputStream pis = new PushbackInputStream(is, 100);
+ pis.unread(INIT_BYTES);
+ ObjectInputStream ois = new MarshalledValueInputStream(pis);
+ short versionId = ois.readShort();
+ Marshaller marshaller = getMarshaller(versionId);
+ return marshaller.objectFromObjectStream(ois);
}
public void objectToObjectStream(Object obj, ObjectOutputStream out, Fqn region) throws Exception
> VersionAwareMarshalle.objectFromStream implemention uses unreliable InputStream.available
> -----------------------------------------------------------------------------------------
>
> Key: JBCACHE-1289
> URL: http://jira.jboss.com/jira/browse/JBCACHE-1289
> Project: JBoss Cache
> Issue Type: Bug
> Security Level: Public(Everyone can see)
> Reporter: Elias Ross
> Assigned To: Manik Surtani
>
> InputStream.available() may return less than the complete number of bytes available on the stream. The following does not work:
> @Override
> public Object objectFromStream(InputStream is) throws Exception
> {
> int avbl = is.available(); // MAY RETURN 1 !
> byte[] bytes = new byte[avbl];
> is.read(bytes, 0, avbl);
> return objectFromByteBuffer(bytes);
> }
> I want to be able to stream objects from the Amazon S3 service. The following does not work either:
> ObjectInputStream ois = new MarshalledValueInputStream(is);
> short versionId = ois.readShort();
> Marshaller marshaller = getMarshaller(versionId);
> return marshaller.objectFromObjectStream(ois);
> I'm guessing ReusableObjectInputStream needs to be used and changed to actually support streams, not byte arrays! But I'm not too familiar with the mechanics.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the jboss-jira
mailing list