THRIFT-2753 Haxe support: Misc. improvements
Client: Haxe
Patch: Jens Geyer

This closes #229
diff --git a/lib/haxe/README.md b/lib/haxe/README.md
index 3335b43..82525d4 100644
--- a/lib/haxe/README.md
+++ b/lib/haxe/README.md
@@ -32,17 +32,17 @@
 Current status
 ========================
 - tested with Haxe C++ target
-- transports: socket 
-- protocols: binary, JSON
+- transports: Socket, HTTP (client only), Stream
+- protocols: Binary, JSON
 - tutorial client and server available
 - cross-test client and server available 
 
 
 Further developments
 ========================
-- add HTTP transport, update tutorial and tests accordingly
 - improve to work with C#, Java and JavaScript Haxe/OpenFL targets
 - improve to work with more (ideally all) Haxe/OpenFL targets
+- add HTTP server, update tutorial and tests accordingly
 
 
 Dependencies
@@ -53,9 +53,9 @@
 after installing Haxe itself. For example, if you plan to target C#, Java and C++,
 enter the following commands after installing Haxe:
 
-  haxelib install hxcpp
-  haxelib install hxjava
-  haxelib install hxcs
+    haxelib install hxcpp
+    haxelib install hxjava
+    haxelib install hxcs
 
 For other targets, please consult the Haxe documentation whether or not any additional
 target libraries need to be installed and how to achieve this.
diff --git a/lib/haxe/src/org/apache/thrift/protocol/TJSONProtocol.hx b/lib/haxe/src/org/apache/thrift/protocol/TJSONProtocol.hx
index edd5e12..1a93332 100644
--- a/lib/haxe/src/org/apache/thrift/protocol/TJSONProtocol.hx
+++ b/lib/haxe/src/org/apache/thrift/protocol/TJSONProtocol.hx
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements. See the NOTICE file
  * distributed with this work for additional information
@@ -58,6 +58,9 @@
 	// Reader that manages a 1-byte buffer
 	private var reader : LookaheadReader;
 
+	// whether the underlying system holds Strings as UTF-8
+	// http://old.haxe.org/manual/encoding
+	private static var utf8Strings = haxe.Utf8.validate("Ç-ß-Æ-Ю-Ш");
 
 	// TJSONProtocol Constructor
 	public function new( trans : TTransport)
@@ -74,7 +77,7 @@
 	public function writeMessageBegin(message:TMessage) : Void {
 		WriteJSONArrayStart();
 		WriteJSONInteger( JSONConstants.VERSION);
-		WriteJSONString( Utf8Encode(message.name));
+		WriteJSONString( BytesFromString(message.name));
 		WriteJSONInteger( message.type);
 		WriteJSONInteger( message.seqid);
 	}
@@ -94,7 +97,7 @@
 	public function writeFieldBegin(field:TField) : Void {
 		WriteJSONInteger( field.id );
 		WriteJSONObjectStart();
-		WriteJSONString( Utf8Encode( JSONConstants.GetTypeNameForTypeID( field.type)));
+		WriteJSONString( BytesFromString( JSONConstants.GetTypeNameForTypeID( field.type)));
 	}
 
 	public function writeFieldEnd() : Void {
@@ -105,8 +108,8 @@
 
 	public function writeMapBegin(map:TMap) : Void {
 		WriteJSONArrayStart();
-		WriteJSONString( Utf8Encode( JSONConstants.GetTypeNameForTypeID( map.keyType)));
-		WriteJSONString( Utf8Encode( JSONConstants.GetTypeNameForTypeID( map.valueType)));
+		WriteJSONString( BytesFromString( JSONConstants.GetTypeNameForTypeID( map.keyType)));
+		WriteJSONString( BytesFromString( JSONConstants.GetTypeNameForTypeID( map.valueType)));
 		WriteJSONInteger( map.size);
 		WriteJSONObjectStart();
 	}
@@ -118,7 +121,7 @@
 
 	public function writeListBegin(list:TList) : Void {
 		WriteJSONArrayStart();
-		WriteJSONString( Utf8Encode( JSONConstants.GetTypeNameForTypeID( list.elemType )));
+		WriteJSONString( BytesFromString( JSONConstants.GetTypeNameForTypeID( list.elemType )));
 		WriteJSONInteger( list.size);
 	}
 
@@ -128,7 +131,7 @@
 
 	public function writeSetBegin(set:TSet) : Void {
 		WriteJSONArrayStart();
-		WriteJSONString( Utf8Encode( JSONConstants.GetTypeNameForTypeID( set.elemType)));
+		WriteJSONString( BytesFromString( JSONConstants.GetTypeNameForTypeID( set.elemType)));
 		WriteJSONInteger( set.size);
 	}
 
@@ -164,7 +167,7 @@
 	}
 
 	public function writeString(str : String) : Void {
-		WriteJSONString( Utf8Encode(str));
+		WriteJSONString( BytesFromString(str));
 	}
 
 	public function writeBinary(bin:Bytes) : Void {
@@ -180,8 +183,7 @@
 										 "Message contained bad version.");
 		}
 
-        var buf = ReadJSONString(false);
-		message.name = Utf8Decode(buf);
+		message.name = ReadJSONString(false);
 		message.type = ReadJSONInteger();
 		message.seqid = ReadJSONInteger();
 		return message;
