Skip to content

优化 data URI 支持#4206

Merged
Glavo merged 3 commits intoHMCL-dev:mainfrom
Glavo:data-url
Aug 6, 2025
Merged

优化 data URI 支持#4206
Glavo merged 3 commits intoHMCL-dev:mainfrom
Glavo:data-url

Conversation

@Glavo
Copy link
Copy Markdown
Member

@Glavo Glavo commented Aug 6, 2025

No description provided.

@Glavo Glavo requested a review from Copilot August 6, 2025 08:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR optimizes data URI support by restructuring the data URI handling code and integrating it with Java's URL stream handler system. The changes move data URI classes to a dedicated package, add proper URL stream handling, and integrate with Java's service provider interface.

  • Reorganized data URI classes from util.io to dedicated util.url.data package
  • Implemented URL stream handler for data URIs with proper URLConnection support
  • Added service provider registration for custom URL stream handler

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
DataUriTest.java Updated package declaration and import to reflect new package structure
URLStreamHandlerProvider Added service provider registration for HMCL URL stream handler
DataUri.java Moved to new package and added import for NetworkUtils
DataURLHandle.java New URL stream handler implementation for data URIs
DataURLConnection.java New URLConnection implementation for data URI content access
HMCLURLStreamHandlerProvider.java New service provider for custom URL stream handlers
Comments suppressed due to low confidence (1)

}

@Override
public int getContentLength() {
Copy link

Copilot AI Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The getContentLength() method may return incorrect values when called before connect(). The data field is only initialized in connect(), so calling getContentLength() before connecting will always return -1 even if the data URI contains valid data.

Suggested change
public int getContentLength() {
public int getContentLength() {
try {
connect();
} catch (IOException e) {
return -1;
}

Copilot uses AI. Check for mistakes.
Comment on lines +31 to +33
switch (protocol) {
case "data":
return new DataURLHandle();
Copy link

Copilot AI Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider using a more modern approach like a Map or if-else statement instead of switch for a single case. The current switch statement with only one case is unnecessarily verbose.

Suggested change
switch (protocol) {
case "data":
return new DataURLHandle();
if ("data".equals(protocol)) {
return new DataURLHandle();

Copilot uses AI. Check for mistakes.
@Glavo Glavo merged commit 2c6ceb3 into HMCL-dev:main Aug 6, 2025
2 checks passed
@Glavo Glavo deleted the data-url branch August 6, 2025 08:48
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