Class FileContentTypes

java.lang.Object
dev.frostlake.functions.scalar.file.FileContentTypes

public final class FileContentTypes extends Object
The two lookup tables behind the FILE family, both measured against a live Snowflake account on rather than inferred from the function names.

1. Extension → CONTENT_TYPE. TO_FILE derives a staged file's CONTENT_TYPE from its FILE NAME EXTENSION ALONE — never from its bytes. The decisive live pair: a file holding real PNG bytes named png_named.txt reports text/plain, while a file holding plain text named text_named.png reports image/png. Anything whose extension is not in the table below — including a name with no extension at all — is application/octet-stream (measured for noext, .bz2, .avro, .orc, .parquet, .woff2 and .yaml).

2. CONTENT_TYPE → category. FL_GET_FILE_TYPE and the five FL_IS_* predicates classify on the descriptor's CONTENT_TYPE — not on the path, not on the bytes. Proven live by feeding TRY_TO_FILE a hand-built descriptor whose RELATIVE_PATH and CONTENT_TYPE disagree: ('x.txt', 'image/png') classifies image and ('x.png', 'text/plain') classifies document.

The category tables are CLOSED EXACT-MATCH SETS — emphatically not a image/* style prefix rule, and not case- or whitespace-insensitive. Every one of these was measured: image/x-bogus, video/x-bogus, audio/x-bogus, text/x-bogus and application/x-bogus are all unknown; so are IMAGE/PNG (wrong case), " image/png" / "image/png " (untrimmed) and application/gzip;charset=utf-8 (parameters not stripped). Within a family, membership is arbitrary and must not be guessed: audio/mpeg is audio but audio/mp4 is unknown; text/plain is a document but text/tab-separated-values is unknown; application/gzip is compressed but application/x-gzip is unknown; application/zip is compressed but application/x-7z-compressed is unknown.

The sets also OVERLAP. video/x-msvideo (an .avi file) is in BOTH the video and the audio set — live, FL_IS_VIDEO and FL_IS_AUDIO are both TRUE for it while FL_GET_FILE_TYPE answers video. So FL_IS_x(f) is NOT FL_GET_FILE_TYPE(f) = 'x': each predicate is its own membership test, and FL_GET_FILE_TYPE resolves the tie by checking image, then video, then audio, then document, then compressed.

A content type absent from every set — and a NULL content type — is unknown, with all five predicates FALSE.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    FL_GET_FILE_TYPE for anything in no category, and for a NULL file or content type.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Map<String,String>
    The measured extension table, for the test that pins it.
    static String
    fileType(String contentType)
    FL_GET_FILE_TYPE: the single category name for a content type — image, video, audio, document, compressed or unknown.
    static String
    forPath(String relativePath)
    The CONTENT_TYPE Snowflake reports for a staged file with this relative path — from the extension only, application/octet-stream when the extension is unknown or absent.
    static boolean
    isAudio(String contentType)
    FL_IS_AUDIO's membership test — includes video/x-msvideo, see the class note.
    static boolean
    isCompressed(String contentType)
    FL_IS_COMPRESSED's membership test — note application/x-gzip is NOT in it.
    static boolean
    isDocument(String contentType)
    FL_IS_DOCUMENT's membership test — exact match against the measured document set.
    static boolean
    isImage(String contentType)
    FL_IS_IMAGE's membership test — exact match against the measured image set.
    static boolean
    isVideo(String contentType)
    FL_IS_VIDEO's membership test — exact match against the measured video set.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • UNKNOWN

      public static final String UNKNOWN
      FL_GET_FILE_TYPE for anything in no category, and for a NULL file or content type.
      See Also:
  • Method Details

    • forPath

      public static String forPath(String relativePath)
      The CONTENT_TYPE Snowflake reports for a staged file with this relative path — from the extension only, application/octet-stream when the extension is unknown or absent.
      Parameters:
      relativePath - the file's path within its stage
      Returns:
      the content type, never null
    • fileType

      public static String fileType(String contentType)
      FL_GET_FILE_TYPE: the single category name for a content type — image, video, audio, document, compressed or unknown. Checked in that order, which is what makes an .avi (in both the video and audio sets) a video.
      Parameters:
      contentType - the descriptor's CONTENT_TYPE, may be null
      Returns:
      the category name, never null
    • isImage

      public static boolean isImage(String contentType)
      FL_IS_IMAGE's membership test — exact match against the measured image set.
    • isVideo

      public static boolean isVideo(String contentType)
      FL_IS_VIDEO's membership test — exact match against the measured video set.
    • isAudio

      public static boolean isAudio(String contentType)
      FL_IS_AUDIO's membership test — includes video/x-msvideo, see the class note.
    • isDocument

      public static boolean isDocument(String contentType)
      FL_IS_DOCUMENT's membership test — exact match against the measured document set.
    • isCompressed

      public static boolean isCompressed(String contentType)
      FL_IS_COMPRESSED's membership test — note application/x-gzip is NOT in it.
    • extensionTable

      public static Map<String,String> extensionTable()
      The measured extension table, for the test that pins it.