Check if the content of a byte array is binary
@param b byte array to check
@return true if the content is binary (Non-white Control Characters)
199669
public static boolean isNonWhitespaceControlCharacter(@NonNull byte[] b) {
        ByteBuffer head = ByteBuffer.allocate(DEFAULT_PROBE_SIZE);
        int toCopy = Math.min(head.remaining(), b.length);
        if (toCopy == 0) {
            throw new IllegalStateException("No more room to buffer header, should have chosen stream by now");
        }

        head.put(b, 0, toCopy);
        head.flip().mark();
        return isNonWhitespaceControlCharacter(head);
    }
683495
byte []readBinary()
    throws IOException
  {
    TempOutputStream tos = new TempOutputStream();
    
    while (true) {
      int ch = read();
      int len;
    
      switch (ch) {
      default:
        _peek = ch;
        return tos.toByteArray();
      
      case 0x20: case 0x21: case 0x22: case 0x23:
      case 0x24: case 0x25: case 0x26: case 0x27:
      case 0x28: case 0x29: case 0x2a: case 0x2b:
      case 0x2c: case 0x2d: case 0x2e: case 0x2f:
        len = ch - 0x20;
        readBinary(tos, len);
        return tos.toByteArray();
      
      case 0x34: case 0x35: case 0x36: case 0x37:
        len = ((ch - 0x34) << 8) + read();
        readBinary(tos, len);
        return tos.toByteArray();
        
      case 'B':
        len = readShort();
        readBinary(tos, len);
        return tos.toByteArray();
        
      case 'A':
        len = readShort();
        readBinary(tos, len);
        break;
      }
    }
  }
466102
function isFbxFormatBinary( buffer ) {

		var CORRECT = 'Kaydara FBX Binary  \0';

		return buffer.byteLength >= CORRECT.length && CORRECT === convertArrayBufferToString( buffer, 0, CORRECT.length );

	}
421073
public static boolean isBinaryExpressionType(Expression expression, String token) {
        if (expression instanceof BinaryExpression) {
            if (token.equals(((BinaryExpression) expression).getOperation().getText())) {
                return true;
            }
        }
        return false;
    }
226097
private boolean match(final ByteBuffer buf) throws IOException {
		boolean matches = true;
		switch (getType()) {
		case MagicMimeEntry.STRING_TYPE: {
			matches = matchString(buf);
			break;
		}

		case MagicMimeEntry.SHORT_TYPE: {
			matches = matchShort(buf, ByteOrder.BIG_ENDIAN, false, (short) 0xFF);
			break;
		}

		case MagicMimeEntry.LESHORT_TYPE:
		case MagicMimeEntry.BESHORT_TYPE: {
			ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
			if (getType() == MagicMimeEntry.LESHORT_TYPE) {
				byteOrder = ByteOrder.LITTLE_ENDIAN;
			}
			boolean needMask = false;
			short sMask = 0xFF;
			final int indx = this.typeStr.indexOf('&');
			if (indx >= 0) {
				sMask = (short) Integer.parseInt(this.typeStr.substring(indx + 3), 16);
				needMask = true;
			} else if (getContent().startsWith("&")) {
				sMask = (short) Integer.parseInt(getContent().substring(3), 16);
				needMask = true;
			}
			matches = matchShort(buf, byteOrder, needMask, sMask);
			break;
		}

		case MagicMimeEntry.LELONG_TYPE:
		case MagicMimeEntry.BELONG_TYPE: {
			ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
			if (getType() == MagicMimeEntry.LELONG_TYPE) {
				byteOrder = ByteOrder.LITTLE_ENDIAN;
			}
			boolean needMask = false;
			long lMask = 0xFFFFFFFF;
			final int indx = this.typeStr.indexOf('&');
			if (indx >= 0) {
				lMask = Long.parseLong(this.typeStr.substring(indx + 3), 16);
				needMask = true;
			} else if (getContent().startsWith("&")) {
				lMask = Long.parseLong(getContent().substring(3), 16);
				needMask = true;
			}
			matches = matchLong(buf, byteOrder, needMask, lMask);
			break;
		}

		case MagicMimeEntry.BYTE_TYPE: {
			matches = matchByte(buf);
		}

		default: {
			matches = false;
			break;
		}
		}
		return matches;
	}
662975
public static String bin2hex(final byte[] b)
    {
        if (b == null)
        {
            return "";
        }
        StringBuffer sb = new StringBuffer(2 * b.length);
        for (int i = 0; i < b.length; i++)
        {
            int v = (256 + b[i]) % 256;
            sb.append(hex.charAt((v / 16) & 15));
            sb.append(hex.charAt((v % 16) & 15));
        }
        return sb.toString();
    }
