matthiasblaesing commented on a change in pull request #2633:
URL: https://github.com/apache/netbeans/pull/2633#discussion_r553478217
##########
File path: platform/openide.util/src/org/openide/util/NbBundle.java
##########
@@ -1458,4 +1475,90 @@ public DebugInputStream(InputStream base, int id,
boolean localizable) {
}
}
+
+
+ /**
+ * Local charset to decode using UTF-8 by default, but automatically
switching to ISO-8859-1 if UTF-8 decoding fails.
+ *
+ */
+ static private class UtfThenIsoCharset extends Charset {
+
+ private final boolean onlyUTF8;
+
+ /**
+ *
+ * @param acceptOnlyUTF8 If true there is no automatic switch to
ISO-8859-1 if UTF-8 decoding fails.
+ */
+ public UtfThenIsoCharset(boolean acceptOnlyUTF8) {
+ super(UtfThenIsoCharset.class.getCanonicalName(), null);
+ this.onlyUTF8 = acceptOnlyUTF8;
+ }
+
+ @Override
+ public boolean contains(Charset arg0) {
+ return false;
+ }
+
+ @Override
+ public CharsetDecoder newDecoder() {
+ return new UtfThenIsoDecoder(this, 1.0f, 1.0f);
+ }
+
+ @Override
+ public CharsetEncoder newEncoder() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ private final class UtfThenIsoDecoder extends CharsetDecoder {
Review comment:
For the note: I hope you don't imply there is code in this, that was
copied from a foreign source (aka JDK). This would be invalid and would violate
the assumption, that you are the author of the code.
For my comment, please have a look at the top of the
https://docs.oracle.com/javase/8/docs/api/java/nio/charset/CharsetDecoder.html.
There the sequence is described, which methods should be invoked by callers.
The ISO-8859-1 and UTF-8 decoders might not have internal state, in that case
your overriders are ok, but if they have, they are invalid according to the
described call sequence.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists