Uploaded image for project: 'Commons IO'
  1. Commons IO
  2. IO-318

Add Charset sister APIs to method that take a String charset name.

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 2.3
    • None
    • None

    Description

      Add Charset sister APIs to method that take a String charset name (aka encoding).
      For example: foo(..., String charsetName) -> foo(..., Charset charset).
      Refactor such that we do not have code duplication of the algorithms.

      Known issue: Source compatibility.

      Now there are APIs that change only with the last type, String vs. Charset, you will get a compile error if you pass null to the old String API because the target method will be ambiguous: do you want to call the String or Charset version? You must type-cast to one type or the other.

      Known issue: checked java.io.UnsupportedEncodingException vs. unchecked java.nio.charset.UnsupportedCharsetException

      The JRE API Charset.forName throws the unchecked UnsupportedCharsetException.
      The Commons IO 2.2 String APIs throw the checked UnsupportedEncodingException, a subclass of IOException, when a charset is not available.
      The refactored String APIs throw UnsupportedCharsetException from Charset.forName, an unchecked IllegalArgumentException. The String APIs throw IOException, so there is no source compatibility issue.

      If you somehow relied on catching the checked UnsupportedEncodingException instead of IOException, its superclass, you should catch the unchecked java.nio.charset.UnsupportedCharsetException to act on the fact that the charset is not available.

      Attachments

        Activity

          People

            Unassigned Unassigned
            ggregory Gary D. Gregory
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: