@VisibleForTesting public static boolean isPlaintext(Buffer buffer) throws EOFException {
  try {
    Buffer prefix=new Buffer();
    long byteCount=buffer.size() < 64 ? buffer.size() : 64;
    buffer.copyTo(prefix,0,byteCount);
    for (int i=0; i < 16; i++) {
      if (prefix.exhausted()) {
        break;
      }
      int codePoint=prefix.readUtf8CodePoint();
      if (Character.isISOControl(codePoint) && !Character.isWhitespace(codePoint)) {
        return false;
      }
    }
    return true;
  }
 catch (  EOFException e) {
    return false;
  }
}

@ VisibleForTesting public static boolean isPlaintext ( Buffer buffer ) throws EOFException { try { Buffer prefix = new Buffer ( ) ; long byteCount = buffer . size ( ) < 64 ? buffer . size ( ) : 64 ; buffer . copyTo ( prefix , 0 , byteCount ) ; for ( int i = 0 ; i < 16 ; i ++ ) { if ( prefix . exhausted ( ) ) { break ; } int codePoint = prefix . readUtf8CodePoint ( ) ; if ( Character . isISOControl ( codePoint ) && ! Character . isWhitespace ( codePoint ) ) { return false ; } } return true ; } catch ( EOFException e ) { return false ; } }
returns true if the body in question probably contains human readable text . uses a small sample of code points to detect unicode control characters commonly used in binary file signatures .