@@ -211,7 +213,7 @@
 		{
 			field.id = ReadJSONInteger();
 			ReadJSONObjectStart();
-			field.type = JSONConstants.GetTypeIDForTypeName( Utf8Decode( ReadJSONString(false)));
+			field.type = JSONConstants.GetTypeIDForTypeName( ReadJSONString(false));
 		}
 		return field;
 	}
@@ -222,8 +224,8 @@
 
 	public function readMapBegin() : TMap {
 		ReadJSONArrayStart();
-		var KeyType = JSONConstants.GetTypeIDForTypeName( Utf8Decode( ReadJSONString(false)));
-		var ValueType = JSONConstants.GetTypeIDForTypeName( Utf8Decode( ReadJSONString(false)));
+		var KeyType = JSONConstants.GetTypeIDForTypeName( ReadJSONString(false));
+		var ValueType = JSONConstants.GetTypeIDForTypeName( ReadJSONString(false));
 		var Count : Int = ReadJSONInteger();
 		ReadJSONObjectStart();
 
@@ -238,7 +240,7 @@
 
 	public function readListBegin():TList {
 		ReadJSONArrayStart();
-		var ElementType = JSONConstants.GetTypeIDForTypeName( Utf8Decode( ReadJSONString(false)));
+		var ElementType = JSONConstants.GetTypeIDForTypeName( ReadJSONString(false));
 		var Count : Int = ReadJSONInteger();
 
 		var list = new TList( ElementType, Count);
@@ -251,7 +253,7 @@
 
 	public function readSetBegin() : TSet {
 		ReadJSONArrayStart();
-		var ElementType = JSONConstants.GetTypeIDForTypeName( Utf8Decode( ReadJSONString(false)));
+		var ElementType = JSONConstants.GetTypeIDForTypeName( ReadJSONString(false));
 		var Count : Int = ReadJSONInteger();
 
 		var set = new TSet( ElementType, Count);
@@ -263,7 +265,7 @@
 	}
 
 	public function readBool() : Bool {
-		return (ReadJSONInteger() == 0 ? false : true);
+		return (ReadJSONInteger() != 0);
 	}
 
 	public function readByte() : Int {
@@ -287,8 +289,7 @@
 	}
 
 	public function readString() : String {
-        var buf = ReadJSONString(false);
-		return Utf8Decode(buf);
+        return ReadJSONString(false);
 	}
 
 	public function readBinary() : Bytes {
@@ -402,7 +403,6 @@
 			str += JSONConstants.QUOTE;
 		}
 
-trace('WriteJSONInt64($str)');
 		var tmp = BytesFromString( str);
 		trans.write( tmp, 0, tmp.length);
 	}
@@ -502,7 +502,7 @@
 
 	// Read in a JSON string, unescaping as appropriate.
     // Skip Reading from the context if skipContext is true.
-	private function ReadJSONString(skipContext : Bool) : Bytes
+	private function ReadJSONString(skipContext : Bool) : String
 	{
 		if (!skipContext)
 		{
@@ -560,7 +560,7 @@
 			buffer.addString( String.fromCharCode(charcode));
 		}
 
-		return buffer.getBytes();
+		return StringFromBytes( buffer.getBytes());
 	}
 
 	// Return true if the given byte could be a valid part of a JSON number.
@@ -642,8 +642,6 @@
 			ReadJSONSyntaxChar( JSONConstants.QUOTE);
 		}
 
-trace('ReadJSONInt64() = $str');
-		
 	    // process sign
 		var bMinus = false;
 		var startAt = 0;
