switched to stream call way for closing headache
978668
public void downloadStreamCall(ResponseDownloadResource resource, HttpServletResponse response) {
        final WrittenStreamCall streamCall = resource.getStreamCall();
        if (streamCall == null) {
            String msg = "Either byte data or input stream is required: " + resource;
            throw new IllegalArgumentException(msg);
        }
        try {
            final Integer contentLength = resource.getContentLength();
            if (contentLength != null) {
                response.setContentLength(contentLength);
            }
            final OutputStream out = response.getOutputStream();
            try {
                streamCall.callback(createWrittenStreamOut(out));
                flushDownloadStream(out);
            } finally {
                closeDownloadStream(out);
            }
        } catch (RuntimeException e) {
            throw new ResponseDownloadFailureException("Failed to download the input stream: " + resource, e);
        } catch (IOException e) {
            handleDownloadIOException(resource, e);
        }
    }
1216703
def close(self):
        '''
        
        '''
        if self._closing:
            return
        self._closing = True
        for stream in self.streams:
            stream.close()
        self.streams.clear()
        if hasattr(self.sock, 'close'):
            self.sock.close()
1115260
function(viewers, req) {
  var stream = bl();

  req.on('data', function(chunk) {
    stream.append(chunk);
  });

  req.on('end', function() {
    var data = stream.toString('ascii');
    console.log('Dispatching: ' + data);
  })
}
95385
def _close_event_stream(self):
        """"""
        self.__subscribed = False
        del self.__events[:]
        self.__event_handle.clear()
1252356
function wrap(stream) {
  stream.on('error', error => {
    gutil.log(gutil.colors.red(error.message));
    gutil.log(error.stack);
    if (watching) {
      gutil.log(gutil.colors.yellow('[aborting]'));
      stream.end();
    } else {
      gutil.log(gutil.colors.yellow('[exiting]'));
      process.exit(1);
    }
    ringBell();
  });
  return stream;
}
1014517
function closeStreams(exitCode) {
	// default is 0 if not specified
	exitCode = exitCode === undefined ? 0 : exitCode;

	if (streams.length) {
		streams.forEach(function (logger) {
			logger.write({ level: bunyan.TRACE, msg: util.format('exited with code %d', exitCode) });
			logger.stream.end();
			// jscs:disable jsDoc
			logger.write = function () {};
		});
	}
}
1016977
def close_stream(self):
		
		self.keep_listening = False
		self.stream.stop_stream()
		self.stream.close()
		self.pa.terminate()
570991
@Override
  public void close() throws IOException
  {
      if(this.in != null && this.inStream != null){
          if (TraceComponent.isAnyTracingEnabled()&&logger.isLoggable (Level.FINE)) {
              logger.logp(Level.FINE, CLASS_NAME,"close", "close called->"+this);
          }
          this.in.close();
      }
      else{
          super.close();
      }
  }
557012
private void close(T stream) {

        // Attempt to close stream
        try {
            stream.close();
        }
        catch (IOException e) {
            logger.warn("Unable to close intercepted stream: {}", e.getMessage());
            logger.debug("I/O error prevented closure of intercepted stream.", e);
        }

        // Notify waiting threads that the stream has ended
        synchronized (stream) {
            stream.notify();
        }

    }
1157756
public function stream_close()
    {
        if ($this->data == null) {
            return;
        }

        $this->stream_flush();

        $this->data = null;
        $this->path = null;
        $this->save = false;
        $this->dirty = null;
        $this->metadata = array();
    }
286978
public void close()
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(tc, "close");

    Enumeration streams = null;
    synchronized (this)
    {
      synchronized (streamTable)
      {
        closed = true;
        closeBrowserSessionsInternal();
        streams = streamTable.elements();
      }
    }
    // since already set closed to true, no more AOStreams will be created and added to the streamTable,
    // even if there is an
    // asynchronous stream creation in progress (the itemStream will be created, but no AOStream will
    // be added to the streamTable).
    while (streams.hasMoreElements())
    {
      StreamInfo sinfo = (StreamInfo) streams.nextElement();
      if (sinfo.stream != null)
      {
        sinfo.stream.close();
      }
    }

    synchronized (streamTable)
    {
      streamTable.clear();
    }
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(tc, "close");
  }
1053239
public function stream_close()
    {
        @fclose($this->temporaryFileHandle);
        
        // Upload the file?
        if ($this->writeMode) {
            // Make sure the container exists
            if (! $this->containerExists($this->fileName)) {
                $this->getStorageClient($this->fileName)->createContainer($this->getContainerName($this->fileName));
            }
            
            $mimeTypeGuesser = MimeTypeGuesser::getInstance();
            $createBlobOptions = new CreateBlobOptions();
            $createBlobOptions->setBlobContentType($mimeTypeGuesser->guess($this->temporaryFileName));
            
            // Upload the file
            try {
                $result = $this->getStorageClient($this->fileName)->createBlockBlob($this->getContainerName($this->fileName), $this->getFileName($this->fileName), fopen($this->temporaryFileName, "r"), $createBlobOptions);
            } catch (Exception $ex) {
                $this->cleanup();
                
                throw $ex;
            }
        }
        
        $this->cleanup();
    }
712579
def end
      unless ready? then
        warn "attempt to close uninitialized stream; ignored."
        return nil
      end

      if in_stream? then
        warn "attempt to close unfinished zstream; reset forced"
        reset
      end

      reset_input

      err = Zlib.send @func_end, pointer

      Zlib.handle_error err, message

      @flags = 0

      # HACK this may be wrong
      @output = nil
      @next_out.free unless @next_out.nil?
      @next_out = nil

      nil
    end
389899
private void closeStream(final Throwable throwable) {
    if (stream != null) {
      stream.onCompleted();
      stream = null;
    }

    if (isActive.getAndSet(false)) {
      userCallbackExecutor.execute(
          new Runnable() {
            @Override
            public void run() {
              listener.onEvent(
                  null,
                  throwable instanceof FirestoreException
                      ? (FirestoreException) throwable
                      : FirestoreException.apiException(
                          new ApiException(
                              throwable,
                              GrpcStatusCode.of(getStatus(throwable).getCode()),
                              false)));
            }
          });
    }
  }
933234
private final void _close(boolean forceClosing)
        throws IOException
    {
        byte[] buf = mOutBuffer;
        if (buf != null) {
            mOutBuffer = null;
            if (mOutPtr > 0) {
                mOut.write(buf, 0, mOutPtr);
                mOutPtr = 0;
            }
            if (mConfig != null) {
                mConfig.freeFullBBuffer(buf);
            }
        }

        if (forceClosing) {
            mOut.close();
        }
        
        /* Let's 'flush' orphan surrogate, no matter what; but only
         * after cleanly closing everything else.
         */
        int code = mSurrogate;
        if (code > 0) {
            mSurrogate = 0;
            throwIllegal(code);
        }
    }
1036437
void cleanup(Http2Stream stream, EmbeddedChannel compressor) {
        if (compressor.finish()) {
            for (;;) {
                final ByteBuf buf = compressor.readOutbound();
                if (buf == null) {
                    break;
                }

                buf.release();
            }
        }
        stream.removeProperty(propertyKey);
    }
1351984
private void closeStream(InputStream stream) {

        if (stream != null) {
            try {
                stream.close();
            } catch (Exception ex) {
                LOG.error(ex.getLocalizedMessage(), ex);
            }
        }
    }