diff options
author | Matthias Andreas Benkard <matthias@benkard.de> | 2008-07-07 09:53:02 +0200 |
---|---|---|
committer | Matthias Andreas Benkard <matthias@benkard.de> | 2008-07-07 09:53:02 +0200 |
commit | 629a99a805399db4be550029666d9edc75488937 (patch) | |
tree | 1130ab1c0d03edc992a418b0535e238f1391cb5e | |
parent | a47ea1c8dada820c603607835be9d56178dd00f8 (diff) |
Properly open and close streams if necessary.
-rw-r--r-- | MLKStream.h | 2 | ||||
-rw-r--r-- | MLKStream.m | 25 |
2 files changed, 26 insertions, 1 deletions
diff --git a/MLKStream.h b/MLKStream.h index cc67400..733b5ee 100644 --- a/MLKStream.h +++ b/MLKStream.h @@ -28,6 +28,8 @@ NSOutputStream *_output; NSStringEncoding _encoding; BOOL _charCached; + BOOL _closeInputWhenDone; + BOOL _closeOutputWhenDone; unichar _cachedChar; } diff --git a/MLKStream.m b/MLKStream.m index d77ff9c..f1c2b32 100644 --- a/MLKStream.m +++ b/MLKStream.m @@ -57,6 +57,8 @@ _encoding = encoding; _cachedChar = 0; _charCached = NO; + _closeInputWhenDone = NO; + _closeOutputWhenDone = NO; return self; } @@ -75,6 +77,12 @@ return ch; } + if ([_input streamStatus] == NSStreamStatusNotOpen) + { + _closeInputWhenDone = YES; + [_input open]; + } + buffer = NULL; for (i = 0;; i++) { @@ -85,7 +93,7 @@ buffer = realloc (buffer, i+1); bytes_read = [_input read:(buffer+i) maxLength:1]; - NSLog (@"%d bytes read", bytes_read); + //NSLog (@"%d bytes read", bytes_read); if (bytes_read < 1) { @@ -149,4 +157,19 @@ return eofp; } + +-(void) dealloc +{ + if (_closeInputWhenDone) + { + [_input close]; + } + RELEASE (_input); + if (_closeOutputWhenDone) + { + [_output close]; + } + RELEASE (_output); + [super dealloc]; +} @end |