@@ -689,7 +687,7 @@
 		
 		var str : String = "";
 		if (StringFromBytes(reader.Peek()) == JSONConstants.QUOTE) {
-			str = StringFromBytes( ReadJSONString(true));
+			str = ReadJSONString(true);
 			
 			// special cases
 			if( str == JSONConstants.FLOAT_IS_NAN) {
@@ -729,7 +727,7 @@
 	// Read in a JSON string containing base-64 encoded data and decode it.
 	private function ReadJSONBase64() : Bytes
 	{
-		var str = StringFromBytes( ReadJSONString(false));
+		var str = ReadJSONString(false);
 		return Base64.decode( str);
 	}
 
@@ -758,21 +756,22 @@
 
 	public static function BytesFromString( str : String) : Bytes {
 		var buf = new BytesBuffer();
-		buf.addString( str);
+		if( utf8Strings)
+			buf.addString( str);  // no need to encode on UTF8 targets, the string is just fine
+		else
+			buf.addString( Utf8.encode( str));
 		return buf.getBytes();
 	}
 
 	public static function StringFromBytes( buf : Bytes) : String {
 		var inp = new BytesInput( buf);
-		return inp.readString( buf.length);
-	}
-
-	public static function Utf8Encode(str : String) : Bytes {
-		return BytesFromString( Utf8.encode( str));
-	}
-
-	public static function Utf8Decode( buf : Bytes) : String {
-		return Utf8.decode( StringFromBytes( buf));
+		if( buf.length == 0)
+			return "";  // readString() would return null in that case, which is wrong
+		var str = inp.readString( buf.length);
+		if( utf8Strings)
+			return str;  // no need to decode on UTF8 targets, the string is just fine
+		else
+			return Utf8.decode( str);
 	}
 
 	// Convert a byte containing a hex char ('0'-'9' or 'a'-'f') into its corresponding hex value
diff --git a/lib/haxe/src/org/apache/thrift/server/TServer.hx b/lib/haxe/src/org/apache/thrift/server/TServer.hx
index 9b235f69..37105bd 100644
--- a/lib/haxe/src/org/apache/thrift/server/TServer.hx
+++ b/lib/haxe/src/org/apache/thrift/server/TServer.hx
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements. See the NOTICE file
  * distributed with this work for additional information
diff --git a/lib/haxe/src/org/apache/thrift/server/TServerEventHandler.hx b/lib/haxe/src/org/apache/thrift/server/TServerEventHandler.hx
index 08f48b2..83bff95 100644
--- a/lib/haxe/src/org/apache/thrift/server/TServerEventHandler.hx
+++ b/lib/haxe/src/org/apache/thrift/server/TServerEventHandler.hx
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements. See the NOTICE file
  * distributed with this work for additional information
diff --git a/lib/haxe/src/org/apache/thrift/server/TSimpleServer.hx b/lib/haxe/src/org/apache/thrift/server/TSimpleServer.hx
index 20a7195..c516b78 100644
--- a/lib/haxe/src/org/apache/thrift/server/TSimpleServer.hx
+++ b/lib/haxe/src/org/apache/thrift/server/TSimpleServer.hx
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements. See the NOTICE file
  * distributed with this work for additional information
diff --git a/lib/haxe/src/org/apache/thrift/transport/TFileStream.hx b/lib/haxe/src/org/apache/thrift/transport/TFileStream.hx
new file mode 100644
index 0000000..03e031f
--- /dev/null
+++ b/lib/haxe/src/org/apache/thrift/transport/TFileStream.hx
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.thrift.transport;
+
+import haxe.io.Bytes;
+import haxe.io.BytesBuffer;
+import haxe.io.Input;
+import haxe.io.Output;
+
+
+enum TFileMode {
+	CreateNew;
+	Append;
+	Read;
+}
+	
+
+class TFileStream implements TStream {
+
+	public var FileName(default,null) : String;
+	
+	private var Input  : sys.io.FileInput;
+	private var Output : sys.io.FileOutput;
+	
+	
+	public function new( fname : String, mode : TFileMode) {
+		FileName = fname;	
+		switch ( mode)
+		{
+			case TFileMode.CreateNew:
+				Output = sys.io.File.write( fname, true);
+
+			case TFileMode.Append:
+				Output = sys.io.File.append( fname, true);
+
+			case TFileMode.Read:
+				Input = sys.io.File.read( fname, true);
+
+			default:
+				throw new TTransportException( TTransportException.UNKNOWN,
+											   "Unsupported mode");
+		}
+
+	}
+	
+	public function Close() : Void {
+		if( Input != null) {
+			Input.close();
+			Input = null;
+		}
+		if( Output != null) { 
+			Output.close();
+			Output = null;
+		}
+	}
+	
+	public function Peek() : Bool {
+		if( Input == null)
+			throw new TTransportException( TTransportException.NOT_OPEN, "File not open for input");
+
+		return (! Input.eof());
+	}
+	
+	public function Read( buf : Bytes, offset : Int, count : Int) : Int {
+		if( Input == null)
+			throw new TTransportException( TTransportException.NOT_OPEN, "File not open for input");
+
+		return Input.readBytes( buf, offset, count);
+	}
+	
+	public function Write( buf : Bytes, offset : Int, count : Int) : Void {
+		if( Output == null)
+			throw new TTransportException( TTransportException.NOT_OPEN, "File not open for output");
+		
+		Output.writeBytes( buf, offset, count);			
+	}
+
+	public function Flush() : Void {
+		if( Output != null) 
+			Output.flush();
+	}
+	
+}
diff --git a/lib/haxe/src/org/apache/thrift/transport/TFramedTransport.hx b/lib/haxe/src/org/apache/thrift/transport/TFramedTransport.hx
index 5d77140..77335e7 100644
--- a/lib/haxe/src/org/apache/thrift/transport/TFramedTransport.hx
+++ b/lib/haxe/src/org/apache/thrift/transport/TFramedTransport.hx
@@ -7,7 +7,7 @@
  * "License"); you may not use this file except in compliance
  * with the License. You may obtain a copy of the License at
  *
- *   http : //www.apache.org/licenses/LICENSE-2.0
+ *   http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
diff --git a/lib/haxe/src/org/apache/thrift/transport/TFramedTransportFactory.hx b/lib/haxe/src/org/apache/thrift/transport/TFramedTransportFactory.hx
index 00127bf..3cca1f8 100644
--- a/lib/haxe/src/org/apache/thrift/transport/TFramedTransportFactory.hx
+++ b/lib/haxe/src/org/apache/thrift/transport/TFramedTransportFactory.hx
@@ -7,7 +7,7 @@
  * "License"); you may not use this file except in compliance
  * with the License. You may obtain a copy of the License at
  *
