wozhenbang2004 opened a new pull request, #943:
URL: https://github.com/apache/commons-io/pull/943
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
Addresses [IO-342](https://issues.apache.org/jira/browse/IO-342).
Add `ByteOrderMark.getCharset()` and `BOMInputStream.getBOMCharset()`, so
callers can use the detected charset directly with a reader. The stream getter
returns null when no BOM matches and does not consume additional bytes.
Charset lookup happens on first use. Custom BOMs with illegal or unsupported
names remain constructible; the new getters report the corresponding
`Charset.forName()` exception when called. The cached charset is transient and
is resolved again after deserialization, as requested in the issue discussion.
Existing name getters and BOM inclusion behavior stay unchanged.
A standalone consumer decodes UTF-8, UTF-16 and UTF-32 files through the new
API, including both byte orders and an explicit fallback for a file without a
BOM. Serializing a BOM after filling its cache produces exactly the same bytes
as the base, and the base and patch can read each other's serialized form.
Validation: the [complete default Maven
build](https://github.com/wozhenbang2004/contribution-validation/actions/runs/45234511300)
passes on JDK 21, including tests, coverage and the required checks. The run
pins this PR commit and checks the five changed file hashes.
### Contribution checklist
- [x] Read the [contribution guidelines](CONTRIBUTING.md) for this project.
- [x] Read the [ASF Generative Tooling
Guidance](https://www.apache.org/legal/generative-tooling.html) if you use
Artificial Intelligence (AI).
- [x] I used AI to create part or all of this pull request. OpenAI ChatGPT
generated the implementation, tests, release note and PR draft, and ran the
local verification. A separate ChatGPT agent reviewed the patch and exercised
independent cases.
- [x] Run a successful build using the default Maven goal with `mvn`.
- [x] Write unit tests matching behavioral changes. These are new APIs,
absent from the base.
- [x] Write a detailed pull request description.
- [x] Each commit has a meaningful subject and body.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]