Another fix for the base64 stream implementation that addresses three issues:
1. Fixed a bun introduced with the last fix for uploads with no content stream - now uploads with content stream work again as well
2. Unnecessary log statements removed - it happens all the time that the base64InputStream is not yet opened when the encoder Stream receives an NSStreamEventHasSpaceAvailable without causing any issues
3. Added a workaround for the 'Stream ... is sending an event before being opened' Apple bug that seems to work - when the encoder stream is opened we also open the bound base64InputStream although this should be done by the NSURLRequest but doing it here apparently causes no harm and fixes the bug 

git-svn-id: https://svn.apache.org/repos/asf/chemistry/objectivecmis/trunk@1496374 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ObjectiveCMIS/Utils/CMISHttpUploadRequest.m b/ObjectiveCMIS/Utils/CMISHttpUploadRequest.m
index 1167fa2..7349e0c 100644
--- a/ObjectiveCMIS/Utils/CMISHttpUploadRequest.m
+++ b/ObjectiveCMIS/Utils/CMISHttpUploadRequest.m
@@ -305,6 +305,9 @@
 {
     switch (eventCode){
         case NSStreamEventOpenCompleted:{
+            if (self.base64InputStream.streamStatus != NSStreamStatusOpen) {
+                [self.base64InputStream open]; // this seems to work around the 'Stream ... is sending an event before being opened' Apple bug
+            }
             if (self.inputStream.streamStatus != NSStreamStatusOpen) {
                 [self.inputStream open];
             }
@@ -313,20 +316,16 @@
         case NSStreamEventHasBytesAvailable: {
         } break;
         case NSStreamEventHasSpaceAvailable: {
-            /*
-             first we check if we can fill the output stream buffer with data
-             the criteria for that is that bufferOffset equals the buffer limit
-             */
             if (self.base64InputStream) {
                 NSStreamStatus inputStatus = self.base64InputStream.streamStatus;
-                if (inputStatus == NSStreamStatusNotOpen || inputStatus == NSStreamStatusClosed) {
-                    CMISLogDebug(@"*** Base 64 Input Stream is not yet open or closed. The status is %d ***", inputStatus);
+                if (inputStatus == NSStreamStatusClosed) {
+                    CMISLogDebug(@"Base64InputStream %@ is closed", self.base64InputStream);
                 }
                 else if (inputStatus == NSStreamStatusAtEnd){
-                    CMISLogDebug(@"*** Base 64 Input Stream has reached the end ***");
+                    CMISLogDebug(@"Base64InputStream %@ has reached the end", self.base64InputStream);
                 }
                 else if (inputStatus == NSStreamStatusError){
-                    CMISLogDebug(@"Input stream error");
+                    CMISLogDebug(@"Base64InputStream %@ input stream error: %@", self.base64InputStream, self.base64InputStream.streamError);
                     [self stopSendWithStatus:@"Network read error"];
                 }
             }
@@ -357,6 +356,7 @@
                         self.bufferOffset = 0;
                         self.bufferLimit = self.streamEndData.length;
                         self.dataBuffer = [NSData dataWithData:self.streamEndData];
+                        self.streamEndData = nil;
                     }
                     if ((self.bufferLimit == self.bufferOffset) && self.encoderStream != nil) {
                         self.encoderStream.delegate = nil;