[squeak-dev] SmartRefStream has no usable Stream interface. Why?

Edgar De Cleene edgardec2005 at gmail.com
Tue May 10 11:54:43 UTC 2016


Some of us are using .obj for long time for limited exchange of simple objects between Cuis,Squeak and Pharo

Object methodsFor: 'objects from disk' stamp: 'edc 6/20/2008 11:41'!
saveOnFileNamed: aString 
	"Ask the user for a filename and save myself on a
	SmartReferenceStream file. Writes out the version and class structure.
	The file is fileIn-able. UniClasses will be filed out.
	This save objects as .obj"
	| aFileName fileStream |
	aString isEmpty
		ifTrue: [^ self error: 'name is missing'].
	aFileName := aString , '.obj'.
	fileStream := ReferenceStream fileNamed: aFileName .
	fileStream nextPut: self.
	fileStream close.
	! !


!Object class methodsFor: 'objects from disk' stamp: 'edc 3/5/2008 12:12'!
readAndInspect: inputStream
| o rr |

	rr _ ReferenceStream on: inputStream.
	o _ rr next.
	rr close.
	o inspect! !

!Object class methodsFor: '*services-extras' stamp: 'edc 2/14/2008 08:24'!
fileReaderServicesForFile: fullName suffix: suffix
	| services |
	services _ OrderedCollection new.
		
	(fullName asLowercase endsWith: '.obj')
		ifTrue: [ services add: self serviceLoadObject ].
	^services! !

!Object class methodsFor: '*services-extras' stamp: 'edc 7/27/2008 08:11'!
readCompressedObject: aFileStream 
		
	self readAndInspect: (MultiByteBinaryOrTextStream with: (GZipReadStream on: aFileStream) upToEnd) reset! !

!Object class methodsFor: '*services-extras' stamp: 'edc 7/27/2008 07:40'!
serviceCompressedObject
	"Answer a service for opening a saved Object"
	^ (SimpleServiceEntry
		provider: Object
		label: 'gz saved Object'
		selector: #readCompressedObject:
		description: 'open a gz Object'
		buttonLabel: 'object')
		argumentGetter: [:fileList | 
				
			fileList readOnlyStream]! !

!Object class methodsFor: '*services-extras' stamp: 'edc 2/14/2008 08:26'!
serviceLoadObject
"Answer a service for opening a saved Object"

	^ (SimpleServiceEntry 
		provider: self 
		label: 'saved Object'
		selector: #readAndInspect:
		description: 'open a Object'
		buttonLabel: 'object')
		argumentGetter: [:fileList | fileList readOnlyStream]! !


-- 
Edgar De Cleene
Sent with Airmail

On May 10, 2016 at 08:23:08, marcel.taeumel (marcel.taeumel at hpi.de) wrote:

Hi, there!  

If you want to serialize an object with the SmartRefStream to support  
addition and removal instance variables in classes, you can do this:  

obj := Morph new.  
stream := SmartRefStream on: #[] writeStream.  
stream nextPutObjOnly: obj.  
stream close.  
blob := stream contents.  
objCopy := (SmartRefStream on: blob readStream) next.  

Or your can do this, which produces the traditional "file-in format" with a  
text header used, for example, when filing out a morph:  

obj := Morph new.  
stream := SmartRefStream on: (RWBinaryOrTextStream on: '').  
stream nextPut: obj.  
stream close.  
blob := stream contents.  
objCopy := (SmartRefStream on: blob readStream asBinaryOrTextStream)  
nextAndClose.  

This is awkward. It took me some time to figure out that I just cannot use  
the regular stream interface, which I can do with ReferenceStream. And  
SmartRefStream is just a subclass of it. *sigh*  

So, I want to use #nextPut: and #next: just as usual:  

obj := Morph new.  
stream := SmartRefStream on: #[] writeStream.  
stream nextPut: obj.  
stream close.  
blob := stream contents.  
objCopy := (SmartRefStream on: blob readStream) next.  

Also, WriteStream DNU #ascii. *sigh*  

Best,  
Marcel  




--  
View this message in context: http://forum.world.st/SmartRefStream-has-no-usable-Stream-interface-Why-tp4894185.html  
Sent from the Squeak - Dev mailing list archive at Nabble.com.  

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20160510/952c5fef/attachment.htm


More information about the Squeak-dev mailing list