- *   http : //www.apache.org/licenses/LICENSE-2.0
+ *   http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
diff --git a/lib/haxe/src/org/apache/thrift/transport/THttpClient.hx b/lib/haxe/src/org/apache/thrift/transport/THttpClient.hx
index d2fda79..52a9d26 100644
--- a/lib/haxe/src/org/apache/thrift/transport/THttpClient.hx
+++ b/lib/haxe/src/org/apache/thrift/transport/THttpClient.hx
@@ -25,30 +25,7 @@
 import haxe.io.BytesOutput;
 import haxe.io.BytesInput;
 
-#if openfl
-// OpenFL all targets
-import openfl.errors.EOFError;
-import openfl.events.Event;
-import openfl.events.IOErrorEvent;
-import openfl.events.SecurityErrorEvent;
-import openfl.net.URLLoader;
-import openfl.net.URLLoaderDataFormat;
-import openfl.net.URLRequest;
-import openfl.net.URLRequestMethod;
-#elseif flash  
-// Haxe flash, no OpenFL
-import flash.errors.EOFError;
-import flash.events.Event;
-import flash.events.IOErrorEvent;
-import flash.events.SecurityErrorEvent;
-import flash.net.URLLoader;
-import flash.net.URLLoaderDataFormat;
-import flash.net.URLRequest;
-import flash.net.URLRequestMethod;
-#else
-// bare Haxe 
 import haxe.Http;
-#end
 
 
 	
@@ -62,29 +39,15 @@
     private var requestBuffer_  : BytesOutput = new BytesOutput();
     private var responseBuffer_ : BytesInput = null;
 
-	#if (flash || openfl)
-	private var request_        : URLRequest = null;
-    #else
 	private var request_        : Http = null;
-    #end
 
     
-	#if (flash || openfl)
-
-	public function new( request : URLRequest) : Void {
-		request.contentType = "application/x-thrift";
-		request_ = request;
-    }
-	
-	#else
-
 	public function new( requestUrl : String) : Void {
 	  	request_ = new Http(requestUrl);
 		request_.addHeader( "contentType", "application/x-thrift");
     }
     
-	#end
-    
+   
     public override function open() : Void {
     }
 
@@ -100,24 +63,10 @@
         	throw new TTransportException(TTransportException.UNKNOWN, "Response buffer is empty, no request.");
 		}
 		
-		#if flash
-        try {
-			var data = Bytes.alloc(len);
-            responseBuffer_.readBytes(data, off, len);
-            buf.addBytes(data,0,len);
-			return len;
-        } catch (e : EOFError) {
-            throw new TTransportException(TTransportException.UNKNOWN, "No more data available.");
-        }
-			
-		#else
-			
         var data =Bytes.alloc(len);
 		len = responseBuffer_.readBytes(data, off, len);
 		buf.addBytes(data,0,len);
 		return len;
-		
-		#end
     }
 
     public override function write(buf:Bytes, off : Int, len : Int) : Void {
@@ -125,59 +74,30 @@
     }
 
 	
-	#if (flash || openfl)
-		
-    public override function flush(callback:Error->Void = null) : Void {
-		var loader : URLLoader = new URLLoader();
-		
-		if (callback != null) {
-			loader.addEventListener(Event.COMPLETE, function(event:Event) : Void {
-				responseBuffer_ = new URLLoader(event.target).data;
-				callback(null);
-			});
-			loader.addEventListener(IOErrorEvent.IO_ERROR, function(event:IOErrorEvent) : Void {
-				callback(new TTransportException(TTransportException.UNKNOWN, "IOError: " + event.text));
-				responseBuffer_ = null;
-			});
-			loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, function(event:SecurityErrorEvent) : Void {
-				callback(new TTransportException(TTransportException.UNKNOWN, "SecurityError: " + event.text));
-				responseBuffer_ = null;
-			});
-		}
-			
-		request_.method = URLRequestMethod.POST;
-		loader.dataFormat = URLLoaderDataFormat.BINARY;
-		//requestBuffer_.position = 0;
-		request_.data = requestBuffer_;
-		loader.load(request_);
-    }
-
-	#else 
-		
     public override function flush(callback:Dynamic->Void = null) : Void {
-		
 		var buffer = requestBuffer_;
 		requestBuffer_ = new BytesOutput();
 		responseBuffer_ = null;
 			
 		request_.onData = function(data : String) { 
-			responseBuffer_ = new BytesInput(buffer.getBytes());
-			callback(null);
-		};
-		request_.onError = function(msg : String) {
-			callback(new TTransportException(TTransportException.UNKNOWN, "IOError: " + msg));
+			var tmp = new BytesBuffer();
+			tmp.addString(data);
+			responseBuffer_ = new BytesInput(tmp.getBytes());
+			if( callback != null) {
+				callback(null);
+			}
 		};
 		
-		#if js
+		request_.onError = function(msg : String) {
+			if( callback != null) {
+				callback(new TTransportException(TTransportException.UNKNOWN, "IOError: " + msg));
+			}
+		};
+		
 		request_.setPostData(buffer.getBytes().toString());
 		request_.request(true/*POST*/);
-		#else
-		request_.customRequest( true/*POST*/, buffer);
-		#end
     }
 		
-	#end
-
 }
 
 	
\ No newline at end of file
diff --git a/lib/haxe/src/org/apache/thrift/transport/TServerSocket.hx b/lib/haxe/src/org/apache/thrift/transport/TServerSocket.hx
index 1953244..0eae931 100644
--- a/lib/haxe/src/org/apache/thrift/transport/TServerSocket.hx
+++ b/lib/haxe/src/org/apache/thrift/transport/TServerSocket.hx
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements. See the NOTICE file
  * distributed with this work for additional information
