From f0918e61039a18947a31efe01d23b7607acf9c92 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 21 Apr 2011 18:13:29 +0000 Subject: Strings work now. --- java/com/xagasoft/gats/GatsObject.java | 2 +- java/com/xagasoft/gats/GatsString.java | 51 +++++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 2 deletions(-) (limited to 'java/com/xagasoft') diff --git a/java/com/xagasoft/gats/GatsObject.java b/java/com/xagasoft/gats/GatsObject.java index 031dc90..1538c93 100644 --- a/java/com/xagasoft/gats/GatsObject.java +++ b/java/com/xagasoft/gats/GatsObject.java @@ -28,7 +28,7 @@ public abstract class GatsObject break; case 's': - // goRet = new GatsString(); + goRet = new GatsString(); break; case '0': diff --git a/java/com/xagasoft/gats/GatsString.java b/java/com/xagasoft/gats/GatsString.java index 89edc21..e512ade 100644 --- a/java/com/xagasoft/gats/GatsString.java +++ b/java/com/xagasoft/gats/GatsString.java @@ -5,17 +5,66 @@ import java.io.OutputStream; public class GatsString extends GatsObject { + private byte[] aValue = null; + + public GatsString() + { + } + + public GatsString( String sValue ) + { + this.aValue = sValue.getBytes(); + } + + public GatsString( byte[] aValue ) + { + this.aValue = aValue; + } + + public byte[] getValue() + { + return aValue; + } + + public void setValue( String sValue ) + { + this.aValue = sValue.getBytes(); + } + + public void setValue( byte[] aValue ) + { + this.aValue = aValue; + } + + public String toString() + { + return new String( aValue ); + } + public int getType() { return GatsObject.STRING; } - public void read( InputStream is, char cType ) + public void read( InputStream is, char cType ) throws java.io.IOException { + long lSize = GatsInteger.readPackedInt( is ); + aValue = new byte[(int)lSize]; + is.read( aValue ); } public void write( OutputStream os ) throws java.io.IOException { + os.write( (int)'s' ); + if( aValue == null ) + { + GatsInteger.writePackedInt( os, 0 ); + } + else + { + GatsInteger.writePackedInt( os, aValue.length ); + os.write( aValue ); + } } }; -- cgit v1.2.3