May I suggest also explicitly checking magic bytes of file to guess if it's gzipped? FileTypeDetectordocs say it may only check file extension, which can be misleading when, for example, you create a temp file in your pipeline and that information is lost.
File type detection is different under newer versions of Java and this adds support for null detection and alternate MIME strings.