You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@royale.apache.org by GitBox <gi...@apache.org> on 2018/05/30 07:59:50 UTC

[GitHub] piotrzarzycki21 closed pull request #254: Base64Decoder class added and wrapper classes modified to support decoding

piotrzarzycki21 closed pull request #254: Base64Decoder class added and wrapper classes modified to support decoding
URL: https://github.com/apache/royale-asjs/pull/254
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/.gitignore b/.gitignore
index 5581ecb9f..2c1495b99 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,153 +1,157 @@
-# eclipse conf file
-.settings
-.classpath
-.project
-.manager
-.scala_dependencies
-.cache
-.actionScriptProperties
-.flexProperties
-.flexLibProperties
-
-# idea conf files
-.idea
-*.iml
-*.ipr
-*.iws
-
-# VSCode conf files
-.vscode/settings.json
-
-# building
-target/
-[Bb]uild/
-null
-tmp
-temp
-dist
-test-output
-build.log
-release
-fonts
-out
-gen
-bin-debug
-bin-release
-binjs-debug
-binjs-release
-examples/FlexJSTest_again/html-template
-examples/FlexJSTest_again/bin
-rat.report
-mustella/tests/basicTests/bin
-mustella/tests/mxtests/basicTests/bin
-asdoc-output
-
-#Apache Flex Projects
-lib/
-libs/
-in/
-swfobject/
-flex2/
-thirdparty/
-3.0.33/
-3.0.33
-
-*.pbj
-*.vms
-*.ser
-*.mxp
-bundles.properties
-empty.properties
-css_*.properties
-FXGException_*.properties
-FXGLog_*.properties
-FABridge.js
-frameworks/projects/spark/manifest.xml
-frameworks/air-config.xml
-frameworks/createjs-config.xml
-frameworks/flex-config.xml
-frameworks/jquery-config.xml
-frameworks/js-config.xml
-frameworks/node-config.xml
-frameworks/royale-config.xml
-env.properties
-local.properties
-/flex-sdk-description.xml
-/royale-sdk-description.xml
-
-#OS junk files
-[Tt]humbs.db
-*.DS_Store
-
-#Files we fake for Flash Builder SDKs
-frameworks/airmobile-config.xml
-frameworks/mxml-manifest.xml
-frameworks/spark-manifest.xml
-frameworks/themes/Halo/Halo.swc
-frameworks/themes/Spark/spark.css
-ide/flashbuilder/flashbuilder-config.xml
-
-#Visual Studio files
-*.[Oo]bj
-*.user
-*.aps
-*.pch
-*.vspscc
-*.vssscc
-*_i.c
-*_p.c
-*.ncb
-*.suo
-*.tlb
-*.tlh
-*.bak
-*.[Cc]ache
-*.ilk
-*.log
-*.lib
-*.sbr
-*.sdf
-ipch/
-obj/
-[Dd]ebug/
-[Rr]elease*/
-Ankh.NoLoad
-!releasemgr
-
-#Tooling
-_ReSharper*/
-*.resharper
-
-#CVS files
-.svn
-.git
-
-# Office Temp Files
-~$*
-
-#Binaries
-*.dll
-*.bin
-*.com
-*.exe
-*.class
-*.jar
-*.swf
-*.swc
-
-#Compressed Files
-*.zip
-*.rar
-*.tar
-
-#VF2JS generated files
-vf2js/frameworks/js/
-
-#Royale generated files
-frameworks/js/Royale/generated-sources
-manualtests/RoyaleTest_SVG/bin
-*.css.map
-
-#npm
-node_modules
-npm/cli/test
\ No newline at end of file
+# eclipse conf file
+.settings
+.classpath
+.project
+.manager
+.scala_dependencies
+.cache
+.actionScriptProperties
+.flexProperties
+.flexLibProperties
+
+# idea conf files
+.idea
+*.iml
+*.ipr
+*.iws
+
+# VSCode conf files
+.vscode/settings.json
+
+# building
+target/
+[Bb]uild/
+null
+tmp
+temp
+dist
+test-output
+build.log
+release
+fonts
+out
+gen
+bin-debug
+bin-release
+binjs-debug
+binjs-release
+examples/FlexJSTest_again/html-template
+examples/FlexJSTest_again/bin
+rat.report
+mustella/tests/basicTests/bin
+mustella/tests/mxtests/basicTests/bin
+asdoc-output
+
+#Apache Flex Projects
+lib/
+libs/
+in/
+swfobject/
+flex2/
+thirdparty/
+3.0.33/
+3.0.33
+
+*.pbj
+*.vms
+*.ser
+*.mxp
+bundles.properties
+empty.properties
+css_*.properties
+FXGException_*.properties
+FXGLog_*.properties
+FABridge.js
+frameworks/projects/spark/manifest.xml
+frameworks/air-config.xml
+frameworks/createjs-config.xml
+frameworks/flex-config.xml
+frameworks/jquery-config.xml
+frameworks/js-config.xml
+frameworks/node-config.xml
+frameworks/royale-config.xml
+env.properties
+local.properties
+/flex-sdk-description.xml
+/royale-sdk-description.xml
+
+#OS junk files
+[Tt]humbs.db
+*.DS_Store
+
+#Files we fake for Flash Builder SDKs
+frameworks/airmobile-config.xml
+frameworks/mxml-manifest.xml
+frameworks/spark-manifest.xml
+frameworks/themes/Halo/Halo.swc
+frameworks/themes/Spark/spark.css
+ide/flashbuilder/flashbuilder-config.xml
+
+#Visual Studio files
+*.[Oo]bj
+*.user
+*.aps
+*.pch
+*.vspscc
+*.vssscc
+*_i.c
+*_p.c
+*.ncb
+*.suo
+*.tlb
+*.tlh
+*.bak
+*.[Cc]ache
+*.ilk
+*.log
+*.lib
+*.sbr
+*.sdf
+ipch/
+obj/
+[Dd]ebug/
+[Rr]elease*/
+Ankh.NoLoad
+!releasemgr
+
+#Tooling
+_ReSharper*/
+*.resharper
+
+#CVS files
+.svn
+.git
+
+# Office Temp Files
+~$*
+
+#Binaries
+*.dll
+*.bin
+*.com
+*.exe
+*.class
+*.jar
+*.swf
+*.swc
+
+#Compressed Files
+*.zip
+*.rar
+*.tar
+
+#VF2JS generated files
+vf2js/frameworks/js/
+
+#Royale generated files
+frameworks/js/Royale/generated-sources
+manualtests/RoyaleTest_SVG/bin
+*.css.map
+
+#npm
+node_modules
+npm/cli/test
+
+frameworks/projects/MXRoyale/.vscode
+.gitignore
+.gitignore
diff --git a/frameworks/projects/MXRoyale/src/main/royale/MXRoyaleClasses.as b/frameworks/projects/MXRoyale/src/main/royale/MXRoyaleClasses.as
index f0e081e65..c46d41970 100644
--- a/frameworks/projects/MXRoyale/src/main/royale/MXRoyaleClasses.as
+++ b/frameworks/projects/MXRoyale/src/main/royale/MXRoyaleClasses.as
@@ -188,6 +188,7 @@ internal class MXRoyaleClasses
 	import mx.collections.ArrayCollection; ArrayCollection;
 	import mx.controls.Alert; Alert;
 	import mx.utils.Base64Encoder; Base64Encoder;
