Returns the response error stream, handling the case when it contains gzipped data.
@return gzip decoded (if needed) error stream or null
481790
private InputStream getErrorStream() {
        InputStream errorStream = this.connection.getErrorStream();
        if (errorStream != null) {
            final String contentEncoding = this.connection.getContentEncoding();
            if (contentEncoding != null && contentEncoding.equalsIgnoreCase("gzip")) {
                try {
                    errorStream = new GZIPInputStream(errorStream);
                } catch (IOException e) {
                    // just return the error stream as is
                }
            }
        }

        return errorStream;
    }
1072956
InputStream getInputStream() throws IOException {
        switch (filetype) {
            case GZ:
                LOG.debug("Decompressing .gz file");
                return new GzipCompressorInputStream(new FileInputStream(compressedFile));
            case BZ2:
                LOG.debug("Decompressing .bz2 file");
                return new BZip2CompressorInputStream(new FileInputStream(compressedFile));
        }
        return null;
    }
1068698
protected function GetErrorCodesFromResponse()
    {
        $SReturnMessage = false;
        if ($this->bIsCorrectIPaymentType()) {
            $oGlobal = TGlobal::instance();
            $SReturnState = $oGlobal->GetUserData('ret_status');
            if ('ERROR' == $SReturnState) {
                $SReturnMessage = $oGlobal->GetUserData('ret_errormsg');
                $SReturnMessage = utf8_encode($SReturnMessage);
            }
        }

        return $SReturnMessage;
    }
365311
public function getErrorContent()
    {
        if ($this->getErrorFile() && file_exists($this->getErrorFile())) {
            return file_get_contents($this->getErrorFile());
        } else {
            return null;
        }
    }
560650
public static byte[] getContent(HttpResponse response) {

		try {
			if (response != null && response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
				return ResourceUtils.getBytes(response.getEntity().getContent());
			}
		}
		catch (IOException e) {
			log.error("Failed to read response: ", e.getMessage());
		}

		return null;
	}
577448
function decodeStream( $request, $stream, $headers=false, $cookies=array(), $statuscode="200" )
    {
        $this->decodeStreamCommon( $request, $stream, $headers, $cookies, $statuscode );

        $contentType = $this->ContentType;
        $charset = $this->Charset;

        // allow request to force an expected response type
        // this is useful if servers do respond with eg. text/plain content-header for json or xml
        if ( ( $forcedType = $request->responseType() ) != '' )
        {
            list ( $contentType, $charset2 ) = $this->parseContentTypeHeader( $forcedType );
            $this->ContentType = $contentType . '; received="' . $this->ContentType . '"';
            if ( $charset2 != '' )
            {
                $charset = $charset2;
                $this->Charset = $charset . '; received="' . $this->Charset . '"';
            }
        }

        // Allow empty payloads regardless of declared content type, for 204 and 205 responses
        if ( $statuscode == '204' || $statuscode == '205' )
        {
            if ( $stream == '' && ( !isset( $headers['content-length'] ) || $headers['content-length'] == 0 ) )
            {
                $this->Value = null;
                return;
            }
            else
            {
                /// @todo this is not valid according to rfc 2616 - but we should leave that control to client really
                $this->IsFault = true;
                $this->FaultCode = ggRESTResponse::INVALIDRESPONSEERROR;
                $this->FaultString = ggRESTResponse::INVALIDRESPONSESTRING . " (received http response 204/205 with a body. Not valid http)";
            }
        }

        /// @todo take into account charset when decoding json / xml

        switch( $this->mimeTypeToEncodeType( $contentType ) )
        {
            case 'json':
            case 'application/json':
                $val = json_decode( $stream, true );
                if ( function_exists( 'json_last_error' ) )
                {
                    $err = json_last_error();
                }
                else
                {
                    $err = ( $val === null ) ? 1 : false;
                }
                if ( $err )
                {
                    $this->IsFault = true;
                    $this->FaultCode = ggRESTResponse::INVALIDRESPONSEERROR;
                    $this->FaultString = ggRESTResponse::INVALIDRESPONSESTRING . ' json. Decoding error: ' . $err;
                }
                else
                {
                    $this->Value = $val;
                }
                break;
            case 'xml':
            case 'text/xml':
            case 'application/xml':
                try
                {
                    $doc = new DOMDocument();
                    $prev = libxml_use_internal_errors( true );
                    libxml_clear_errors();
                    $doc->loadXML( $stream );
                    $node = $doc->documentElement;
                    if ( $node == null )
                    {
                        $errors = libxml_get_errors();
                        libxml_use_internal_errors( $prev );
                        $errorText = '';
                        foreach( $errors as $error)
                        {
                            if ( $error->level > LIBXML_ERR_WARNING )
                            {
                                $errorText .= trim ( $error->message ) . ", line: $error->line" . " column: $error->column\n";
                            }
                        }
                        throw new Exception( $errorText );
                    }
                    libxml_use_internal_errors( $prev );
                    $this->Value = new ggSimpleTemplateXML( $node );

                }
                catch ( Exception $e )
                {
                    $this->IsFault = true;
                    $this->FaultCode = ggRESTResponse::INVALIDRESPONSEERROR;
                    $this->FaultString = ggRESTResponse::INVALIDRESPONSESTRING . ' xml. ' . $e->getMessage();
                }
                break;
            case 'text/plain':
            case 'text/html':
                $this->Value = $stream;
                break;
            default:
                $this->IsFault = true;
                $this->FaultCode = ggRESTResponse::INVALIDRESPONSEERROR;
                $this->FaultString = ggRESTResponse::INVALIDRESPONSESTRING . " (unsupported format $contentType)";
        }
    }
