Conversation
There was a problem hiding this comment.
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.ioto dedicatedutil.url.datapackage - 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() { |
There was a problem hiding this comment.
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.
| public int getContentLength() { | |
| public int getContentLength() { | |
| try { | |
| connect(); | |
| } catch (IOException e) { | |
| return -1; | |
| } |
| switch (protocol) { | ||
| case "data": | ||
| return new DataURLHandle(); |
There was a problem hiding this comment.
[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.
| switch (protocol) { | |
| case "data": | |
| return new DataURLHandle(); | |
| if ("data".equals(protocol)) { | |
| return new DataURLHandle(); |
No description provided.