Jetzt mache ich Flash Actionscript 3.0 Entwicklung, ich habe eine Base64bitEncoder-Klasse mit der encodeByteArray (...) und decodeToByteArray (...) -Funktion.Was und wo ist das Problem in Base64bitEncoder.decodeToByteArray
aber wenn ich den untenstehenden Testcode schreibe, aber die byteArray.length am vor der Codierung und nach der Decodierung sind anders, können Sie helfen zu sehen, wo ich falsch liegen?
Test-Beispielcode wie folgt:
var _loc_2:XML = new XML("<formXML>aaaaa</formXML>");;
var _loc_3:ByteArray;
_loc_3 = new ByteArray();
//_loc_3.endian = Endian.LITTLE_ENDIAN;
_loc_3.writeUTFBytes(_loc_2);
trace("Before Encoding Length:" + _loc_3.length);
var baseString:String = Base64bitEncoder.encodeByteArray(_loc_3);
trace(baseString);
var strArray:ByteArray = Base64bitEncoder.decodeToByteArray(baseString);
trace("After Decoding length:" + strArray.length);
Ausgabeprotokoll wie folgt:
Before Encoding Length:5
GFhAGFhA
After Decoding length:**6**
Warum die nach 6, wo ich falsch gemacht?
Base64bitEncoder Quellcode wie folgt:
package
{
import flash.utils.*;
public class Base64bitEncoder extends Object
{
private static const BASE64_CHARS:String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/=";
private static const BASE64_URL_CHARS:String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_!";
public function Base64bitEncoder()
{
return;
}// end function
public static function encode(param1:String, param2:Boolean = false) : String
{
var _loc_3:ByteArray;
_loc_3 = new ByteArray();
_loc_3.writeUTFBytes(param1);
return encodeByteArray(_loc_3, param2);
}// end function
public static function decodeToByteArray(param1:String, param2:Boolean = false) : ByteArray
{
var _loc_3:ByteArray;
var _loc_4:Array;
var _loc_5:Array;
var _loc_6:uint;
var _loc_7:uint;
var _loc_8:uint;
_loc_3 = new ByteArray();
_loc_4 = new Array(4);
_loc_5 = new Array(3);
_loc_6 = 0;
while (_loc_6 < param1.length)
{
// label
_loc_7 = 0;
while (_loc_7++ < 4 && _loc_6 + _loc_7 < param1.length)
{
// label
_loc_4[_loc_7] = param2 == true ? (BASE64_URL_CHARS.indexOf(param1.charAt(_loc_6 + _loc_7))) : (BASE64_CHARS.indexOf(param1.charAt(_loc_6 + _loc_7)));
}// end while
_loc_5[0] = (_loc_4[0] << 2) + ((_loc_4[1] & 48) >> 4);
_loc_5[1] = ((_loc_4[1] & 15) << 4) + ((_loc_4[2] & 60) >> 2);
_loc_5[2] = ((_loc_4[2] & 3) << 6) + _loc_4[3];
_loc_8 = 0;
while (_loc_8++ < _loc_5.length)
{
// label
if (_loc_4[_loc_8 + 1] == 64)
{
break;
}// end if
_loc_3.writeByte(_loc_5[_loc_8]);
}// end while
_loc_6 = _loc_6 + 4;
}// end while
_loc_3.position = 0;
return _loc_3;
}// end function
public static function encodeByteArray(param1:ByteArray, param2:Boolean = false) : String
{
var _loc_3:String;
var _loc_4:Array;
var _loc_5:Array;
var _loc_6:uint;
var _loc_7:uint;
var _loc_8:uint;
_loc_3 = "";
_loc_5 = new Array(4);
param1.position = 0;
while (param1.bytesAvailable > 0)
{
// label
_loc_4 = [];
_loc_6 = 0;
while (_loc_6++ < 3 && param1.bytesAvailable > 0)
{
// label
_loc_4[_loc_6] = param1.readUnsignedByte();
}// end while
_loc_5[0] = (_loc_4[0] & 252) >> 2;
_loc_5[1] = (_loc_4[0] & 3) << 4 | _loc_4[1] >> 4;
_loc_5[2] = (_loc_4[1] & 15) << 2 | _loc_4[2] >> 6;
_loc_5[3] = _loc_4[2] & 63;
_loc_7 = _loc_4.length;
while (_loc_7++ < 3)
{
// label
_loc_5[_loc_7 + 1] = 64;
}// end while
_loc_8 = 0;
while (_loc_8++ < _loc_5.length)
{
// label
_loc_3 = _loc_3 + (param2 == true ? (BASE64_URL_CHARS.charAt(_loc_5[_loc_8])) : (BASE64_CHARS.charAt(_loc_5[_loc_8])));
}// end while
}// end while
return _loc_3;
}// end function
public static function decode(param1:String, param2:Boolean = false) : String
{
var _loc_3:ByteArray;
_loc_3 = decodeToByteArray(param1, param2);
return _loc_3.readUTFBytes(_loc_3.length);
}// end function
}
}
Das ist ein dekompilierten Code und es ist nicht dein, also warum Sie uns gesagt: „Ich Flash-AS3 tun ... Ich habe eine Base64bitEncoder Klasse haben ... Ich schreibe die folgenden Testcode ... ich falsch ... ich falsch gemacht "... aber wie du es gesagt hast, du tust wirklich falsch! Versuchen Sie, Ihren eigenen Code zu schreiben, wenn Sie Probleme haben, schreiben Sie sie hier und Sie werden sicherlich Hilfe bekommen, aber nicht, wenn Sie den Code anderer benutzen! – akmozo
@akmozo, Ja, Sie haben Recht, der Base64bitEncoder Klassencode wurde nicht von mir entwickelt, ich beziehe mich nur darauf. Aber ich habe festgestellt, dass es möglicherweise ein Problem in decodeByteArray-Methode, da ich nicht mit dem Base64 vertraut bin, so dass ich den Code hier vorbei, um zu sehen, ob der Master darauf hinweisen kann, was/wo das Problem ist. Vielen Dank. –
Ihr Problem ist mit Base64 in AS3 oder nur mit diesem Code? Es gibt viele [AS3-Bibliotheken] (http://stackoverflow.com/questions/6625347/best-class-for-base64-encoding-decoding-action-script), um das zu tun (und viele von ihnen sind Open Source). . – akmozo