aboutsummaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2011-04-21 17:19:19 +0000
committerMike Buland <eichlan@xagasoft.com>2011-04-21 17:19:19 +0000
commit49216a230c331791b06df1527c3245c88e991c20 (patch)
tree3ac2a22fdc1e2d30cd960cd4fe77e137a3a0a846 /java
parentcd3a919b88c401fd86b1f4c853ee60898f2cb24a (diff)
downloadlibgats-49216a230c331791b06df1527c3245c88e991c20.tar.gz
libgats-49216a230c331791b06df1527c3245c88e991c20.tar.bz2
libgats-49216a230c331791b06df1527c3245c88e991c20.tar.xz
libgats-49216a230c331791b06df1527c3245c88e991c20.zip
Gats for java is getting closer.
Diffstat (limited to 'java')
-rw-r--r--java/com/xagasoft/gats/Boolean.java6
-rw-r--r--java/com/xagasoft/gats/Dictionary.java6
-rw-r--r--java/com/xagasoft/gats/Float.java6
-rw-r--r--java/com/xagasoft/gats/GatsInputStream.java96
-rw-r--r--java/com/xagasoft/gats/GatsObject.java62
-rw-r--r--java/com/xagasoft/gats/GatsOutputStream.java7
-rw-r--r--java/com/xagasoft/gats/GatsStream.java6
-rw-r--r--java/com/xagasoft/gats/Integer.java6
-rw-r--r--java/com/xagasoft/gats/List.java6
-rw-r--r--java/com/xagasoft/gats/String.java6
-rw-r--r--java/com/xagasoft/gats/Type.java16
11 files changed, 183 insertions, 40 deletions
diff --git a/java/com/xagasoft/gats/Boolean.java b/java/com/xagasoft/gats/Boolean.java
index eb83ecd..692247a 100644
--- a/java/com/xagasoft/gats/Boolean.java
+++ b/java/com/xagasoft/gats/Boolean.java
@@ -1,10 +1,10 @@
1package com.xagasoft.gats; 1package com.xagasoft.gats;
2 2
3public class Boolean extends Type 3public class Boolean extends GatsObject
4{ 4{
5 public int getType() 5 public int getGatsObject()
6 { 6 {
7 return Type.BOOLEAN; 7 return GatsObject.BOOLEAN;
8 } 8 }
9}; 9};
10 10
diff --git a/java/com/xagasoft/gats/Dictionary.java b/java/com/xagasoft/gats/Dictionary.java
index 1166899..d96ff76 100644
--- a/java/com/xagasoft/gats/Dictionary.java
+++ b/java/com/xagasoft/gats/Dictionary.java
@@ -1,10 +1,10 @@
1package com.xagasoft.gats; 1package com.xagasoft.gats;
2 2
3public class Dictionary extends Type 3public class Dictionary extends GatsObject
4{ 4{
5 public int getType() 5 public int getGatsObject()
6 { 6 {
7 return Type.DICTIONARY; 7 return GatsObject.DICTIONARY;
8 } 8 }
9}; 9};
10 10
diff --git a/java/com/xagasoft/gats/Float.java b/java/com/xagasoft/gats/Float.java
index 60d5cf0..d0a9604 100644
--- a/java/com/xagasoft/gats/Float.java
+++ b/java/com/xagasoft/gats/Float.java
@@ -1,10 +1,10 @@
1package com.xagasoft.gats; 1package com.xagasoft.gats;
2 2
3public class Float extends Type 3public class Float extends GatsObject
4{ 4{
5 public int getType() 5 public int getGatsObject()
6 { 6 {
7 return Type.FLOAT; 7 return GatsObject.FLOAT;
8 } 8 }
9}; 9};
10 10
diff --git a/java/com/xagasoft/gats/GatsInputStream.java b/java/com/xagasoft/gats/GatsInputStream.java
new file mode 100644
index 0000000..e787d56
--- /dev/null
+++ b/java/com/xagasoft/gats/GatsInputStream.java
@@ -0,0 +1,96 @@
1package com.xagasoft.gats;
2
3import java.io.InputStream;
4import java.io.ByteArrayOutputStream;
5import java.io.DataInputStream;
6
7public class GatsInputStream
8{
9 private InputStream is;
10 private ByteArrayOutputStream baos = new ByteArrayOutputStream();
11 private int iVer = 0;
12 private int iSize;
13
14 public GatsInputStream( InputStream is )
15 {
16 this.is = is;
17 }
18
19 public GatsObject readObject()
20 {
21 do
22 {
23 if( baos.size() < 5 )
24 {
25 byte aBuf[] = new byte[5-baos.size()];
26 int iRead = is.read( aBuf );
27 baos.write( ret, iRead );
28
29 if( baos.size() < 5 )
30 return null;
31 }
32 } while( !skipReadNulls() );
33
34 if( iVer == 0 )
35 {
36 ByteArrayInputStream bais = new ByteArrayInputStream(
37 baos.toByteArray()
38 );
39 DataInputStream dis( bais );
40 iVer = dis.readUnsignedByte();
41 iSize = dis.readInt();
42 }
43
44 byte aBuf[] = new byte[1500];
45 while( baos.size() < iSize )
46 {
47 int iGoal = iSize-baos.size();
48 if( iGoal > 1500 )
49 iGoal = 1500;
50
51 int iRead = is.read( aBuf );
52 baos.write( abuf, 0, iRead );
53
54 if( iRead < iGoal )
55 return null;
56 }
57
58 if( baos.size() < iSize )
59 return null;
60
61 ByteArrayInputStream bais = new ByteArrayInputStream(
62 baos.toByteArray()
63 );
64 bais.skip( 5 );
65
66 GatsObject goRet = GatsObject::read( bais );
67 iVer = 0;
68
69 return goRet;
70 }
71
72
73 private bool skipReadNulls()
74 {
75 if( baos.size() == 0 )
76 return false;
77
78 byte aBuf[] = baos.toByteArray();
79 if( aBuf[0] != 0 )
80 return true;
81
82 for( int j = 1; j < aBuf.size; j++ )
83 {
84 if( aBuf[j] != 0 )
85 {
86 baos.clear();
87 baos.write( aBuf, j, aBuf.size-j );
88 return true;
89 }
90 }
91
92 baos.clear();
93 return true;
94 }
95};
96
diff --git a/java/com/xagasoft/gats/GatsObject.java b/java/com/xagasoft/gats/GatsObject.java
new file mode 100644
index 0000000..63fcf36
--- /dev/null
+++ b/java/com/xagasoft/gats/GatsObject.java
@@ -0,0 +1,62 @@
1package com.xagasoft.gats;
2
3import java.io.InputStream;
4
5public abstract class GatsObject
6{
7 public final static int INTEGER = 1;
8 public final static int FLOAT = 2;
9 public final static int STRING = 3;
10 public final static int LIST = 4;
11 public final static int DICTIONARY = 5;
12 public final static int BOOLEAN = 6;
13
14 public abstract int getType();
15
16 public abstract void read( InputStream is, char cType );
17
18 public static GatsObject read( InputStream is )
19 {
20 char type = is.read();
21 GatsObject goRet;
22 switch( type )
23 {
24 case 'i':
25 goRet = new Integer();
26 break;
27
28 case 's':
29 goRet = new String();
30 break;
31
32 case '0':
33 case '1':
34 goRet = new Boolean();
35 break;
36
37 case 'l':
38 goRet = new List();
39 break;
40
41 case 'd':
42 goRet = new Dictionary();
43 break;
44
45 case 'f':
46 case 'F':
47 goRet = new Float();
48 break;
49
50 case 'e':
51 return null;
52
53 default:
54 throw new Exception("Invalid gats type discovered: " + (char)type );
55 }
56
57 goRet.read( is, type );
58
59 return goRet;
60 }
61};
62
diff --git a/java/com/xagasoft/gats/GatsOutputStream.java b/java/com/xagasoft/gats/GatsOutputStream.java
new file mode 100644
index 0000000..f3020f4
--- /dev/null
+++ b/java/com/xagasoft/gats/GatsOutputStream.java
@@ -0,0 +1,7 @@
1package com.xagasoft.gats;
2
3public class GatsOutputStream
4{
5 public GatsOutputStream(
6};
7
diff --git a/java/com/xagasoft/gats/GatsStream.java b/java/com/xagasoft/gats/GatsStream.java
deleted file mode 100644
index 0cbd775..0000000
--- a/java/com/xagasoft/gats/GatsStream.java
+++ /dev/null
@@ -1,6 +0,0 @@
1package com.xagasoft.gats;
2
3public class GatsStream
4{
5};
6
diff --git a/java/com/xagasoft/gats/Integer.java b/java/com/xagasoft/gats/Integer.java
index 7da12d4..ab3d6de 100644
--- a/java/com/xagasoft/gats/Integer.java
+++ b/java/com/xagasoft/gats/Integer.java
@@ -3,11 +3,11 @@ package com.xagasoft.gats;
3import java.io.OutputStream; 3import java.io.OutputStream;
4import java.io.InputStream; 4import java.io.InputStream;
5 5
6public class Integer extends Type 6public class Integer extends GatsObject
7{ 7{
8 public int getType() 8 public int getGatsObject()
9 { 9 {
10 return Type.INTEGER; 10 return GatsObject.INTEGER;
11 }; 11 };
12 12
13 /** 13 /**
diff --git a/java/com/xagasoft/gats/List.java b/java/com/xagasoft/gats/List.java
index 99d10e9..dbc729b 100644
--- a/java/com/xagasoft/gats/List.java
+++ b/java/com/xagasoft/gats/List.java
@@ -1,10 +1,10 @@
1package com.xagasoft.gats; 1package com.xagasoft.gats;
2 2
3public class List extends Type 3public class List extends GatsObject
4{ 4{
5 public int getType() 5 public int getGatsObject()
6 { 6 {
7 return Type.LIST; 7 return GatsObject.LIST;
8 } 8 }
9}; 9};
10 10
diff --git a/java/com/xagasoft/gats/String.java b/java/com/xagasoft/gats/String.java
index b89d042..301a98a 100644
--- a/java/com/xagasoft/gats/String.java
+++ b/java/com/xagasoft/gats/String.java
@@ -1,10 +1,10 @@
1package com.xagasoft.gats; 1package com.xagasoft.gats;
2 2
3public class String extends Type 3public class String extends GatsObject
4{ 4{
5 public int getType() 5 public int getGatsObject()
6 { 6 {
7 return Type.STRING; 7 return GatsObject.STRING;
8 } 8 }
9}; 9};
10 10
diff --git a/java/com/xagasoft/gats/Type.java b/java/com/xagasoft/gats/Type.java
deleted file mode 100644
index d6bff4d..0000000
--- a/java/com/xagasoft/gats/Type.java
+++ /dev/null
@@ -1,16 +0,0 @@
1package com.xagasoft.gats;
2
3public abstract class Type
4{
5 public final static int INTEGER = 1;
6 public final static int FLOAT = 2;
7 public final static int STRING = 3;
8 public final static int LIST = 4;
9 public final static int DICTIONARY = 5;
10 public final static int BOOLEAN = 6;
11
12 public abstract int getType();
13
14
15};
16