From b251853a7d1bade6a8a49f3ae331f62fb4c59afc Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 10 Mar 2011 22:48:18 +0000 Subject: The beginings of java gats. --- java/com/xagasoft/gats/Boolean.java | 10 +++++ java/com/xagasoft/gats/Dictionary.java | 10 +++++ java/com/xagasoft/gats/Float.java | 10 +++++ java/com/xagasoft/gats/GatsStream.java | 6 +++ java/com/xagasoft/gats/Integer.java | 71 ++++++++++++++++++++++++++++++++++ java/com/xagasoft/gats/List.java | 10 +++++ java/com/xagasoft/gats/String.java | 10 +++++ java/com/xagasoft/gats/Type.java | 16 ++++++++ 8 files changed, 143 insertions(+) create mode 100644 java/com/xagasoft/gats/Boolean.java create mode 100644 java/com/xagasoft/gats/Dictionary.java create mode 100644 java/com/xagasoft/gats/Float.java create mode 100644 java/com/xagasoft/gats/GatsStream.java create mode 100644 java/com/xagasoft/gats/Integer.java create mode 100644 java/com/xagasoft/gats/List.java create mode 100644 java/com/xagasoft/gats/String.java create mode 100644 java/com/xagasoft/gats/Type.java (limited to 'java/com/xagasoft/gats') diff --git a/java/com/xagasoft/gats/Boolean.java b/java/com/xagasoft/gats/Boolean.java new file mode 100644 index 0000000..eb83ecd --- /dev/null +++ b/java/com/xagasoft/gats/Boolean.java @@ -0,0 +1,10 @@ +package com.xagasoft.gats; + +public class Boolean extends Type +{ + public int getType() + { + return Type.BOOLEAN; + } +}; + diff --git a/java/com/xagasoft/gats/Dictionary.java b/java/com/xagasoft/gats/Dictionary.java new file mode 100644 index 0000000..1166899 --- /dev/null +++ b/java/com/xagasoft/gats/Dictionary.java @@ -0,0 +1,10 @@ +package com.xagasoft.gats; + +public class Dictionary extends Type +{ + public int getType() + { + return Type.DICTIONARY; + } +}; + diff --git a/java/com/xagasoft/gats/Float.java b/java/com/xagasoft/gats/Float.java new file mode 100644 index 0000000..60d5cf0 --- /dev/null +++ b/java/com/xagasoft/gats/Float.java @@ -0,0 +1,10 @@ +package com.xagasoft.gats; + +public class Float extends Type +{ + public int getType() + { + return Type.FLOAT; + } +}; + diff --git a/java/com/xagasoft/gats/GatsStream.java b/java/com/xagasoft/gats/GatsStream.java new file mode 100644 index 0000000..0cbd775 --- /dev/null +++ b/java/com/xagasoft/gats/GatsStream.java @@ -0,0 +1,6 @@ +package com.xagasoft.gats; + +public class GatsStream +{ +}; + diff --git a/java/com/xagasoft/gats/Integer.java b/java/com/xagasoft/gats/Integer.java new file mode 100644 index 0000000..7da12d4 --- /dev/null +++ b/java/com/xagasoft/gats/Integer.java @@ -0,0 +1,71 @@ +package com.xagasoft.gats; + +import java.io.OutputStream; +import java.io.InputStream; + +public class Integer extends Type +{ + public int getType() + { + return Type.INTEGER; + }; + + /** + * Possible TODO: have this return a Number, and construct either a Long + * or BigInteger when appropriate. + */ + public static long readPackedInt( InputStream is ) + throws java.io.IOException + { + int b; + long rOut = 0; + boolean bNeg; + + b = is.read(); + bNeg = (b&0x40) == 0x40; + rOut |= b&0x3F; + int c = 0; + while( (b&0x80) == 0x80 ) + { + b = is.read(); + rOut |= (long)(b&0x7F) << (6+7*(c++)); + } + if( bNeg ) + return -rOut; + return rOut; + } + + public static void writePackedInt( OutputStream os, long iIn ) + throws java.io.IOException + { + int b; + + if( iIn < 0 ) + { + iIn = -iIn; + b = (int)(iIn&0x3F); + if( iIn > b ) + b |= 0x80 | 0x40; + else + b |= 0x40; + } + else + { + b = (int)(iIn&0x3F); + if( iIn > b ) + b |= 0x80; + } + os.write( b ); + iIn = iIn >> 6; + + while( iIn > 0 ) + { + b = (int)(iIn&0x7F); + if( iIn > b ) + b |= 0x80; + os.write( b ); + iIn = iIn >> 7; + } + } +}; + diff --git a/java/com/xagasoft/gats/List.java b/java/com/xagasoft/gats/List.java new file mode 100644 index 0000000..99d10e9 --- /dev/null +++ b/java/com/xagasoft/gats/List.java @@ -0,0 +1,10 @@ +package com.xagasoft.gats; + +public class List extends Type +{ + public int getType() + { + return Type.LIST; + } +}; + diff --git a/java/com/xagasoft/gats/String.java b/java/com/xagasoft/gats/String.java new file mode 100644 index 0000000..b89d042 --- /dev/null +++ b/java/com/xagasoft/gats/String.java @@ -0,0 +1,10 @@ +package com.xagasoft.gats; + +public class String extends Type +{ + public int getType() + { + return Type.STRING; + } +}; + diff --git a/java/com/xagasoft/gats/Type.java b/java/com/xagasoft/gats/Type.java new file mode 100644 index 0000000..d6bff4d --- /dev/null +++ b/java/com/xagasoft/gats/Type.java @@ -0,0 +1,16 @@ +package com.xagasoft.gats; + +public abstract class Type +{ + public final static int INTEGER = 1; + public final static int FLOAT = 2; + public final static int STRING = 3; + public final static int LIST = 4; + public final static int DICTIONARY = 5; + public final static int BOOLEAN = 6; + + public abstract int getType(); + + +}; + -- cgit v1.2.3