code: public static String copyAsString(final BufferedInputStream inputStream) throws IOException, IllegalStateException {
          if (inputStream == null) return null;
  
          try {
              inputStream.mark(Integer.MAX_VALUE);
              return new String(streamToBytes(inputStream, false));
          } finally {
              try {
                  inputStream.reset();
              } catch (IOException ioe) {
                  throw new IllegalStateException("Unable to reset stream - original stream content may be corrupted");
              }
          }
      }
docs: Safely copies the contents of the {@link BufferedInputStream} to a {@link String} and resets the stream.
  This method is generally only useful for testing and logging purposes.
  
  @param inputStream the BufferedInputStream
  @return a String copy of the stream contents
  @throws IOException           if something goes wrong with the stream
  @throws IllegalStateException if the stream cannot be reset