Read stream into string

@param postResponse
The response to get the body from.

@return The response body.
169281
private String getResponseBody(HttpResponse postResponse) {
        InputStream input = null;
        try {
            input = postResponse.getEntity().getContent();
            Reader reader = new InputStreamReader(input,
                    MwsUtl.DEFAULT_ENCODING);
            StringBuilder b = new StringBuilder();
            char[] c = new char[1024];
            int len;
            while (0 < (len = reader.read(c))) {
                b.append(c, 0, len);
            }
            return b.toString();
        } catch (Exception e) {
            throw MwsUtl.wrap(e);
        } finally {
            MwsUtl.close(input);
        }
    }
1257865
private function read(): string
    {
        $this->lastResponse = fread($this->stream, 1024); // Read up to 1KB
        $this->lastResponseCode = intval(explode(" ", $this->lastResponse)[0]);
        $this->lastResponseCode = $this->lastResponseCode > 0 ? $this->lastResponseCode : -1;
        return $this->lastResponse;
    }
790799
private static String[] parseResponseHeader(InputStream pIS) throws IOException {
        List<String> headers = new ArrayList<String>();

        // Wrap Stream in Reader
        BufferedReader in = new BufferedReader(new InputStreamReader(pIS));

        // Get response status
        String header;

        while ((header = in.readLine()) != null) {
            //System.err.println(header);
            headers.add(header);
        }
        return headers.toArray(new String[headers.size()]);
    }
288715
public static String postFrom(
                    final URL to_url,
                    final InputStream from_stream,
                    final MediaType media_type
                    )
    {
        InputStreamRequestCallback  callback =
                        new InputStreamRequestCallback( from_stream, media_type );
        String  location = _execute( to_url, HttpMethod.POST, callback,
                        new LocationHeaderResponseExtractor() );

        return location;
    }
1285377
private static String inputStreamToString(InputStream stream)
			throws IOException {
		ByteArrayOutputStream result = new ByteArrayOutputStream();
		byte[] buffer = new byte[1024];
		int length;
		String resultString = null;
		while ((length = stream.read(buffer)) != -1) {
			result.write(buffer, 0, length);
		}
		resultString = result.toString("UTF-8");
		return resultString;
	}
747248
private String response(HttpURLConnection connection) throws LightblueHttpClientException {
        try (InputStream responseStream = connection.getInputStream()) {
            return readResponseStream(responseStream, connection);
        } catch (IOException e) {
            return readErrorStream(connection,e);
        }
    }
552731
private byte[] readRequestBody() {
        int bytesLeft = m_request.getContentLength();
        if (bytesLeft <= 0) {
            return new byte[0];
        }

        int totalBytesRead = 0;
        try {
            byte[] byteBuffer = new byte[bytesLeft];
            try (InputStream inputStream = m_request.getInputStream()) {
                int bytesRead = -1;
                int offset = 0;
                while ((bytesRead = inputStream.read(byteBuffer, offset, bytesLeft)) > 0) {
                    offset += bytesRead;
                    bytesLeft -= bytesRead;
                    totalBytesRead += bytesRead;
                }
            }
            return byteBuffer;
        } catch (IOException e) {
            String errMsg =
                String.format("Error reading from input request; expected %d bytes; only read %d bytes",
                              m_request.getContentLength(), totalBytesRead);
            throw new RuntimeException(errMsg, e);
        }
    }
507991
def from_post_response(post_response, content):
        '''
        
        '''
        response = OutcomeResponse()
        response.post_response = post_response
        response.response_code = post_response.status
        response.process_xml(content)
        return response
735677
private static String getResponseStringData(InputStream is, String charset) throws IOException {
    ByteArrayOutputStream respDataStream = new ByteArrayOutputStream();
    String result;
    try {
      byte[] b = new byte[8192];
      int len;
      while (true) {
        len = is.read(b);
        if (len <= 0) {
          is.close();
          break;
        }
        respDataStream.write(b, 0, len);
      }
      result = respDataStream.toString(charset);
    } finally {
      respDataStream.close();
    }
    return result;
  }
639800
private Response readResponse() throws IOException {
		Response response = new Response();
		response.setResponseCode(connection.getResponseCode());
		response.setResponseMessage(connection.getResponseMessage());
		response.setHeaders(connection.getHeaderFields());
		try {
			response.setBody(getStringFromStream(connection.getInputStream()));
		} catch (IOException e) {
			response.setBody(getStringFromStream(connection.getErrorStream()));
		}
		return response;
	}
