yearclass/src/main/java/com/facebook/device/yearclass/DeviceInfo.java
private static int parseFileForValue(String textToMatch, FileInputStream stream) {
    byte[] buffer = new byte[1024];
    try {
      int length = stream.read(buffer);
      for (int i = 0; i < length; i++) {
        if (buffer[i] == '\n' || i == 0) {
          if (buffer[i] == '\n') i++;
          for (int j = i; j < length; j++) {
            int textIndex = j - i;
            //Text doesn't match query at some point.
            if (buffer[j] != textToMatch.charAt(textIndex)) {
              break;
            }
            //Text matches query here.
            if (textIndex == textToMatch.length() - 1) {
              return extractValue(buffer, j);
            }
          }
        }
      }
    } catch (IOException e) {
      //Ignore any exceptions and fall through to return unknown value.
    } catch (NumberFormatException e) {
    }
    return DEVICEINFO_UNKNOWN;
  }
/**
   * Helper method for reading values from system files, using a minimised buffer.
   *
   * @param textToMatch - Text in the system files to read for.
   * @param stream      - FileInputStream of the system file being read from.
   * @return A numerical value following textToMatch in specified the system file.
   * -1 in the event of a failure.
   */
Helper method for reading values from system files, using a minimised buffer.
@param textToMatch - Text in the system files to read for.
@param stream      - FileInputStream of the system file being read from.
@return A numerical value following textToMatch in specified the system file.
-1 in the event of a failure.
Helper method for reading values from system files using a minimised buffer . @param textToMatch - Text in the system files to read for . @param stream - FileInputStream of the system file being read from . @return A numerical value following textToMatch in specified the system file . - 1 in the event of a failure .
private static int parseFileForValue(String textToMatch, FileInputStream stream) {
    byte[] buffer = new byte[1024];
    try {
      int length = stream.read(buffer);
      for (int i = 0; i < length; i++) {
        if (buffer[i] == '\n' || i == 0) {
          if (buffer[i] == '\n') i++;
          for (int j = i; j < length; j++) {
            int textIndex = j - i;
            if (buffer[j] != textToMatch.charAt(textIndex)) {
              break;
            }
            if (textIndex == textToMatch.length() - 1) {
              return extractValue(buffer, j);
            }
          }
        }
      }
    } catch (IOException e) {
    } catch (NumberFormatException e) {
    }
    return DEVICEINFO_UNKNOWN;
  }
private static int parseFileForValue ( String textToMatch , FileInputStream stream ) { byte [ ] buffer = new byte [ 1024 ] ; try { int length = stream . read ( buffer ) ; for ( int i = 0 ; i < length ; i ++ ) { if ( buffer [ i ] == '\n' || i == 0 ) { if ( buffer [ i ] == '\n' ) i ++ ; for ( int j = i ; j < length ; j ++ ) { int textIndex = j - i ; if ( buffer [ j ] != textToMatch . charAt ( textIndex ) ) { break ; } if ( textIndex == textToMatch . length ( ) - 1 ) { return extractValue ( buffer , j ) ; } } } } } catch ( IOException e ) { } catch ( NumberFormatException e ) { } return DEVICEINFO_UNKNOWN ; }
Helper method for reading values from system files, using a minimised buffer.
Helper method for reading values from system files using a minimised buffer .
//Text doesn't match query at some point. //Text matches query here. //Ignore any exceptions and fall through to return unknown value.