matthiasblaesing commented on a change in pull request #2633:
URL: https://github.com/apache/netbeans/pull/2633#discussion_r552172582



##########
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;

Review comment:
       Quote from docu: "Every charset contains itself.", maybe better: `return 
this.equals(arg0)`

##########
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:
       I think reset and flush need to delegate to the "right" backing decoder. 
UTF-8 decoding could be stateful (if the input ByteBuffer contains only part of 
a multibytesequence, this state must be preseved) or is the caller expected to 
resubmit the whole buffer it an underrun is reported?




----------------------------------------------------------------
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

Reply via email to