Squeak
  links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
DataStream example
Last updated at 10:14 am UTC on 4 April 2019
 coll := Set new.

 (Metaclass allInstances asSortedCollection: 
 [:a :b | a name   b name]) do: [:cl | coll add: (cl name copyReplaceAll: ' class' with: '')].


Store the set
	ds := DataStream fileNamed: 'test.obj'.
	ds nextPut: coll.
	ds close.


To get it back in the same or another image file:

 | coll |
	ds := DataStream fileNamed: 'test.obj'.
	coll := ds next.
	ds close.
       coll inspect


Reading an object file in Cuis


   'test.obj' asFileEntry readStreamDo: [ :file |
    file binary.
    DATA _ (DataStream on: file) next ].
    DATA inspect

Note: This works if 'test.obj' only contains objects of classes which are also available in Cuis.

For example WideString is not in Cuis. Thus a string value which contains Unicode characters contained in 'test.obj' does not allow the file to be read. A workaround is then to write out a copy and send it #asByteArray first.

 aString asByteArray

Then in Cuis use

 String fromUtf8: aByteArray

Hint: Also consider to use method storeDataOn: aDataStream in your own classes, more see DataStream.