From 7dd5c386611e31930e7ccfb83cb585df27696881 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 1 Mar 2012 04:24:35 +0000 Subject: Fixed a bug in java gats reading large strings over the network. --- java/com/xagasoft/gats/GatsObject.java | 5 +++-- java/com/xagasoft/gats/GatsString.java | 10 +++++++--- python/test.py | 4 ++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/java/com/xagasoft/gats/GatsObject.java b/java/com/xagasoft/gats/GatsObject.java index fc3fb5a..47602b3 100644 --- a/java/com/xagasoft/gats/GatsObject.java +++ b/java/com/xagasoft/gats/GatsObject.java @@ -43,7 +43,8 @@ public abstract class GatsObject */ static GatsObject read( InputStream is ) throws java.io.IOException { - char type = (char)is.read(); + int b = is.read(); + char type = (char)b; GatsObject goRet = null; switch( type ) { @@ -77,7 +78,7 @@ public abstract class GatsObject return null; default: - throw new java.io.IOException("Invalid gats type discovered: " + (char)type ); + throw new java.io.IOException("Invalid gats type discovered: " + type + ", (" + b + ")" ); } goRet.read( is, type ); diff --git a/java/com/xagasoft/gats/GatsString.java b/java/com/xagasoft/gats/GatsString.java index e119aec..8e5c5c0 100644 --- a/java/com/xagasoft/gats/GatsString.java +++ b/java/com/xagasoft/gats/GatsString.java @@ -59,9 +59,13 @@ public class GatsString extends GatsObject void read( InputStream is, char cType ) throws java.io.IOException { - long lSize = GatsInteger.readPackedInt( is ); - aValue = new byte[(int)lSize]; - is.read( aValue ); + int lSize = (int)GatsInteger.readPackedInt( is ); + aValue = new byte[lSize]; + int lRead = 0; + do + { + lRead += is.read( aValue, lRead, lSize-lRead ); + } while( lRead < lSize ); } void write( OutputStream os ) throws java.io.IOException diff --git a/python/test.py b/python/test.py index 14e8306..f4e679a 100755 --- a/python/test.py +++ b/python/test.py @@ -2,9 +2,9 @@ import gats -#print gats.load( open('test.gats', 'rb') ) +print gats.load( open('test.gats', 'rb') ) -#gats.dump( 3.14159, open('out.gats', 'wb') ) +gats.dump( 3.14159, open('out.gats', 'wb') ) print gats.loads( gats.dumps( -- cgit v1.2.3