+	import mx.utils.Base64Decoder; Base64Decoder;
 
 	COMPILE::JS
     {
diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/utils/Base64Decoder.as b/frameworks/projects/MXRoyale/src/main/royale/mx/utils/Base64Decoder.as
new file mode 100644
index 000000000..f22ee8dd0
--- /dev/null
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/utils/Base64Decoder.as
@@ -0,0 +1,260 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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 mx.utils
+{
+
+COMPILE::SWF
+{
+    import flash.utils.ByteArray;
+}
+
+COMPILE::JS
+{
+    import goog.DEBUG;
+}
+/*
+import mx.resources.IResourceManager;
+import mx.resources.ResourceManager;
+
+[ResourceBundle("utils")]
+*/
+
+/**
+ * A utility class to decode a Base64 encoded String to a ByteArray.
+ *  
+ *  @langversion 3.0
+ *  @playerversion Flash 9
+ *  @playerversion AIR 1.1
+ *  @productversion Royale 0.9.4
+ */
+public class Base64Decoder
+{
+    //--------------------------------------------------------------------------
+    //
+    //  Constructor
+    //
+    //--------------------------------------------------------------------------
+
+    /**
+     * Constructor.
+     *  
+     *  @langversion 3.0
+     *  @playerversion Flash 9
+     *  @playerversion AIR 1.1
+     *  @productversion Royale 0.9.4
+     */
+    COMPILE::SWF
+    public function Base64Decoder()
+    {
+        super();
+        data = new ByteArray();
+    }
+
+	COMPILE::JS
+    public function Base64Decoder()
+    {
+        super();
+    }
+
+
+    //--------------------------------------------------------------------------
+    //
+    //  Methods
+    //
+    //--------------------------------------------------------------------------
+
+    /**
+     * Decodes a Base64 encoded String and adds the result to an internal
+     * buffer. Strings must be in ASCII format. 
+     * 
+     * <p>Subsequent calls to this method add on to the internal
+     * buffer. After all data have been encoded, call <code>toByteArray()</code>
+     * to obtain a decoded <code>flash.utils.ByteArray</code>.</p>
+     * 
+     * @param encoded The Base64 encoded String to decode.
+     *  
+     *  @langversion 3.0
+     *  @playerversion Flash 9
+     *  @playerversion AIR 1.1
+     *  @productversion Royale 0.9.4
+     */
+
+    COMPILE::JS
+    public function decode(data:String):String
+    {
+
+		var bytes:Object = new Base64JSWrapper().toByteArray(data);
+		var decodedString:String = new TextEncoderLiteWrapper('utf-8').decode(bytes);
+
+		return decodedString;
+    }
+
+
+    COMPILE::SWF
+    public function decode(encoded:String):void
+    {
+        for (var i:uint = 0; i < encoded.length; ++i)
+        {
+            var c:Number = encoded.charCodeAt(i);
+
+            if (c == ESCAPE_CHAR_CODE)
+                work[count++] = -1;
+            else if (inverse[c] != 64)
+                work[count++] = inverse[c];
+            else
+                continue;
+
+            if (count == 4)
+            {
+                count = 0;
+                data.writeByte((work[0] << 2) | ((work[1] & 0xFF) >> 4));
+                filled++;
+
+                if (work[2] == -1)
+                    break;
+
+                data.writeByte((work[1] << 4) | ((work[2] & 0xFF) >> 2));
+                filled++;
+
+                if (work[3] == -1)
+                    break;
+
+                data.writeByte((work[2] << 6) | work[3]);
+                filled++;
+            }
+        }
+    }
+
+    COMPILE::SWF
+    public function drain():ByteArray
+    {
+        var result:ByteArray = new ByteArray();
+
+        var oldPosition:uint = data.position;    
+        data.position = 0;  // technically, shouldn't need to set this, but carrying over from previous implementation
+        result.writeBytes(data, 0, data.length);        
+        data.position = oldPosition;
+        result.position = 0;
+        
+        filled = 0;
+        return result;
+    }
+
+    /*
+    COMPILE::SWF
+    public function flush():ByteArray
+    {
+        if (count > 0)
+        {
+            
+            var message:String = resourceManager.getString("utils", "partialBlockDropped", [ count ]);
+            throw new Error(message);
+            
+        }
+        return drain();
+    }
+    */
+
+    /**
+     * Clears all buffers and resets the decoder to its initial state.
+     *  
+     *  @langversion 3.0
+     *  @playerversion Flash 9
+     *  @playerversion AIR 1.1
+     *  @productversion Royale 0.9.4
+     */
+    COMPILE::SWF
+    public function reset():void
+    {
+        data = new ByteArray();
+        count = 0;
+        filled = 0;
+    }
+
+    /**
+     * Returns the current buffer as a decoded <code>flash.utils.ByteArray</code>.
+     * Note that calling this method also clears the buffer and resets the 
+     * decoder to its initial state.
+     * 
+     * @return The decoded <code>flash.utils.ByteArray</code>.
+     *  
+     *  @langversion 3.0
+     *  @playerversion Flash 9
+     *  @playerversion AIR 1.1
+     *  @productversion Royale 0.9.4
+     */
+    COMPILE::SWF
+    public function toByteArray():ByteArray
+    {
+        var result:ByteArray = flush();
+        reset();
+        return result;
+    }
+
+    //--------------------------------------------------------------------------
+    //
+    //  Private Variables
+    //
+    //--------------------------------------------------------------------------
+
+    COMPILE::SWF
+    private var count:int = 0;
+    COMPILE::SWF
+    private var data:ByteArray;
+    COMPILE::SWF
+    private var filled:int = 0;
+    COMPILE::SWF
+    private var work:Array = [0, 0, 0, 0];
+
+    /**
+     *  @private 
+     *  Used for accessing localized Error messages.
+     */
+    /*
+    private var resourceManager:IResourceManager =
+                                    ResourceManager.getInstance();
+    */
+    
+    COMPILE::SWF
+    private static const ESCAPE_CHAR_CODE:Number = 61; // The '=' char
+
+    COMPILE::SWF
+    private static const inverse:Array =
+    [
+        64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+        64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+        64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63,
+        52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64,
+        64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+        15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64,
+        64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
+        41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64,
+        64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+        64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+        64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+        64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+        64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+        64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+        64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+        64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
+    ];
+}
+
+}
\ No newline at end of file
diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/utils/Base64JSWrapper.as b/frameworks/projects/MXRoyale/src/main/royale/mx/utils/Base64JSWrapper.as
index 56eb6eb75..cdfc56460 100644
--- a/frameworks/projects/MXRoyale/src/main/royale/mx/utils/Base64JSWrapper.as
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/utils/Base64JSWrapper.as
@@ -40,5 +40,14 @@ package mx.utils
 			return base64js.fromByteArray(bytes);
 			
 		}
+
+		public function toByteArray(b64Str:String):Object
+		{
+			var base64js:Object = window["base64js"];
+			
+			return base64js.toByteArray(b64Str);
+			
+		}
+		
 	}
 }
\ No newline at end of file
diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/utils/TextEncoderLiteWrapper.as b/frameworks/projects/MXRoyale/src/main/royale/mx/utils/TextEncoderLiteWrapper.as
index 7796a2b59..607d0c111 100644
--- a/frameworks/projects/MXRoyale/src/main/royale/mx/utils/TextEncoderLiteWrapper.as
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/utils/TextEncoderLiteWrapper.as
@@ -41,6 +41,12 @@ package mx.utils
 			return new (TextEncoder)(_encoding).encode(data);
 			
 		}
+
+		public function decode(data:Object):String
+		{
+			return new (TextDecoder)(_encoding).decode(data);
+			
+		}
 		
 	}
 }
\ No newline at end of file


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services