2956 readFrom:aStream onError:exceptionBlock |
2955 readFrom:aStream onError:exceptionBlock |
2957 "read an object's printed representation from the argument, aStream |
2956 "read an object's printed representation from the argument, aStream |
2958 and return it (i.e. the stream should contain some representation of |
2957 and return it (i.e. the stream should contain some representation of |
2959 the object which was created using #storeOn:). |
2958 the object which was created using #storeOn:). |
2960 The read object must be a kind of myself. |
2959 The read object must be a kind of myself. |
2961 If its not, the value of exceptionBlock is returned. |
2960 If it's not, the value of exceptionBlock is returned. |
2962 To get any object, use 'Object readFrom:...', |
2961 To get any object, use 'Object readFrom:...', |
2963 To get any number, use 'Number readFrom:...' and so on. |
2962 To get any number, use 'Number readFrom:...' and so on. |
2964 This is the reverse operation to 'storeOn:'. |
2963 This is the reverse operation to 'storeOn:'. |
2965 |
2964 |
2966 WARNING: storeOn: does not handle circular references and multiple |
2965 WARNING: storeOn: does not handle circular references and multiple |
2967 references to the same object. |
2966 references to the same object. |
2968 Use #storeBinary:/readBinaryFrom: for this." |
2967 Use #storeBinary:/readBinaryFrom: for this." |
2969 |
2968 |
2970 ^ [ |
2969 ^ [ |
2971 |newObject| |
2970 |newObject| |
2972 newObject := self evaluatorClass evaluateFrom:aStream ifFail:exceptionBlock. |
2971 |
2973 (newObject isKindOf:self) ifTrue:[newObject] ifFalse:[exceptionBlock value]. |
2972 newObject := self evaluatorClass evaluateFrom:aStream ifFail:exceptionBlock. |
|
2973 ((newObject class == self) or:[newObject isKindOf:self]) |
|
2974 ifTrue:[newObject] |
|
2975 ifFalse:[exceptionBlock value]. |
2974 ] on:Error do:exceptionBlock. |
2976 ] on:Error do:exceptionBlock. |
2975 |
2977 |
2976 " |
2978 " |
2977 |s| |
2979 |s| |
2978 s := WriteStream on:String new. |
2980 s := WriteStream on:String new. |
2979 #(1 2 3 4) storeOn:s. |
2981 #(1 2 3 4) storeOn:s. |
2980 Transcript showCR:( |
2982 Transcript showCR:( |
2981 Array readFrom:(ReadStream on:s contents) onError:'not an Array' |
2983 Array readFrom:(ReadStream on:s contents) onError:'not an Array' |
2982 ) |
2984 ) |
2983 " |
2985 " |
2984 " |
2986 " |
2985 |s| |
2987 |s| |
2986 s := WriteStream on:String new. |
2988 s := WriteStream on:String new. |
2987 #[1 2 3 4] storeOn:s. |
2989 #[1 2 3 4] storeOn:s. |
2988 Transcript showCR:( |
2990 Transcript showCR:( |
2989 Array readFrom:(ReadStream on:s contents) onError:'not an Array' |
2991 Array readFrom:(ReadStream on:s contents) onError:'not an Array' |
2990 ) |
2992 ) |
2991 " |
2993 " |
2992 " |
2994 " |
2993 Object readFrom:'illegal' onError:['bla'] |
2995 Object readFrom:'illegal' onError:['bla'] |
2994 String readFrom:'illegal' onError:'bla' |
2996 String readFrom:'illegal' onError:'bla' |