My Fault, sorry!

I'd expected to retrieve an array, while the file stores 'DocumentFile'
classes (appended one after another), that's wrong. First create array, add
'DocumentFile' object, save and later I have my array. Thanks for all your
help! 

 

Have a nice day.

 

____________________________________

Claudio M. E. Bastos Iorio

 <http://www.blumer.com.ar/> http://www.blumer.com.ar

 

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Alex Harui
Sent: Friday, August 15, 2008 12:40 AM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Re: writeObject() and readObject()

 

I would trace out stream.bytesAvailable to see how many bytes are available.
Maybe the stream isn't where you think it is in the file.  Similarly, track
the file size as you write it out and see if the numbers make sense.  Also
make sure your writeObject and readObject methods are correct.  Maybe
readObject is reading too many bytes.

 

  _____  

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Claudio M. E. Bastos Iorio
Sent: Thursday, August 14, 2008 4:04 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Re: writeObject() and readObject()

 

I have control over the way the file is written (I'm creating and saving the
file). I'm actually adding objects using FileMode.APPEND. So, the resulting
file (simplified, and if you open it using notepad) is something like:

 

s!com.DocumentFileidid55555

s!com.DocumentFileidid55556

s!com.DocumentFileidid55557

 

using (see my following code) FileStream.bytesAvailable I CAN read the data,
but (following my example), I can assign only the LAST saved object. I'd
like to retrieve all of them, and later assign it to an array, filter.. 

 

while(stream.bytesAvailable){

var aDoc:DocumentFile = stream.readObject() as DocumentFile;//only stores
the last saved DocumentFile, no matter if I have other objects stored


}

 

____________________________________

Claudio M. E. Bastos Iorio

 <http://www.blumer.com.ar/> http://www.blumer.com.ar

 

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Alex Harui
Sent: Thursday, August 14, 2008 7:06 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Re: writeObject() and readObject()

 

You have to know what it is in the file or how to figure it out.  If you
don't have control over the way the file is written, it will be much harder.

 

I don't know why if there are bytes available and it is a sequence of
DocumentFiles that you can't just read them.  Make sure you know what is
really in the file.

 

  _____  

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Claudio M. E. Bastos Iorio
Sent: Thursday, August 14, 2008 2:54 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Re: writeObject() and readObject()

 

Alex, many thanks for your responses. I'd like to use the array's 'push'
method, but I'm loading the objects from a file, while the filestream has
bytesavailable, like this: 

 

while(stream.bytesAvailable){

_whatshouldIuseHere = stream.readObject() as DocumentFile;//

var aDoc:DocumentFile = stream.readObject() as DocumentFile;//only stores
the last saved DocumentFile, no matter if I have other objects stored


}

The question should be: given a file, that stores some objects saved in AMF
format. What can I do to retrieve each object, filter? 

____________________________________

Claudio M. E. Bastos Iorio

 <http://www.blumer.com.ar/> http://www.blumer.com.ar

 

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Alex Harui
Sent: Thursday, August 14, 2008 4:46 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Re: writeObject() and readObject()

 

I think I don't understand your problem.  Normally, if you know how many you
are going to write, you would do:

 

arr.push(someDocumentFile);

arr.push(someOtherDocumentFile);

var numFiles:int = arr.length;

writeObject(numFiles);

for (var i:int = 0; I < numFiles, i++)

            writeObject(arr[i]);

 

And read it back like this:

 

Arr = [];

Var numFiles;

numFiles = readObject();

for (var i:int = 0; I < numFiles, i++)

arr.push(readObject());

 

 

If you don't know, how many, you might want to use a tagged file format

 

  _____  

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Claudio M. E. Bastos Iorio
Sent: Wednesday, August 13, 2008 10:12 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Re: writeObject() and readObject()

 

Could be. But forgive If I don't realize: how could I read the fileStream in
that way?

Right now I read it this way:

 

while(stream.bytesAvailable){

arr = stream.readObject() as DocumentFile;//bad cast


}

 

 

I also tried this:

 arr[0] = stream.readObject() as DocumentFile;//assigns the last
DocumentFile saved in the file..

 

 

____________________________________

Claudio M. E. Bastos Iorio

 

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Alex Harui
Sent: Thursday, August 14, 2008 1:21 AM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Re: writeObject() and readObject()

 

I would write out the number of DocumentFiles before writing them out, then
when reading, I'd read that number and know how many to expect

 

  _____  

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Claudio M. E. Bastos Iorio
Sent: Wednesday, August 13, 2008 9:13 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Re: writeObject() and readObject()

 

Thanks for answer.

But what can I do if I have many DocumentFile objects written in the file?
Is there any way to retrieve all objects or filter by value name/id..? just
like a database o e4x..

 

____________________________________

Claudio M. E. Bastos Iorio

 

 

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Alex Harui
Sent: Thursday, August 14, 2008 12:20 AM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Re: writeObject() and readObject()

 

If you wrote an instance of DocumentFIle, you need to read back an instance
of DocumentFIle

 

  _____  

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of slackware2142
Sent: Wednesday, August 13, 2008 5:57 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: writeObject() and readObject()

 

I forgot to mention that I'm using FLEX3 and my class (DocumentFile) 
is already registered:

[RemoteClass(alias="com.DocumentFile")]
public class DocumentFile extends EventDispatcher
{
...
)

____________________________________
Claudio M. E. Bastos Iorio

--- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> ,
"slackware2142" <[EMAIL PROTECTED]> 
wrote:
>
> Hi! I'm trying to create a simple 'file database' in AIR.
> I know I can save and restore objects in AMF format using the 
methods 
> write/restoreObject.
> 
> here is my code to save:
> 
> var DocumentToSave:DocumentFile = new DocumentFile
(); //DocumentFile 
> is a custom class
> DocumentToSave.Name = 'some name';
> var file:File = File.applicationStorageDirectory.resolvePath
> ('myApp.data');
> var stream:FileStream = new FileStream();
> stream.open(file, FileMode.APPEND);
> stream.writeObject(DocumentToSave);
> 
> That code is working and stores the DocumentFile objects and 
values. 
> But, what can I do to retrieve that objects (or any particular 
> object).
> 
> I tried this to retrieve:
> 
> var file:File = File.applicationStorageDirectory.resolvePath
> ('myApp.data');
> var stream:FileStream = new FileStream();
> stream.open(file, FileMode.READ);
> var arr:Array = new Array();
> while(stream.bytesAvailable){
> //what can I use here to create an array of DocumentFiles stored 
> in 'myApp.data'?
> arr = stream.readObject() as Array; //seems to work
> }
> 
> trace('new arr length: ' + arr.length);//doesn't work, why??
> 
> Any help?
> 
> Thanks in advance!
> 
> 
> ____________________________________
> Claudio M. E. Bastos Iorio
>

 

Reply via email to