code: public static String fromStream(InputStream stream) throws IOException {
  		if (stream != null) {			
  			try {
  				Writer writer = new StringWriter();
  				Reader reader = new BufferedReader(new InputStreamReader(stream));
  				int read;
  				while ((read = reader.read()) != -1) {
  					writer.write(read);
  				}
  				return writer.toString();
  			} finally {
  				try {
  					stream.close();
  				} catch(IOException e) {
  					logger.warn("error closing the input stream", e);
  				}
  			}			
  		}
  		return null;
  	}
docs: Reads from the given input stream into a String, and returns it.
  
  @param stream
  the input stream; when the method completes the stream will be closed.
  @return
  the data read from the stream as a string, or {@code null}. if the input
  stream is not valid.