code: private static String readerToString(Reader reader) throws IOException {
          StringWriter writer = new StringWriter();
          try {
              char[] buffer = new char[COPY_BUFFER_SIZE];
              while (true) {
                  int bytesRead = reader.read(buffer);
                  if (bytesRead == -1) {
                      break;
                  } else {
                      writer.write(buffer, 0, bytesRead);
                  }
              }
              return writer.toString();
          } finally {
              reader.close();
          }
      }
docs: Converts a Reader to a String by copying the Reader's contents into a StringWriter via a
  buffer.
  
  @param reader The Reader from which to extract a String.
  @return The String contained in the Reader.
  @throws IOException If there is an error reading from the input Reader.