code: private static void format(List<FileResource<?>> fileResourceList, Properties formatProfile)
     {
        for (FileResource<?> fileResource : fileResourceList)
        {
           if (fileResource.isDirectory())
           {
              List<FileResource<?>> newFileResourceList = new ArrayList<>();
              List<Resource<?>> resourceList = fileResource.listResources();
  
              for (Resource<?> resource : resourceList)
                 newFileResourceList.add(resource.reify(FileResource.class));
  
              format(newFileResourceList, formatProfile);
           }
           else if (fileResource instanceof JavaResource)
           {
              JavaResource file = fileResource.reify(JavaResource.class);
              file.setContents(fileResource.getResourceInputStream(), formatProfile);
           }
        }
  
     }
docs: Formatting the file or folder(recursively).