From 757042bd5748389d3b984bbff72c2b2e3d9d5dd0 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 21 Apr 2011 17:57:04 +0000 Subject: You can read and write integers now. Other types should be pretty easy from here. --- java/com/xagasoft/gats/GatsObject.java | 1 + java/com/xagasoft/gats/GatsOutputStream.java | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) (limited to 'java/com/xagasoft') diff --git a/java/com/xagasoft/gats/GatsObject.java b/java/com/xagasoft/gats/GatsObject.java index 852a18c..031dc90 100644 --- a/java/com/xagasoft/gats/GatsObject.java +++ b/java/com/xagasoft/gats/GatsObject.java @@ -15,6 +15,7 @@ public abstract class GatsObject public abstract int getType(); public abstract void read( InputStream is, char cType ) throws java.io.IOException; + public abstract void write( OutputStream os ) throws java.io.IOException; public static GatsObject read( InputStream is ) throws java.io.IOException { diff --git a/java/com/xagasoft/gats/GatsOutputStream.java b/java/com/xagasoft/gats/GatsOutputStream.java index 0ba452d..7bdfcde 100644 --- a/java/com/xagasoft/gats/GatsOutputStream.java +++ b/java/com/xagasoft/gats/GatsOutputStream.java @@ -1,9 +1,34 @@ package com.xagasoft.gats; -import java.io.InputStream; import java.io.OutputStream; +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; public class GatsOutputStream { + private OutputStream os; + + public GatsOutputStream( OutputStream os ) + { + this.os = os; + } + + public void writeObject( GatsObject obj ) throws java.io.IOException + { + ByteArrayOutputStream bos1 = new ByteArrayOutputStream(); + + obj.write( bos1 ); + + ByteArrayOutputStream bos2 = new ByteArrayOutputStream( + 5 + bos1.size() + ); + + DataOutputStream dos = new DataOutputStream( bos2 ); + dos.writeByte( 1 ); + dos.writeInt( bos1.size()+5 ); + bos2.write( bos1.toByteArray() ); + + os.write( bos2.toByteArray() ); + } }; -- cgit v1.2.3