From 4fb4a056c52d3a96b6ef9a4ceb5ce39fc716a9aa Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 21 Apr 2011 17:40:13 +0000 Subject: It...builds? --- 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/GatsBoolean.java | 17 +++++ java/com/xagasoft/gats/GatsDictionary.java | 17 +++++ java/com/xagasoft/gats/GatsFloat.java | 17 +++++ java/com/xagasoft/gats/GatsInputStream.java | 22 +++--- java/com/xagasoft/gats/GatsInteger.java | 102 +++++++++++++++++++++++++++ java/com/xagasoft/gats/GatsList.java | 17 +++++ java/com/xagasoft/gats/GatsObject.java | 23 +++--- java/com/xagasoft/gats/GatsOutputStream.java | 4 +- java/com/xagasoft/gats/GatsString.java | 17 +++++ java/com/xagasoft/gats/Integer.java | 71 ------------------- java/com/xagasoft/gats/List.java | 10 --- java/com/xagasoft/gats/String.java | 10 --- 15 files changed, 213 insertions(+), 144 deletions(-) delete mode 100644 java/com/xagasoft/gats/Boolean.java delete mode 100644 java/com/xagasoft/gats/Dictionary.java delete mode 100644 java/com/xagasoft/gats/Float.java create mode 100644 java/com/xagasoft/gats/GatsBoolean.java create mode 100644 java/com/xagasoft/gats/GatsDictionary.java create mode 100644 java/com/xagasoft/gats/GatsFloat.java create mode 100644 java/com/xagasoft/gats/GatsInteger.java create mode 100644 java/com/xagasoft/gats/GatsList.java create mode 100644 java/com/xagasoft/gats/GatsString.java delete mode 100644 java/com/xagasoft/gats/Integer.java delete mode 100644 java/com/xagasoft/gats/List.java delete mode 100644 java/com/xagasoft/gats/String.java (limited to 'java/com/xagasoft/gats') diff --git a/java/com/xagasoft/gats/Boolean.java b/java/com/xagasoft/gats/Boolean.java deleted file mode 100644 index 692247a..0000000 --- a/java/com/xagasoft/gats/Boolean.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.xagasoft.gats; - -public class Boolean extends GatsObject -{ - public int getGatsObject() - { - return GatsObject.BOOLEAN; - } -}; - diff --git a/java/com/xagasoft/gats/Dictionary.java b/java/com/xagasoft/gats/Dictionary.java deleted file mode 100644 index d96ff76..0000000 --- a/java/com/xagasoft/gats/Dictionary.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.xagasoft.gats; - -public class Dictionary extends GatsObject -{ - public int getGatsObject() - { - return GatsObject.DICTIONARY; - } -}; - diff --git a/java/com/xagasoft/gats/Float.java b/java/com/xagasoft/gats/Float.java deleted file mode 100644 index d0a9604..0000000 --- a/java/com/xagasoft/gats/Float.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.xagasoft.gats; - -public class Float extends GatsObject -{ - public int getGatsObject() - { - return GatsObject.FLOAT; - } -}; - diff --git a/java/com/xagasoft/gats/GatsBoolean.java b/java/com/xagasoft/gats/GatsBoolean.java new file mode 100644 index 0000000..8fec64a --- /dev/null +++ b/java/com/xagasoft/gats/GatsBoolean.java @@ -0,0 +1,17 @@ +package com.xagasoft.gats; + +import java.io.InputStream; +import java.io.OutputStream; + +public class GatsBoolean extends GatsObject +{ + public int getType() + { + return GatsObject.BOOLEAN; + } + + public void read( InputStream is, char cType ) + { + } +}; + diff --git a/java/com/xagasoft/gats/GatsDictionary.java b/java/com/xagasoft/gats/GatsDictionary.java new file mode 100644 index 0000000..1cf126e --- /dev/null +++ b/java/com/xagasoft/gats/GatsDictionary.java @@ -0,0 +1,17 @@ +package com.xagasoft.gats; + +import java.io.InputStream; +import java.io.OutputStream; + +public class GatsDictionary extends GatsObject +{ + public int getType() + { + return GatsObject.DICTIONARY; + } + + public void read( InputStream is, char cType ) + { + } +}; + diff --git a/java/com/xagasoft/gats/GatsFloat.java b/java/com/xagasoft/gats/GatsFloat.java new file mode 100644 index 0000000..b98c73a --- /dev/null +++ b/java/com/xagasoft/gats/GatsFloat.java @@ -0,0 +1,17 @@ +package com.xagasoft.gats; + +import java.io.InputStream; +import java.io.OutputStream; + +public class GatsFloat extends GatsObject +{ + public int getType() + { + return GatsObject.FLOAT; + } + + public void read( InputStream is, char cType ) + { + } +}; + diff --git a/java/com/xagasoft/gats/GatsInputStream.java b/java/com/xagasoft/gats/GatsInputStream.java index e787d56..e1c4781 100644 --- a/java/com/xagasoft/gats/GatsInputStream.java +++ b/java/com/xagasoft/gats/GatsInputStream.java @@ -2,6 +2,7 @@ package com.xagasoft.gats; import java.io.InputStream; import java.io.ByteArrayOutputStream; +import java.io.ByteArrayInputStream; import java.io.DataInputStream; public class GatsInputStream @@ -16,7 +17,7 @@ public class GatsInputStream this.is = is; } - public GatsObject readObject() + public GatsObject readObject() throws java.io.IOException { do { @@ -24,7 +25,7 @@ public class GatsInputStream { byte aBuf[] = new byte[5-baos.size()]; int iRead = is.read( aBuf ); - baos.write( ret, iRead ); + baos.write( aBuf, 0, iRead ); if( baos.size() < 5 ) return null; @@ -36,7 +37,7 @@ public class GatsInputStream ByteArrayInputStream bais = new ByteArrayInputStream( baos.toByteArray() ); - DataInputStream dis( bais ); + DataInputStream dis = new DataInputStream( bais ); iVer = dis.readUnsignedByte(); iSize = dis.readInt(); } @@ -49,7 +50,7 @@ public class GatsInputStream iGoal = 1500; int iRead = is.read( aBuf ); - baos.write( abuf, 0, iRead ); + baos.write( aBuf, 0, iRead ); if( iRead < iGoal ) return null; @@ -63,14 +64,13 @@ public class GatsInputStream ); bais.skip( 5 ); - GatsObject goRet = GatsObject::read( bais ); + GatsObject goRet = GatsObject.read( bais ); iVer = 0; return goRet; } - - private bool skipReadNulls() + private boolean skipReadNulls() { if( baos.size() == 0 ) return false; @@ -79,17 +79,17 @@ public class GatsInputStream if( aBuf[0] != 0 ) return true; - for( int j = 1; j < aBuf.size; j++ ) + for( int j = 1; j < aBuf.length; j++ ) { if( aBuf[j] != 0 ) { - baos.clear(); - baos.write( aBuf, j, aBuf.size-j ); + baos.reset(); + baos.write( aBuf, j, aBuf.length-j ); return true; } } - baos.clear(); + baos.reset(); return true; } }; diff --git a/java/com/xagasoft/gats/GatsInteger.java b/java/com/xagasoft/gats/GatsInteger.java new file mode 100644 index 0000000..1093ab2 --- /dev/null +++ b/java/com/xagasoft/gats/GatsInteger.java @@ -0,0 +1,102 @@ +package com.xagasoft.gats; + +import java.io.OutputStream; +import java.io.InputStream; + +public class GatsInteger extends GatsObject +{ + private long iValue = 0; + + public GatsInteger() + { + } + + public GatsInteger( long iValue ) + { + this.iValue = iValue; + } + + public long getValue() + { + return iValue; + } + + public void setValue( long iValue ) + { + this.iValue = iValue; + } + + public int getType() + { + return GatsObject.INTEGER; + }; + + public void read( InputStream is, char cType ) throws java.io.IOException + + { + iValue = readPackedInt( is ); + } + + public void write( OutputStream os ) throws java.io.IOException + { + os.write( (int)'i' ); + writePackedInt( os, iValue ); + } + + /** + * 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/GatsList.java b/java/com/xagasoft/gats/GatsList.java new file mode 100644 index 0000000..7c238be --- /dev/null +++ b/java/com/xagasoft/gats/GatsList.java @@ -0,0 +1,17 @@ +package com.xagasoft.gats; + +import java.io.InputStream; +import java.io.OutputStream; + +public class GatsList extends GatsObject +{ + public int getType() + { + return GatsObject.LIST; + } + + public void read( InputStream is, char cType ) + { + } +}; + diff --git a/java/com/xagasoft/gats/GatsObject.java b/java/com/xagasoft/gats/GatsObject.java index 63fcf36..852a18c 100644 --- a/java/com/xagasoft/gats/GatsObject.java +++ b/java/com/xagasoft/gats/GatsObject.java @@ -1,6 +1,7 @@ package com.xagasoft.gats; import java.io.InputStream; +import java.io.OutputStream; public abstract class GatsObject { @@ -13,45 +14,45 @@ public abstract class GatsObject public abstract int getType(); - public abstract void read( InputStream is, char cType ); + public abstract void read( InputStream is, char cType ) throws java.io.IOException; - public static GatsObject read( InputStream is ) + public static GatsObject read( InputStream is ) throws java.io.IOException { - char type = is.read(); - GatsObject goRet; + char type = (char)is.read(); + GatsObject goRet = null; switch( type ) { case 'i': - goRet = new Integer(); + goRet = new GatsInteger(); break; case 's': - goRet = new String(); + // goRet = new GatsString(); break; case '0': case '1': - goRet = new Boolean(); + // goRet = new GatsBoolean(); break; case 'l': - goRet = new List(); + // goRet = new GatsList(); break; case 'd': - goRet = new Dictionary(); + // goRet = new GatsDictionary(); break; case 'f': case 'F': - goRet = new Float(); + // goRet = new GatsFloat(); break; case 'e': return null; default: - throw new Exception("Invalid gats type discovered: " + (char)type ); + throw new java.io.IOException("Invalid gats type discovered: " + (char)type ); } goRet.read( is, type ); diff --git a/java/com/xagasoft/gats/GatsOutputStream.java b/java/com/xagasoft/gats/GatsOutputStream.java index f3020f4..0ba452d 100644 --- a/java/com/xagasoft/gats/GatsOutputStream.java +++ b/java/com/xagasoft/gats/GatsOutputStream.java @@ -1,7 +1,9 @@ package com.xagasoft.gats; +import java.io.InputStream; +import java.io.OutputStream; + public class GatsOutputStream { - public GatsOutputStream( }; diff --git a/java/com/xagasoft/gats/GatsString.java b/java/com/xagasoft/gats/GatsString.java new file mode 100644 index 0000000..07456b5 --- /dev/null +++ b/java/com/xagasoft/gats/GatsString.java @@ -0,0 +1,17 @@ +package com.xagasoft.gats; + +import java.io.InputStream; +import java.io.OutputStream; + +public class GatsString extends GatsObject +{ + public int getType() + { + return GatsObject.STRING; + } + + public void read( InputStream is, char cType ) + { + } +}; + diff --git a/java/com/xagasoft/gats/Integer.java b/java/com/xagasoft/gats/Integer.java deleted file mode 100644 index ab3d6de..0000000 --- a/java/com/xagasoft/gats/Integer.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.xagasoft.gats; - -import java.io.OutputStream; -import java.io.InputStream; - -public class Integer extends GatsObject -{ - public int getGatsObject() - { - return GatsObject.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 deleted file mode 100644 index dbc729b..0000000 --- a/java/com/xagasoft/gats/List.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.xagasoft.gats; - -public class List extends GatsObject -{ - public int getGatsObject() - { - return GatsObject.LIST; - } -}; - diff --git a/java/com/xagasoft/gats/String.java b/java/com/xagasoft/gats/String.java deleted file mode 100644 index 301a98a..0000000 --- a/java/com/xagasoft/gats/String.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.xagasoft.gats; - -public class String extends GatsObject -{ - public int getGatsObject() - { - return GatsObject.STRING; - } -}; - -- cgit v1.2.3