def streamToReceiver(self, inputStream, streamVariable, filename, typ,
                contentLength):
        if streamVariable is None:
            raise ValueError, 'StreamVariable for the post not found'

        out = None
        totalBytes = 0
        startedEvent = StreamingStartEventImpl(filename, typ, contentLength)

        try:
            streamVariable.streamingStarted(startedEvent)
            out = streamVariable.getOutputStream()
            listenProgress = streamVariable.listenProgress()

            # Gets the output target stream
            if out is None:
                raise NoOutputStreamException()

            if inputStream is None:
                # No file, for instance non-existent filename in html upload
                raise NoInputStreamException()

            bufferSize = self._MAX_UPLOAD_BUFFER_SIZE
            bytesReadToBuffer = 0
            while totalBytes < len(inputStream):
                buff = inputStream.read(bufferSize)
                bytesReadToBuffer = inputStream.pos - bytesReadToBuffer

                out.write(buff)
                totalBytes += bytesReadToBuffer

                if listenProgress:
                    # update progress if listener set and contentLength
                    # received
                    progressEvent = StreamingProgressEventImpl(filename,
                            typ, contentLength, totalBytes)
                    streamVariable.onProgress(progressEvent)

                if streamVariable.isInterrupted():
                    raise UploadInterruptedException()

            # upload successful
            out.close()
            event = StreamingEndEventImpl(filename, typ, totalBytes)
            streamVariable.streamingFinished(event)
        except UploadInterruptedException, e:
            # Download interrupted by application code
            self.tryToCloseStream(out)
            event = StreamingErrorEventImpl(filename, typ, contentLength,
                    totalBytes, e)
            streamVariable.streamingFailed(event)
            # Note, we are not throwing interrupted exception forward as
            # it is not a terminal level error like all other exception.
        except Exception, e:
            self.tryToCloseStream(out)
            event = StreamingErrorEventImpl(filename, typ, contentLength,
                    totalBytes, e)
            streamVariable.streamingFailed(event)
            # throw exception for terminal to be handled (to be passed
            # to terminalErrorHandler)
            raise UploadException(e)

        return startedEvent.isDisposed()
Ticket #16329: sqlite3 in-memory test databases
dataset/ETHPy150Open rwl/muntjac/muntjac/terminal/gwt/server/abstract_communication_manager.py/AbstractCommunicationManager.streamToReceiver--crossover with--dataset/ETHPy150Open AppScale/appscale/AppServer/lib/django-1.5/tests/regressiontests/test_runner/tests.py/Sqlite3InMemoryTestDbs.test_transaction_support