mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-21 09:37:50 -05:00
Brought up to date with the private repository (feea4c7)
This commit is contained in:
1 parent
1aa738d692
commit
1b1df1ae48
7925 files changed
+2617237
-20
No files matched your search
@@ -0,0 +1,97 @@
|
||||
package com.hurlant.util
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class Base64
|
||||
{
|
||||
|
||||
private static const BASE64_CHARS:String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
||||
|
||||
public static const version:String = "1.0.0";
|
||||
|
||||
public function Base64()
|
||||
{
|
||||
super();
|
||||
throw new Error("Base64 class is static container only");
|
||||
}
|
||||
|
||||
public static function encode(data:String) : String
|
||||
{
|
||||
var bytes:ByteArray = new ByteArray();
|
||||
bytes.writeUTFBytes(data);
|
||||
return encodeByteArray(bytes);
|
||||
}
|
||||
|
||||
public static function encodeByteArray(data:ByteArray) : String
|
||||
{
|
||||
var dataBuffer:Array = null;
|
||||
var i:uint = 0;
|
||||
var j:uint = 0;
|
||||
var k:uint = 0;
|
||||
var output:String = "";
|
||||
var outputBuffer:Array = new Array(4);
|
||||
data.position = 0;
|
||||
while(data.bytesAvailable > 0)
|
||||
{
|
||||
dataBuffer = new Array();
|
||||
i = 0;
|
||||
while(i < 3 && data.bytesAvailable > 0)
|
||||
{
|
||||
dataBuffer[i] = data.readUnsignedByte();
|
||||
i++;
|
||||
}
|
||||
outputBuffer[0] = (dataBuffer[0] & 0xFC) >> 2;
|
||||
outputBuffer[1] = (dataBuffer[0] & 3) << 4 | dataBuffer[1] >> 4;
|
||||
outputBuffer[2] = (dataBuffer[1] & 0x0F) << 2 | dataBuffer[2] >> 6;
|
||||
outputBuffer[3] = dataBuffer[2] & 0x3F;
|
||||
for(j = dataBuffer.length; j < 3; j++)
|
||||
{
|
||||
outputBuffer[j + 1] = 64;
|
||||
}
|
||||
for(k = 0; k < outputBuffer.length; k++)
|
||||
{
|
||||
output += BASE64_CHARS.charAt(outputBuffer[k]);
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
public static function decode(data:String) : String
|
||||
{
|
||||
var bytes:ByteArray = decodeToByteArray(data);
|
||||
return bytes.readUTFBytes(bytes.length);
|
||||
}
|
||||
|
||||
public static function decodeToByteArray(data:String) : ByteArray
|
||||
{
|
||||
var j:uint = 0;
|
||||
var k:uint = 0;
|
||||
var output:ByteArray = new ByteArray();
|
||||
var dataBuffer:Array = new Array(4);
|
||||
var outputBuffer:Array = new Array(3);
|
||||
for(var i:uint = 0; i < data.length; i += 4)
|
||||
{
|
||||
j = 0;
|
||||
while(j < 4 && i + j < data.length)
|
||||
{
|
||||
dataBuffer[j] = BASE64_CHARS.indexOf(data.charAt(i + j));
|
||||
j++;
|
||||
}
|
||||
outputBuffer[0] = (dataBuffer[0] << 2) + ((dataBuffer[1] & 0x30) >> 4);
|
||||
outputBuffer[1] = ((dataBuffer[1] & 0x0F) << 4) + ((dataBuffer[2] & 0x3C) >> 2);
|
||||
outputBuffer[2] = ((dataBuffer[2] & 3) << 6) + dataBuffer[3];
|
||||
for(k = 0; k < outputBuffer.length; k++)
|
||||
{
|
||||
if(dataBuffer[k + 1] == 64)
|
||||
{
|
||||
break;
|
||||
}
|
||||
output.writeByte(outputBuffer[k]);
|
||||
}
|
||||
}
|
||||
output.position = 0;
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.hurlant.util
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class Hex
|
||||
{
|
||||
|
||||
public function Hex()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function toArray(hex:String) : ByteArray
|
||||
{
|
||||
hex = hex.replace(/\s|:/gm,"");
|
||||
var a:ByteArray = new ByteArray();
|
||||
if(Boolean(hex.length & 1 == 1))
|
||||
{
|
||||
hex = "0" + hex;
|
||||
}
|
||||
for(var i:uint = 0; i < hex.length; i += 2)
|
||||
{
|
||||
a[i / 2] = parseInt(hex.substr(i,2),16);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
public static function fromArray(array:ByteArray, colons:Boolean = false) : String
|
||||
{
|
||||
var s:String = "";
|
||||
for(var i:uint = 0; i < array.length; i++)
|
||||
{
|
||||
s += ("0" + array[i].toString(16)).substr(-2,2);
|
||||
if(colons)
|
||||
{
|
||||
if(i < array.length - 1)
|
||||
{
|
||||
s += ":";
|
||||
}
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public static function toString(hex:String) : String
|
||||
{
|
||||
var a:ByteArray = toArray(hex);
|
||||
return a.readUTFBytes(a.length);
|
||||
}
|
||||
|
||||
public static function fromString(str:String, colons:Boolean = false) : String
|
||||
{
|
||||
var a:ByteArray = new ByteArray();
|
||||
a.writeUTFBytes(str);
|
||||
return fromArray(a,colons);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.hurlant.util
|
||||
{
|
||||
import flash.net.LocalConnection;
|
||||
import flash.system.System;
|
||||
|
||||
public class Memory
|
||||
{
|
||||
|
||||
public function Memory()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function gc() : void
|
||||
{
|
||||
try
|
||||
{
|
||||
new LocalConnection().connect("foo");
|
||||
new LocalConnection().connect("foo");
|
||||
}
|
||||
catch(e:*)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public static function get used() : uint
|
||||
{
|
||||
return System.totalMemory;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user