zekai-li commented on code in PR #21675:
URL: https://github.com/apache/flink/pull/21675#discussion_r1105606819


##########
pom.xml:
##########
@@ -1500,6 +1500,8 @@ under the License.
                         
<exclude>flink-formats/flink-avro/src/test/resources/flink_11-kryo_registrations</exclude>
                                                
<exclude>flink-scala/src/test/resources/flink_11-kryo_registrations</exclude>
                                                
<exclude>flink-core/src/test/resources/kryo-serializer-config-snapshot-v1</exclude>
+                                               
<exclude>flink-core/src/test/resources/abstractID-with-toString-field</exclude>
+                                               
<exclude>flink-core/src/test/resources/abstractID-with-toString-field-set</exclude>

Review Comment:
       public static boolean isBinary(InputStream in) {
           try {
               byte[] taste = new byte[200];
               int bytesRead = in.read(taste);
               if (bytesRead > 0) {
                   ByteBuffer bytes = ByteBuffer.wrap(taste, 0, bytesRead);
                   CharBuffer chars = CharBuffer.allocate(2 * bytesRead);
                   CharsetDecoder cd = 
CHARSET_FROM_FILE_ENCODING_OR_UTF8.newDecoder()
                           .onMalformedInput(CodingErrorAction.REPORT)
                           .onUnmappableCharacter(CodingErrorAction.REPORT);
                   while (bytes.remaining() > 0) {
                       CoderResult res = cd.decode(bytes, chars, true);
                       if (res.isMalformed() || res.isUnmappable()) {
                           return true;
                       } else if (res.isOverflow()) {
                           chars.limit(chars.position());
                           chars.rewind();
                           int c = chars.capacity() * 2;
                           CharBuffer on = CharBuffer.allocate(c);
                           on.put(chars);
                           chars = on;
                       }
                   }
                   chars.limit(chars.position());
                   chars.rewind();
                   return isBinary(chars);
               }
           } catch (IOException e) {
               // SWALLOW 
           }
           return false;
       }
   
       static Charset getFileEncodingOrUTF8AsFallback() {
           try {
               return Charset.forName(System.getProperty(FILE_ENCODING));
           } catch (UnsupportedCharsetException e) {
               return Charset.forName("UTF-8");
           }
       }
   This is the code of rat-plugin to check whether the file is binary file. I 
doubt that it should be checked out in UNIx-like system, but on windows, the 
check is non-binary file, the specific class is in 
org.apache.rat.document.impl.guesser.BinaryGuesser



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

Reply via email to