Page 1 of 1

Fast way to dump an array as a string in extension?

Posted: 29 Apr 2012, 13:04
by mixart
Trying to find out if there is a fast way to dump a nested SFSarray as a string to a text file (in an extension).

It seems SFSArray.toString() only converts simple objects to strings, not a whole array (like actionscript does).

So I have to iterate through each array and sub array like this:

Code: Select all

String finalString = "";
   for(int i=0; i<mainArray.size(); i++){
            subArray = (ISFSArray) mainArray.getElementAt(i);
            for(int j=0; j<subArray.size(); j++){
                                       //my toString() here is because my array contains mixed data types so I need to convert them each to strings to save them to the final string
               subStr = subArray.getElementAt(j).toString();
               finalString += subStr;
            }
         }


Is there no easier/more efficient way to do this via the API?
P.s. My arrays are a few hundred K of data (sometimes approaching 1 MB).

Re: Fast way to dump an array as a string in extension?

Posted: 30 Apr 2012, 13:21
by Lapo
SFSArray.getDump() :)

Re: Fast way to dump an array as a string in extension?

Posted: 01 May 2012, 07:17
by mixart
Not really what I was after... getDump() includes a pretty huge bloated amount of data (text such as datatype for each piece of data and also lots of tab data, etc.).

E.g. a getDump outputs:

Code: Select all

(sfs_array)
               (utf_string) pen
               (utf_string) 154,75|1454,575|1154,475|81564,745|1354,765
               (int) 4
               (int) 100
               (utf_string) username27
(sfs_array)
               (utf_string) pen
               (utf_string) 154,75|1454,575|1154,475|81564,745|1354,765
               (int) 4
               (int) 100
               (utf_string) username27


When all I want is the data as a string like this:

Code: Select all

pen,154,75|1454,575|1154,475|81564,745|1354,765,4,100,username27,pen,154,75|1454,575|1154,475|81564,745|1354,765,4,100,username27


I guess I could replace/strip all the unnecessary data here, but that would probably be slower than just looping through the arrays to extract the data.

In my SFSx1 extension (actionscript extension) I simply used myArray.toString() to achieve this.
It would be really cool if in the API "toString" worked on Arrays in this way :)

Re: Fast way to dump an array as a string in extension?

Posted: 02 May 2012, 07:39
by Lapo
The SFSArray can contain any number of other SFSObject/Array nested within, therefore getDump() provides a full-depth view of the object.

Re: Fast way to dump an array as a string in extension?

Posted: 02 May 2012, 11:01
by mixart
I understand getdump and it's value - great for debugging. I was just hoping there was something for my needs - which is a dump that's compact for the purpose of saving data to a file that is imported into other web apps.

I ended up just using for loops - does the job.