FakeFileHandle

  1.  
  2. #import "FakeFileHandle.h"
  3.  
  4. @implementation FakeFileHandle
  5.  
  6. - (id)init
  7. {
  8. if (self = [super init]) {
  9. _dataWritten = [[NSMutableData alloc] initWithCapacity:0];
  10. }
  11. return self;
  12. }
  13.  
  14. - (void)dealloc
  15. {
  16. [_dataWritten release];
  17. [super dealloc];
  18. }
  19.  
  20. - (void)writeData:(NSData *)data
  21. {
  22. [_dataWritten appendData:data];
  23. }
  24.  
  25. - (NSData *)dataWritten
  26. {
  27. return _dataWritten;
  28. }
  29.  
  30. - (NSString *)stringWritten
  31. {
  32. return [[[NSString alloc] initWithData:_dataWritten
  33. encoding:NSUTF8StringEncoding] autorelease];
  34. }
  35.  
  36. - (int)fileDescriptor {
  37. // Not true, but this will appease some callers.
  38. return STDOUT_FILENO;
  39. }
  40.  
  41. - (void)synchronizeFile
  42. {
  43. }
  44.  
  45. @end
Programming language: 
Objective-C