code: public static InputStream filterUtf8ResourceStream(InputStream stream, Function<String, String> transformation) {
  
          try {
              byte[] streamData = CmsFileUtil.readFully(stream);
              String dataAsString = new String(streamData, "UTF-8");
              byte[] transformedData = transformation.apply(dataAsString).getBytes("UTF-8");
              return new ByteArrayInputStream(transformedData);
          } catch (UnsupportedEncodingException e) {
              LOG.error(e.getLocalizedMessage(), e);
              return null;
          } catch (IOException e) {
              LOG.error(e.getLocalizedMessage(), e);
              throw new RuntimeException(e);
          }
      }
docs: Reads the content of an input stream into a string (using UTF-8 encoding), performs a function on the string, and returns the result
  again as an input stream.<p>
  
  @param stream the stream producing the input data
  @param transformation the function to apply to the input
  
  @return the stream producing the transformed input data