608782
function getStream()
    {
        if ($err = $this->getError() !== UPLOAD_ERR_OK)
            // TODO Handle Upload With Exception Error
            throw new \RuntimeException(sprintf(
                'Cannot retrieve stream due to upload error. error: (%s).'
                , getUploadErrorMessageFromCode($err)
            ));

        if ($this->isFileMoved)
            throw new \RuntimeException('Cannot retrieve stream after it has already been moved');

        if ($this->stream)
            return $this->stream;

        $givenFileResource = $this->_c_givenResource;
        if (!$givenFileResource instanceof StreamInterface)
            $givenFileResource = new Stream($givenFileResource, 'r');
        
        return $this->stream = $givenFileResource;
    }
507038
def stream_decode_gzip(iterator):
    """"""
    try:
        dec = zlib.decompressobj(16 + zlib.MAX_WBITS)
        for chunk in iterator:
            rv = dec.decompress(chunk)
            if rv:
                yield rv
        buf = dec.decompress('')
        rv = buf + dec.flush()
        if rv:
            yield rv
    except zlib.error:
        pass
329197
function decodeStream( $request, $stream, $headers=false, $cookies=array(), $statuscode="200"  )
    {
        $this->decodeStreamCommon( $request, $stream, $headers, $cookies, $statuscode );

        /// @todo refuse bad content-types?

        $results = json_decode( $stream, true );
        if ( !is_array($results) ||
            !array_key_exists( 'result', $results ) ||
            !array_key_exists( 'error', $results ) ||
            !array_key_exists( 'id', $results )
            )
        {
            // invalid jsonrpc response
            $this->IsFault = true;
            $this->FaultCode = self::INVALIDRESPONSEERROR;
            $this->FaultString = self::INVALIDRESPONSESTRING;
        }
        else
        {
            $this->Id =  $results['id'];

            /// we should check if id of response is same as id of request, and raise error if not
            if ( $results['id'] != $request->id() )
            {
                $this->IsFault = true;
                $this->FaultCode = self::INVALIDIDERROR;
                $this->FaultString = self::INVALIDIDSTRING;
            }
            else if ( $results['error'] === null )
            {
                /// NB: spec is formally strange: what if both error and result are null???

                $this->Value = $results['result'];
            }
            else
            {
                $this->IsFault = true;
                $error = $results['error'];
                if ( is_array( $error ) && array_key_exists( 'faultCode', $error ) && array_key_exists( 'faultString', $error ) )
                {
                    // since server conforms to our error syntax, we force the types on him, too
                    $this->FaultCode = (int)$error['faultCode'];
                    $this->FaultString = (string)$error['faultString'];
                }
                else
                {
                    $this->FaultCode = self::GENERICRESPONSEERROR;
                    /// @todo we should somehow typecast to string here??? maybe reencode as json?
                    $this->FaultString = $results['error'];
                }
            }
        }
    }
