code: public static String getStringFromReader(Reader reader, boolean trim) throws IOException {
      BufferedReader bufferedReader = null;
      StringBuilder stringBuilder = new StringBuilder();
      try {
        bufferedReader = new BufferedReader(reader);
        String line;
        while ((line = bufferedReader.readLine()) != null) {
          if (trim) {
            stringBuilder.append(line.trim());
          } else {
            stringBuilder.append(line).append("\n");
          }
        }
      } finally {
        closeSilently(bufferedReader);
      }
  
      return stringBuilder.toString();
    }
docs: Convert an {@link Reader} to a {@link String}
  
  @param reader the {@link Reader} to convert
  @param trim trigger if whitespaces are trimmed in the output
  @return the resulting {@link String}
  @throws IOException