I wonder what use case InputSource
is there for? In other words, is there any situation where InputSource
can’t be replaced by StreamSource
? In still other words, why do these two classes exist in the JDK?
AFAICS: Both classes lie in the java.xml
module, and their APIs are almost identical, the only difference being that InputSource
has an “encoding” parameter; and that StreamSource
is part of a hierarchy (as it implements Source
), which makes it nicer to use in some contexts (you can decide to accept a Source
if that is enough for your purpose when designing your API). Furthermore, they both were introduced in Java 1.4.
As also pointed out here, these classes are used in different parts of the JDK API: “A Parser can take its input from an InputSource, but not from a StreamSource. A Transformer can take its input from a StreamSource, but not from an InputSource.” But this does not explain why the designers of the JDK API decided to introduce two apparently redundant classes for the purpose of representing a source. Hence, my question.
(Slightly related: difference between InputSource and InputStream.)