public BinaryFinding isBinary(List<String> codeLines,String fileName){
  if (codeLines.isEmpty()) {
    return new BinaryFinding(true,"file is empty");
  }
  String lowerFileName=fileName.toLowerCase();
  for (  String extention : this.WHITELIST) {
    if (lowerFileName.endsWith("." + extention)) {
      return new BinaryFinding(false,"appears in extension whitelist");
    }
  }
  for (  String extention : this.BLACKLIST) {
    if (lowerFileName.endsWith("." + extention)) {
      return new BinaryFinding(true,"appears in extension blacklist");
    }
  }
  for (  Classifier classifier : this.classifier) {
    for (    String extention : classifier.extensions) {
      if (lowerFileName.endsWith("." + extention)) {
        return new BinaryFinding(false,"appears in internal extension whitelist");
      }
    }
  }
  if (this.GUESSBINARY == false) {
    return new BinaryFinding(false,Values.EMPTYSTRING);
  }
  int lines=codeLines.size() < 10000 ? codeLines.size() : 10000;
  double asciiCount=0;
  double nonAsciiCount=0;
  for (int i=0; i < lines; i++) {
    String line=codeLines.get(i);
    for (int j=0; j < line.length(); j++) {
      if (((int)line.charAt(j)) <= 128) {
        asciiCount++;
      }
 else {
        nonAsciiCount++;
      }
    }
  }
  if (nonAsciiCount == 0) {
    return new BinaryFinding(false,Values.EMPTYSTRING);
  }
  if (asciiCount == 0) {
    return new BinaryFinding(true,"all characters found non-ascii");
  }
  double percent=asciiCount / (asciiCount + nonAsciiCount);
  if (percent < 0.30) {
    return new BinaryFinding(true,"only 30% of characters are non-ascii");
  }
  return new BinaryFinding(false,Values.EMPTYSTRING);
}

public BinaryFinding isBinary ( List < String > codeLines , String fileName ) { if ( codeLines . isEmpty ( ) ) { return new BinaryFinding ( true , "file is empty" ) ; } String lowerFileName = fileName . toLowerCase ( ) ; for ( String extention : this . WHITELIST ) { if ( lowerFileName . endsWith ( "." + extention ) ) { return new BinaryFinding ( false , "appears in extension whitelist" ) ; } } for ( String extention : this . BLACKLIST ) { if ( lowerFileName . endsWith ( "." + extention ) ) { return new BinaryFinding ( true , "appears in extension blacklist" ) ; } } for ( Classifier classifier : this . classifier ) { for ( String extention : classifier . extensions ) { if ( lowerFileName . endsWith ( "." + extention ) ) { return new BinaryFinding ( false , "appears in internal extension whitelist" ) ; } } } if ( this . GUESSBINARY == false ) { return new BinaryFinding ( false , Values . EMPTYSTRING ) ; } int lines = codeLines . size ( ) < 10000 ? codeLines . size ( ) : 10000 ; double asciiCount = 0 ; double nonAsciiCount = 0 ; for ( int i = 0 ; i < lines ; i ++ ) { String line = codeLines . get ( i ) ; for ( int j = 0 ; j < line . length ( ) ; j ++ ) { if ( ( ( int ) line . charAt ( j ) ) <= 128 ) { asciiCount ++ ; } else { nonAsciiCount ++ ; } } } if ( nonAsciiCount == 0 ) { return new BinaryFinding ( false , Values . EMPTYSTRING ) ; } if ( asciiCount == 0 ) { return new BinaryFinding ( true , "all characters found non-ascii" ) ; } double percent = asciiCount / ( asciiCount + nonAsciiCount ) ; if ( percent < 0.30 ) { return new BinaryFinding ( true , "only 30% of characters are non-ascii" ) ; } return new BinaryFinding ( false , Values . EMPTYSTRING ) ; }
determine if a list < string > which is used to represent a code file contains a code file that is suspected to be ascii or non ascii . this is for the purposes of excluding it from the index .