diff --git a/lib/haxe/src/org/apache/thrift/transport/TServerTransport.hx b/lib/haxe/src/org/apache/thrift/transport/TServerTransport.hx
index e0ce697..5819803 100644
--- a/lib/haxe/src/org/apache/thrift/transport/TServerTransport.hx
+++ b/lib/haxe/src/org/apache/thrift/transport/TServerTransport.hx
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements. See the NOTICE file
  * distributed with this work for additional information
diff --git a/lib/haxe/src/org/apache/thrift/transport/TStream.hx b/lib/haxe/src/org/apache/thrift/transport/TStream.hx
new file mode 100644
index 0000000..0e1b52d
--- /dev/null
+++ b/lib/haxe/src/org/apache/thrift/transport/TStream.hx
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.thrift.transport;
+
+import haxe.io.Bytes;
+import haxe.io.BytesBuffer;
+
+
+interface TStream {
+	function Close() : Void;
+	function Peek() : Bool;
+	function Read( buf : Bytes, offset : Int, count : Int) : Int;
+	function Write( buf : Bytes, offset : Int, count : Int) : Void;
+	function Flush() : Void;
+}
diff --git a/lib/haxe/src/org/apache/thrift/transport/TStreamTransport.hx b/lib/haxe/src/org/apache/thrift/transport/TStreamTransport.hx
new file mode 100644
index 0000000..99203b4
--- /dev/null
+++ b/lib/haxe/src/org/apache/thrift/transport/TStreamTransport.hx
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.thrift.transport;
+
+import org.apache.thrift.transport.*;
+import org.apache.thrift.helper.*;
+
+import haxe.io.Bytes;
+import haxe.io.BytesBuffer;
+import haxe.io.BytesOutput;
+import haxe.io.BytesInput;
+
+
+class TStreamTransport extends TTransport {
+	
+	public var InputStream(default,null) : TStream;
+	public var OutputStream(default,null) : TStream;
+
+
+	public function new( input : TStream, output : TStream) {
+		this.InputStream = input;
+		this.OutputStream = output;
+	}
+	
+	public override function isOpen() : Bool {
+		return true;
+	}
+	
+    public override function peek() : Bool {
+		return (InputStream != null);
+	}
+
+    public override function open() : Void {
+	}
+
+	public override function close() : Void {
+		if (InputStream != null)
+		{
+			InputStream.Close();
+			InputStream = null;
+		}
+		if (OutputStream != null)
+		{
+			OutputStream.Close();
+			OutputStream = null;
+		}
+	}
+
+	public override function read( buf : BytesBuffer, off : Int, len : Int) : Int {
+		if (InputStream == null)
+		{
+			throw new TTransportException( TTransportException.NOT_OPEN, 
+								  		   "Cannot read from null InputStream");
+		}
+
+		var data : Bytes =  Bytes.alloc(len);
+		var size = InputStream.Read( data, off, len);
+		buf.addBytes( data, 0, size);
+		return size;
+	}
+
+    public override function write(buf:Bytes, off : Int, len : Int) : Void {
+		if (OutputStream == null)
+		{
+			throw new TTransportException( TTransportException.NOT_OPEN, 
+										   "Cannot write to null OutputStream");
+		}
+
+		OutputStream.Write(buf, off, len);
+	}
+
+    public override function flush(callback:Dynamic->Void =null) : Void {
+		if (OutputStream == null)
+		{
+			var err = new TTransportException( TTransportException.NOT_OPEN,
+											   "Cannot flush null OutputStream");
+	    	if(callback != null)
+				callback(err);
+			else
+				throw err;
+		}
+
+		OutputStream.Flush();
+	}
+
+}
diff --git a/lib/haxe/test/Makefile.am b/lib/haxe/test/Makefile.am
new file mode 100644
index 0000000..5e92f98
--- /dev/null
+++ b/lib/haxe/test/Makefile.am
@@ -0,0 +1,50 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+THRIFT = $(top_srcdir)/compiler/cpp/thrift
+THRIFTCMD = $(THRIFT) --gen haxe -r
+THRIFTTEST = $(top_srcdir)/test/ThriftTest.thrift
+
+BIN_CPP = bin/Main-debug
+
+gen-haxe/thrift/test/ThriftTest.hx: $(THRIFTTEST)
+	$(THRIFTCMD) $(THRIFTTEST)
+
+all-local: $(BIN_CPP)
+
+$(BIN_CPP):    gen-haxe/thrift/test/ThriftTest.hx
+	$(HAXE) --cwd .  cpp.hxml
+
+
+#TODO: other haxe targets
+#    $(HAXE)  --cwd .  csharp
+#    $(HAXE)  --cwd .  flash
+#    $(HAXE)  --cwd .  java
+#    $(HAXE)  --cwd .  javascript
+#    $(HAXE)  --cwd .  neko
+#    $(HAXE)  --cwd .  php
+#    $(HAXE)  --cwd .  python  # needs Haxe 3.1.4
+
+
+clean-local:
+	$(RM) -r gen-haxe bin
+
+check: $(BIN_CPP)
+	$(BIN_CPP)
+
diff --git a/lib/haxe/test/cpp.hxml b/lib/haxe/test/cpp.hxml
new file mode 100644
index 0000000..73848a8
--- /dev/null
+++ b/lib/haxe/test/cpp.hxml
@@ -0,0 +1,41 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+ 
+#integrate files to classpath
+-cp src
+-cp ../src
+-cp gen-haxe
+
+#this class wil be used as entry point for your app.
+-main Main
+
+#CPP target
+-cpp bin
+
+#To produce 64 bit binaries the file should define the HXCPP_M64 compile variable:
+#-D HXCPP_M64
+
+#Add debug information
+-debug
+
+#dead code elimination : remove unused code
+#"-dce no" : do not remove unused code
+#"-dce std" : remove unused code in the std lib (default)
+#"-dce full" : remove all unused code
+-dce full
\ No newline at end of file
diff --git a/lib/haxe/test/csharp.hxml b/lib/haxe/test/csharp.hxml
new file mode 100644
index 0000000..4c34b0d
--- /dev/null
+++ b/lib/haxe/test/csharp.hxml
@@ -0,0 +1,38 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+ 
+#integrate files to classpath
+-cp src
+-cp ../src
+-cp gen-haxe
+
+#this class wil be used as entry point for your app.
+-main Main
+
+#CSHARP target
+-cs bin/Test.exe
+
+#Add debug information
+-debug
+
+#dead code elimination : remove unused code
+#"-dce no" : do not remove unused code
+#"-dce std" : remove unused code in the std lib (default)
+#"-dce full" : remove all unused code
+-dce full
\ No newline at end of file
diff --git a/lib/haxe/test/flash.hxml b/lib/haxe/test/flash.hxml
new file mode 100644
index 0000000..8b17631
--- /dev/null
+++ b/lib/haxe/test/flash.hxml
@@ -0,0 +1,38 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+ 
+#integrate files to classpath
+-cp src
+-cp ../src
+-cp gen-haxe
+
+#this class wil be used as entry point for your app.
+-main Main
+
+#Flash target
+-swf bin/Test.swf
+
+#Add debug information
+-debug
+
+#dead code elimination : remove unused code
+#"-dce no" : do not remove unused code
+#"-dce std" : remove unused code in the std lib (default)
+#"-dce full" : remove all unused code
+-dce full
\ No newline at end of file
diff --git a/lib/haxe/test/java.hxml b/lib/haxe/test/java.hxml
new file mode 100644
index 0000000..c947159
--- /dev/null
+++ b/lib/haxe/test/java.hxml
@@ -0,0 +1,38 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+ 
+#integrate files to classpath
+-cp src
+-cp ../src
+-cp gen-haxe
+
+#this class wil be used as entry point for your app.
+-main Main
+
+#Java target
+-java bin/Test.jar
+
+#Add debug information
+-debug
+
+#dead code elimination : remove unused code
+#"-dce no" : do not remove unused code
+#"-dce std" : remove unused code in the std lib (default)
+#"-dce full" : remove all unused code
+-dce full
\ No newline at end of file
diff --git a/lib/haxe/test/javascript.hxml b/lib/haxe/test/javascript.hxml
new file mode 100644
index 0000000..18d9964
--- /dev/null
+++ b/lib/haxe/test/javascript.hxml
@@ -0,0 +1,44 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+ 
+#integrate files to classpath
+-cp src
+-cp ../src
+-cp gen-haxe
+
+#this class wil be used as entry point for your app.
+-main Main
+
+#JavaScript target
+-js bin/Test.js
+
+#You can use -D source-map-content (requires Haxe 3.1+) to have the .hx 
+#files directly embedded into the map file, this way you only have to 
+#upload it, and it will be always in sync with the compiled .js even if 
+#you modify your .hx files.
+-D source-map-content
+
+#Generate source map and add debug information
+-debug
+
+#dead code elimination : remove unused code
+#"-dce no" : do not remove unused code
+#"-dce std" : remove unused code in the std lib (default)
+#"-dce full" : remove all unused code
+-dce full
\ No newline at end of file
diff --git a/lib/haxe/test/make_all.bat b/lib/haxe/test/make_all.bat
new file mode 100644
index 0000000..ee18f10
--- /dev/null
+++ b/lib/haxe/test/make_all.bat
@@ -0,0 +1,68 @@
+@echo off
+rem /*
+rem  * Licensed to the Apache Software Foundation (ASF) under one
+rem  * or more contributor license agreements. See the NOTICE file
+rem  * distributed with this work for additional information
+rem  * regarding copyright ownership. The ASF licenses this file
+rem  * to you under the Apache License, Version 2.0 (the
+rem  * "License"); you may not use this file except in compliance
+rem  * with the License. You may obtain a copy of the License at
+rem  *
+rem  *   http://www.apache.org/licenses/LICENSE-2.0
+rem  *
+rem  * Unless required by applicable law or agreed to in writing,
+rem  * software distributed under the License is distributed on an
+rem  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+rem  * KIND, either express or implied. See the License for the
+rem  * specific language governing permissions and limitations
+rem  * under the License.
+rem  */
+
+setlocal
+if "%HOMEDRIVE%"=="" goto MISSINGVARS
+if "%HOMEPATH%"=="" goto MISSINGVARS
+if "%HAXEPATH%"=="" goto NOTINSTALLED
+
+set path=%HAXEPATH%;%HAXEPATH%\..\neko;%path%
+
+rem # invoke Thrift comnpiler
+thrift -r -gen haxe   ..\..\..\test\ThriftTest.thrift
+if errorlevel 1 goto STOP
+
+rem # invoke Haxe compiler for all targets
+for %%a in (*.hxml) do (
+	rem * filter Python, as it is not supported by Haxe 3.1.3 (but will be in 3.1.4)
+	if not "%%a"=="python.hxml" (
+		echo --------------------------
+		echo Building %%a ...
+		echo --------------------------
+		haxe  --cwd .  %%a
+	)
+)
+
+
+echo.
+echo done.
+pause
+goto eof
+
+:NOTINSTALLED
+echo FATAL: Either Haxe is not installed, or the HAXEPATH variable is not set.
+pause
+goto eof
+
+:MISSINGVARS
+echo FATAL: Unable to locate home folder.
+echo.
+echo Both HOMEDRIVE and HOMEPATH need to be set to point to your Home folder.
+echo The current values are:
+echo HOMEDRIVE=%HOMEDRIVE%
+echo HOMEPATH=%HOMEPATH%
+pause
+goto eof
+
+:STOP
+pause
+goto eof
+
+:eof
diff --git a/lib/haxe/test/make_all.sh b/lib/haxe/test/make_all.sh
new file mode 100644
index 0000000..13b5754
--- /dev/null
+++ b/lib/haxe/test/make_all.sh
@@ -0,0 +1,41 @@
+#!/bin/sh
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# invoke Thrift comnpiler
+thrift -r -gen haxe  ../../../test/ThriftTest.thrift
+
+# output folder
+if [ ! -d bin ]; then
+  mkdir  bin
+fi
+
+# invoke Haxe compiler
+for target in *.hxml; do 
+  echo --------------------------
+  echo Building ${target} ...
+  echo --------------------------
+  if [ ! -d bin/${target} ]; then
+    mkdir  bin/${target}
+  fi
+  haxe  --cwd .  ${target} 
+done
+
+
+#eof
diff --git a/lib/haxe/test/neko.hxml b/lib/haxe/test/neko.hxml
new file mode 100644
index 0000000..2db70c8
--- /dev/null
+++ b/lib/haxe/test/neko.hxml
@@ -0,0 +1,38 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+ 
+#integrate files to classpath
+-cp src
+-cp ../src
+-cp gen-haxe
+
+#this class wil be used as entry point for your app.
+-main Main
+
+#neko target
+-neko bin/Test.n
+
+#Add debug information
+-debug
+
+#dead code elimination : remove unused code
+#"-dce no" : do not remove unused code
+#"-dce std" : remove unused code in the std lib (default)
+#"-dce full" : remove all unused code
+-dce full
\ No newline at end of file
diff --git a/lib/haxe/test/php.hxml b/lib/haxe/test/php.hxml
new file mode 100644
index 0000000..b86e64c
--- /dev/null
+++ b/lib/haxe/test/php.hxml
@@ -0,0 +1,38 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+ 
+#integrate files to classpath
+-cp src
+-cp ../src
+-cp gen-haxe
+
+#this class wil be used as entry point for your app.
+-main Main
+
+#PHP target
+-php bin/Test.php
+
+#Add debug information
+-debug
+
+#dead code elimination : remove unused code
+#"-dce no" : do not remove unused code
+#"-dce std" : remove unused code in the std lib (default)
+#"-dce full" : remove all unused code
+-dce full
\ No newline at end of file
diff --git a/lib/haxe/test/project.hide b/lib/haxe/test/project.hide
new file mode 100644
index 0000000..16ef98e
--- /dev/null
+++ b/lib/haxe/test/project.hide
@@ -0,0 +1,67 @@
+{
+     "type" : 0
+    ,"target" : 4
+    ,"name" : "Test"
+    ,"main" : null
+    ,"projectPackage" : ""
+    ,"company" : ""
+    ,"license" : ""
+    ,"url" : ""
+    ,"targetData" : [
+         {
+             "pathToHxml" : "flash.hxml"
+            ,"runActionType" : 1
+            ,"runActionText" : "bin/Test.swf"
+        }
+        ,{
+             "pathToHxml" : "javascript.hxml"
+            ,"runActionType" : 1
+            ,"runActionText" : "bin\\index.html"
+        }
+        ,{
+             "pathToHxml" : "neko.hxml"
+            ,"runActionType" : 2
+            ,"runActionText" : "neko bin/Test.n"
+        }
+        ,{
+             "pathToHxml" : "php.hxml"
+        }
+        ,{
+             "pathToHxml" : "cpp.hxml"
+            ,"runActionType" : 2
+            ,"runActionText" : "bin/Main-debug.exe"
+        }
+        ,{
+             "pathToHxml" : "java.hxml"
+        }
+        ,{
+             "pathToHxml" : "csharp.hxml"
+        }
+        ,{
+             "pathToHxml" : "python.hxml"
+            ,"runActionType" : 2
+            ,"runActionText" : "python bin/Test.py"
+        }
+    ]
+    ,"files" : [
+         {
+             "path" : "src\\Main.hx"
+            ,"useTabs" : true
+            ,"indentSize" : 4
+            ,"foldedRegions" : [
+
+            ]
+            ,"activeLine" : 13
+        }
+    ]
+    ,"activeFile" : "src\\Main.hx"
+    ,"openFLTarget" : null
+    ,"openFLBuildMode" : "Debug"
+    ,"runActionType" : null
+    ,"runActionText" : null
+    ,"buildActionCommand" : null
+    ,"hiddenItems" : [
+
+    ]
+    ,"showHiddenItems" : false
+}
\ No newline at end of file
diff --git a/lib/haxe/test/python.hxml b/lib/haxe/test/python.hxml
new file mode 100644
index 0000000..4d6a133
--- /dev/null
+++ b/lib/haxe/test/python.hxml
@@ -0,0 +1,38 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+ 
+#integrate files to classpath
+-cp src
+-cp ../src
+-cp gen-haxe
+
+#this class wil be used as entry point for your app.
+-main Main
+
+#Python target
+-python bin/Test.py
+
+#Add debug information
+-debug
+
+#dead code elimination : remove unused code
+#"-dce no" : do not remove unused code
+#"-dce std" : remove unused code in the std lib (default)
+#"-dce full" : remove all unused code
+-dce full
\ No newline at end of file
diff --git a/lib/haxe/test/src/Main.hx b/lib/haxe/test/src/Main.hx
new file mode 100644
index 0000000..fff8be5
--- /dev/null
+++ b/lib/haxe/test/src/Main.hx
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package;
+
+import org.apache.thrift.*;
+import org.apache.thrift.protocol.*;
+import org.apache.thrift.transport.*;
+import org.apache.thrift.server.*;
+import org.apache.thrift.meta_data.*;
+
+import thrift.test.*;  // generated code
+
+class Main
+{
+    static public function main()
+    {
+		try
+		{
+        	StreamTest.Run();
+			
+			trace("All tests completed.");
+		}
+		catch( e: Dynamic)
+		{
+			trace('$e');
+		}
+	}
+}
\ No newline at end of file
diff --git a/lib/haxe/test/src/StreamTest.hx b/lib/haxe/test/src/StreamTest.hx
new file mode 100644
index 0000000..b28c8e9
--- /dev/null
+++ b/lib/haxe/test/src/StreamTest.hx
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package;
+
+import haxe.Int64;
+
+import org.apache.thrift.*;
+import org.apache.thrift.protocol.*;
+import org.apache.thrift.transport.*;
+import org.apache.thrift.server.*;
+import org.apache.thrift.meta_data.*;
+
+import thrift.test.*;  // generated code
+
+
+class StreamTest extends TestBase {
+	
+
+	private inline static var tmpfile : String = "bin/data.tmp";
+	
+
+	private static function Expect( expr : Bool, info : String, ?pos : haxe.PosInfos) : Void {
+		if( ! expr) {
+			throw ('Test "$info" failed at '+pos.methodName+' in '+pos.fileName+':'+pos.lineNumber);
+		}			
+	}
+	
+	private static function MakeTestData() : Xtruct {
+		var data : Xtruct = new Xtruct();
+		data.string_thing = "Streamtest";
+		data.byte_thing = -128;
+		data.i32_thing = 4711;
+		data.i64_thing = Int64.make(0x12345678,0x9ABCDEF0);
+		return data;
+	}
+	
+	public static function WriteData() : Xtruct
+	{
+		var stream : TStream = new TFileStream( tmpfile, CreateNew);
+		var trans : TTransport = new TStreamTransport( null, stream);
+		var prot = new TJSONProtocol( trans);
+
+		var data = MakeTestData();	
+		data.write(prot);
+		trans.close();
+		
+		return data;
+	}
+	
+	public static function ReadData() : Xtruct
+	{
+		var stream : TStream = new TFileStream( tmpfile, Read);
+		var trans : TTransport = new TStreamTransport( stream, null);
+		var prot = new TJSONProtocol( trans);
+
+		var data : Xtruct = new Xtruct();
+		data.read(prot);
+		trans.close();
+		
+		return data;
+	}
+	
+	public static override function Run() : Void
+	{
+		var written = WriteData();
+		var read = ReadData();
+
+		Expect( read.string_thing == written.string_thing, "string data");
+		Expect( read.byte_thing == written.byte_thing, "byte data");
+		Expect( read.i32_thing == written.i32_thing, "i32 data");
+		Expect( Int64.compare( read.i64_thing, written.i64_thing) == 0, "i64 data");
+	}
+
+}
+
+
diff --git a/lib/haxe/test/src/TestBase.hx b/lib/haxe/test/src/TestBase.hx
new file mode 100644
index 0000000..03b66dd
--- /dev/null
+++ b/lib/haxe/test/src/TestBase.hx
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package;
+
+import org.apache.thrift.*;
+import org.apache.thrift.protocol.*;
+import org.apache.thrift.transport.*;
+import org.apache.thrift.server.*;
+import org.apache.thrift.meta_data.*;
+
+import thrift.test.*;  // generated code
+
+class TestBase {
+	
+	private function new() {
+		// override, if necessary
+	}
+	
+	public static function Run() : Void {
+      	throw new AbstractMethodError();
+	}	
+}