706662
public static String readInputStreamToString( InputStream inputStream ) {

        try {
            // Create the byte list to hold the data
            List<Byte> bytesList = new ArrayList<Byte>();

            byte b = 0;
            while( (b = (byte) inputStream.read()) != -1 ) {
                bytesList.add(b);
            }
            // Close the input stream and return bytes
            inputStream.close();

            byte[] bArray = new byte[bytesList.size()];
            for( int i = 0; i < bArray.length; i++ ) {
                bArray[i] = bytesList.get(i);
            }

            String file = new String(bArray);
            return file;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
1056925
protected String readString(InputStream in) throws IOException {
        int length = readInt(in);
        if (length < 0) {
            return null;
        } else if (length == 0) {
            return StringUtils.EMPTY;
        } else {
            byte[] value = new byte[length];
            in.read(value);
            return StringSerializer.decode(value);
        }
    }
504376
private RESTResponse readResponse() throws IOException {
        // Read response code from the header line.
        HttpCode resultCode = readStatusLine();
        
        // Read and save headers, keeping track of content-length if we find it.
        Map<String, String> headers = new HashMap<String, String>();
        int contentLength = 0;
        String headerLine = readHeader();
        while (headerLine.length() > 2) {
            // Read header and split into parts based on ":" separator. Both parts are
            // trimmed, and the header is up-cased.
            int colonInx = headerLine.indexOf(':');
            String headerName =     // Use the whole line if there's no colon
                colonInx <= 0 ? headerLine.trim().toUpperCase()
                              : headerLine.substring(0, colonInx).trim().toUpperCase();
            String headerValue =    // Use an empty string if there's no colon
                colonInx <= 0 ? "" : headerLine.substring(colonInx + 1).trim();
            headers.put(headerName, headerValue);
            if (headerName.equals(HttpDefs.CONTENT_LENGTH)) {
                try {
                    contentLength = Integer.parseInt(headerValue);
                } catch (NumberFormatException e) {
                    // Turn into IOException
                    throw new IOException("Invalid content-length value: " + headerLine);
                }
            }
            headerLine = readHeader();
        }

        // Final header line should be CRLF
        if (!headerLine.equals("\r\n")) {
            throw new IOException("Header not properly terminated: " + headerLine);
        }
        
        // If we have a response entity, read that now.
        byte[] body = null;
        if (contentLength > 0) {
            body = readBody(contentLength);
            
            // Decompress output entity if needed.
            String contentEncoding = headers.get(HttpDefs.CONTENT_ENCODING);
            if (contentEncoding != null) {
                Utils.require(contentEncoding.equalsIgnoreCase("gzip"),
                              "Unrecognized output Content-Encoding: " + contentEncoding);
                body = Utils.decompressGZIP(body);
            }
        }
        return new RESTResponse(resultCode, body, headers);
    }
501836
public Observable<HttpClientResponse<ByteBuf>>
  postSmile(String uriStr, JsonPayload payload) {
    byte[] entity = toByteArray(SMILE_FACTORY, payload);
    URI uri = URI.create(uriStr);
    return rxHttp.post(uri, SMILE_CONTENT_TYPE, entity);
  }
298598
public HttpClientResponseBuilder doReturn(int statusCode, String response) {
        return doReturn(statusCode, response, Charset.forName("UTF-8"));
    }
974797
void parseNextResponse() throws IOException {
    contentId++;

    // Extract the outer headers.
    String line;
    while ((line = readLine()) != null && !line.equals("")) {
      // Do nothing.
    }

    // Extract the status code.
    String statusLine = readLine();
    String[] statusParts = statusLine.split(" ");
    int statusCode = Integer.parseInt(statusParts[1]);

    // Extract and store the inner headers.
    // TODO(rmistry): Handle inner headers that span multiple lines. More details here:
    // http://tools.ietf.org/html/rfc2616#section-2.2
    List<String> headerNames = new ArrayList<String>();
    List<String> headerValues = new ArrayList<String>();
    long contentLength = -1L;
    while ((line = readLine()) != null && !line.equals("")) {
      String[] headerParts = line.split(": ", 2);
      String headerName = headerParts[0];
      String headerValue = headerParts[1];
      headerNames.add(headerName);
      headerValues.add(headerValue);
      if ("Content-Length".equalsIgnoreCase(headerName.trim())) {
          contentLength = Long.parseLong(headerValue);
      }
    }

    InputStream body;
    if (contentLength == -1) {
      // This isn't very efficient, but most respectable servers should set the Content-Length
      ByteArrayOutputStream buffer = new ByteArrayOutputStream();
      while ((line = readRawLine()) != null && !line.startsWith(boundary)) {
        // Convert characters back to bytes:
        buffer.write(line.getBytes("ISO-8859-1"));
      }

      // Remove CRLF that separates body from boundary token
      body = trimCrlf(buffer.toByteArray());

      // Remove CRLF from the boundary token (to match readLine)
      line = trimCrlf(line);
    } else {
      body = new FilterInputStream(ByteStreams.limit(inputStream, contentLength)) {
        @Override
        public void close() {
          // Don't allow the parser to close the underlying stream
        }
      };
    }

    HttpResponse response =
        getFakeResponse(statusCode, body, headerNames, headerValues);

    parseAndCallback(requestInfos.get(contentId - 1), statusCode, response);

    // Consume any bytes that were not consumed by the parser
    while (body.skip(contentLength) > 0 || body.read() != -1) {
    }

    if (contentLength != -1) {
      line = readLine();
    } else {
      // The line was already read
    }
    // Consume any blank lines that follow the response (not included in Content-Length)
    while ((line != null) && (line.length() == 0)) {
      line = readLine();
    }

    checkForFinalBoundary(line);
  }
695063
public static String parseHttpResponse(HttpURLConnection conn, boolean includeHeaders, boolean ignoreBody) throws IOException {
        StringBuilder buff = new StringBuilder();
        if (includeHeaders) {
            buff.append(conn.getResponseCode()).append(' ').append(conn.getResponseMessage()).append('\n');
            int idx = (conn.getHeaderFieldKey(0) == null) ? 1 : 0;
            while (true) {
                String key = conn.getHeaderFieldKey(idx);
                if (key == null) {
                    break;
                }
                buff.append(key).append(": ").append(conn.getHeaderField(idx)).append('\n');
                ++idx;
            }
        }

        StreamManager sm = new StreamManager();

        try {
            if (!ignoreBody) {
                BufferedReader in = (BufferedReader) sm.handle(new BufferedReader(new InputStreamReader(conn.getInputStream())));
                String inputLine;
                while ((inputLine = in.readLine()) != null) {
                    buff.append(inputLine);
                }
                in.close();
            }
        } finally {
            sm.closeAll();
        }
        return buff.toString();
    }