94673
public function getContents() : string
    {
        $r = false;
        $err = ($this->stream === null || $this->readable === false);

        if ($err === false) {
            $r = stream_get_contents($this->stream);
        }

        if ($err === true || $r === false) {
            // @codeCoverageIgnoreStart
            throw new \RuntimeException("Could not get contents of stream.");
            // @codeCoverageIgnoreEnd
        }

        return $r;
    }
1197403
public function data() : string
    {
        $code = $this->response->getStatusCode();

        if ($code >= 400 && $code < 600) {
            throw new ErrorResponseException($this->response->getReasonPhrase(), $code);
        }

        return $this->payload();
    }
709399
private function getStream()
    {
        if ($this->stream && get_resource_type($this->stream) === 'Unknown') {
            fclose($this->stream);
            $this->stream = null;
        }
        if (!$this->stream) {
            $this->stream = @fopen($this->streamUrl, 'a');
            if (!$this->stream) {
                LoggerPolicy::processIOError("Error open $this->streamUrl");
                $this->stream = null;
            }
        }

        return $this->stream;
    }
897693
public String getDescription() {
        if (description != null) {
            return description;
        }
        if (UNKNOWN_ERROR.equals(getCode())) {
            return String.format("Received error with code %s", getCode());
        }
        return "Failed with unknown error";
    }
1151829
HttpResponse validateAndStoreSpans(SpanBytesDecoder decoder, byte[] serializedSpans) {
    // logging already handled upstream in UnzippingBytesRequestConverter where request context exists
    if (serializedSpans.length == 0) return HttpResponse.of(HttpStatus.ACCEPTED);
    try {
      SpanBytesDecoderDetector.decoderForListMessage(serializedSpans);
    } catch (IllegalArgumentException e) {
      metrics.incrementMessagesDropped();
      return HttpResponse.of(
        BAD_REQUEST, MediaType.PLAIN_TEXT_UTF_8, "Expected a " + decoder + " encoded list\n");
    }

    SpanBytesDecoder unexpectedDecoder = testForUnexpectedFormat(decoder, serializedSpans);
    if (unexpectedDecoder != null) {
      metrics.incrementMessagesDropped();
      return HttpResponse.of(
        BAD_REQUEST, MediaType.PLAIN_TEXT_UTF_8,
        "Expected a " + decoder + " encoded list, but received: " + unexpectedDecoder + "\n");
    }

    CompletableCallback result = new CompletableCallback();
    List<Span> spans = new ArrayList<>();
    if (!decoder.decodeList(serializedSpans, spans)) {
      throw new IllegalArgumentException("Empty " + decoder.name() + " message");
    }
    collector.accept(spans, result);
    return HttpResponse.from(result);
  }
1014323
public String getErrorMessage ()
    {
        String msg = getMessage();
        return String.valueOf(_errorCode).equals(msg) ? null : msg;
    }
921508
def catch_gzip_errors(f):
    
    def new_f(self, *args, **kwargs):
        try:
            return f(self, *args, **kwargs)
        except requests.exceptions.ContentDecodingError as e:
            log.warning("caught gzip error: %s", e)
            self.connect()
            return f(self, *args, **kwargs)
    return new_f
1369668
@GET
    public Response getStreamContents() {

        // Intercept all output
        StreamingOutput stream = new StreamingOutput() {

            @Override
            public void write(OutputStream output) throws IOException {
                try {
                    tunnel.interceptStream(streamIndex, output);
                }
                catch (GuacamoleException e) {
                    throw new IOException(e);
                }
            }

        };

        // Begin successful response
        ResponseBuilder responseBuilder = Response.ok(stream, mediaType);

        // Set Content-Disposition header for "application/octet-stream"
        if (mediaType.equals(MediaType.APPLICATION_OCTET_STREAM))
            responseBuilder.header("Content-Disposition", "attachment");

        return responseBuilder.build();

    }