664465
public static boolean equal(byte[] a, byte[] b) {
       if (a == b)
          return (true);
       if ((a == null) || (b == null))
          return (false);
       if (a.length != b.length)
          return (false);
       for (int i = 0; i < a.length; i++)
          if (a[i] != b[i])
             return (false);
       return (true);
    }
69096
private static byte[] toBytes(Blob b) {
        try {
            InputStream is = b.getBinaryStream();
            byte[] result = IOUtils.toByteArray(is);
            is.close();
            b.free();
            return result;
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (SQLException e) {
            throw new SQLRuntimeException(e);
        }

    }
552100
protected function isBinary()
    {
        $binary = false;

        if (($this->dcs & 200) === 0) {
            $binary = (($this->dcs & 4) > 0);
        } elseif (($this->dcs & 248) === 240) {
            $binary = (($this->dcs & 4) > 0);
        }

        return $binary;
    }
1089543
def is_binary_file(file_obj):
    
    start = file_obj.tell()
    fbytes = file_obj.read(1024)
    file_obj.seek(start)
    is_str = isinstance(fbytes, str)
    for fbyte in fbytes:
        if is_str:
            code = ord(fbyte)
        else:
            code = fbyte
        if code > 127:
            return True
    return False
339903
public function isBinary()
    {
        if (is_string($this->data)) {
            $mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $this->data);
            return (substr($mime, 0, 4) != 'text' && $mime != 'application/x-empty');
        }

        return false;
    }
523339
public boolean contains(final BinaryString substring) {
		ensureMaterialized();
		substring.ensureMaterialized();
		if (substring.sizeInBytes == 0) {
			return true;
		}
		int find = SegmentsUtil.find(
			segments, offset, sizeInBytes,
			substring.segments, substring.offset, substring.sizeInBytes);
		return find != -1;
	}
903801
public boolean isThumbnail() {
    if (tags.containsTagId(254)) {
      if (tags.get(254).getCardinality() > 0)
        return BigInteger.valueOf(tags.get(254).getFirstNumericValue()).testBit(0);
    }
    if (tags.containsTagId(255)) {
      if (tags.get(255).getCardinality() > 0)
        return tags.get(255).getFirstNumericValue() == 2;
    }
    if (hasSubIFD() && getImageSize() < getsubIFD().getImageSize()) {
      return true;
    }
    if (hasParent() && getImageSize() < getParent().getImageSize()) {
      return true;
    }
    return false;
  }
1249007
private boolean matchString(final ByteBuffer bbuf) throws IOException {
		if (this.isBetween) {
			final String buffer = new String(bbuf.array());
			if (buffer.contains(getContent())) {
				return true;
			}
			return false;
		}
		final int read = getContent().length();
		for (int j = 0; j < read; j++) {
			if ((bbuf.get(j) & 0xFF) != getContent().charAt(j)) {
				return false;
			}
		}
		return true;
	}
1178300
private boolean hasBinaryFileExtension(String path) {
		boolean result = false;

		int extFileIdx = path.lastIndexOf(".");
		if (extFileIdx != -1 && extFileIdx + 1 < path.length()) {
			String extension = path.substring(extFileIdx + 1);
			result = binaryMimeTypeMap.containsKey(extension);
		}

		return result;
	}
603512
public static boolean isLinkCellule (byte[] b) {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(tc, "isLinkCellule", new Object[]{ b });

    boolean rc = false;

    if (b.length > 0) {
      rc = (b[0] == LINKCELLULE);
    }

    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(tc, "isLinkCellule", Boolean.valueOf(rc));
    return rc;
  }
1101388
def is_binary(data):
    '''
    
    '''
    if not data or not isinstance(data, (six.string_types, six.binary_type)):
        return False

    if isinstance(data, six.binary_type):
        if b'\0' in data:
            return True
    elif str('\0') in data:
        return True

    text_characters = ''.join([chr(x) for x in range(32, 127)] + list('\n\r\t\b'))
    # Get the non-text characters (map each character to itself then use the
    # 'remove' option to get rid of the text characters.)
    if six.PY3:
        if isinstance(data, six.binary_type):
            import salt.utils.data
            nontext = data.translate(None, salt.utils.data.encode(text_characters))
        else:
            trans = ''.maketrans('', '', text_characters)
            nontext = data.translate(trans)
    else:
        if isinstance(data, six.text_type):
            trans_args = ({ord(x): None for x in text_characters},)
        else:
            trans_args = (None, str(text_characters))  # future lint: blacklisted-function
        nontext = data.translate(*trans_args)

    # If more than 30% non-text characters, then
    # this is considered binary data
    if float(len(nontext)) / len(data) > 0.30:
        return True
    return False