Hey, you can write an OSGi service that does the conversion of your files into the required format and you can consume this service in a Sling Servlet or Sling Model.
I find some code after here as an example in Java, check this: https://stackoverflow.com/questions/63706439/when-i-create-a-file-with-java-8-using-the-shift-jis-ch...
Also if you are new to AEM, more on OSGi services: https://experienceleague.adobe.com/docs/experience-manager-learn/cloud-service/developing/osgi-servi... and Sling Models here: https://sling.apache.org/documentation/bundles/models.html