Skip to content

Extract MIME-type mapping data into dedicated WellKnownMimeTypes class - #3399

Open
ChneYangOLP wants to merge 1 commit into
allure-framework:mainfrom
ChneYangOLP:main
Open

Extract MIME-type mapping data into dedicated WellKnownMimeTypes class#3399
ChneYangOLP wants to merge 1 commit into
allure-framework:mainfrom
ChneYangOLP:main

Conversation

@ChneYangOLP

Copy link
Copy Markdown

WellKnownFileExtensionsUtils.java contained ~1,312 lines of static m.put(...) data (ported from tika-core 2.9.1) mixed with ~70 lines of actual business logic, totaling 1,383 lines. This made the file difficult to read and maintain.

This PR extracts the pure extension-to-MIME-type mapping data into a new dedicated class WellKnownMimeTypes, reducing WellKnownFileExtensionsUtils from 1,383 lines to 67 lines.

Changes:

New file: WellKnownMimeTypes.java — a package-private data class holding the static Map<String, String> EXT_TO_MIME_TYPE with all ~1,312 m.put(...) entries.
Rewritten: WellKnownFileExtensionsUtils.java — now delegates EXT_TO_MIME_TYPE to WellKnownMimeTypes and builds MIME_TYPE_TO_EXT by inverting it. Introduced ALLURE_HTTP_EXCHANGE and OCTET_STREAM constants to eliminate magic strings. Removed the no-longer-needed @SuppressWarnings("MultipleStringLiterals") annotation.
All public API (EXT_TO_MIME_TYPE, MIME_TYPE_TO_EXT, lookup(), getExtensionByMimeType()) remains unchanged. No caller modifications required (DefaultResultsVisitor, Allure1Plugin, Allure2Plugin, WellKnownFileExtensionsUtilsTest all compile and work as before).
Verified with: ./gradlew :allure-generator:compileJava :allure-generator:compileTestJava — BUILD SUCCESSFUL

Checklist
Sign Allure CLA
Provide unit tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants