feb494b31bacb2669b79c7ab7fd57c7e9a6264fc
[redakcja.git] / redakcja / static / filebrowser / uploadify / com / adobe / protocols / dict / util / SocketHelper.as
1 package com.adobe.protocols.dict.util\r
2 {\r
3         import com.adobe.net.proxies.RFC2817Socket;\r
4         import flash.events.ProgressEvent;\r
5 \r
6         public class SocketHelper\r
7                 extends RFC2817Socket\r
8         {\r
9                 private var terminator:String = "\r\n.\r\n";\r
10                 private var buffer:String;\r
11                 public static var COMPLETE_RESPONSE:String = "completeResponse";\r
12 \r
13                 public function SocketHelper()\r
14                 {\r
15                         super();\r
16                         buffer = new String();\r
17                         addEventListener(ProgressEvent.SOCKET_DATA, incomingData);\r
18                 }\r
19 \r
20                 private function incomingData(event:ProgressEvent):void\r
21                 {\r
22                         buffer += readUTFBytes(bytesAvailable);\r
23                         buffer = buffer.replace(/250[^\r\n]+\r\n/, ""); // Get rid of all 250s. Don't need them.\r
24                         var codeStr:String = buffer.substring(0, 3);\r
25                         if (!isNaN(parseInt(codeStr)))\r
26                         {\r
27                                 var code:uint = uint(codeStr);\r
28                                 if (code == 150 || code >= 200)\r
29                                 {\r
30                                         buffer = buffer.replace("\r\n", this.terminator);\r
31                                 }\r
32                         }\r
33 \r
34                         while (buffer.indexOf(this.terminator) != -1)\r
35                         {\r
36                                 var chunk:String = buffer.substring(0, buffer.indexOf(this.terminator));\r
37                                 buffer = buffer.substring(chunk.length + this.terminator.length, buffer.length);\r
38                                 throwResponseEvent(chunk);\r
39                         }\r
40                 }\r
41                 \r
42                 private function throwResponseEvent(response:String):void\r
43                 {\r
44                         var responseEvent:CompleteResponseEvent = new CompleteResponseEvent();\r
45                         responseEvent.response = response;\r
46                         dispatchEvent(responseEvent);                   \r
47                 }\r
48         }\r
49 }