code: public static boolean isBase64(InputStream in) throws IOException {
      long numBase64Chars = 0;
      int numPadding = 0;
      int read;
  
      while ((read = in.read()) != -1) {
        read = reverseBase64Chars[read];
        if (read == NON_BASE_64) {
          return false;
        } else if (read == NON_BASE_64_WHITESPACE) {
          // ignore white space
        } else if (read == NON_BASE_64_PADDING) {
          numPadding++;
          numBase64Chars++;
        } else if (numPadding > 0) {
          return false;
        } else {
          numBase64Chars++;
        }
      }
      if (numBase64Chars == 0) {
        return false;
      }
      if (numBase64Chars % 4 != 0) {
        return false;
      }
      return true;
    }
docs: Reads data from the stream and determines if it is in base64 format.
  <p>
  Data will be considered to be in base64 format if it contains only base64 characters and white
  space with equals sign padding on the end so that the number of base64 characters is divisible
  by four.
  <p>
  It is possible for data to be in base64 format but for it to not meet these stringent
  requirements.  It is also possible for data to meet these requirements even though decoding it
  would not make any sense.  This method should be used as a guide but it is not authoritative
  because of the possibility of these false positives and false negatives.
  <p>
  Additionally, extra data such as headers or footers may throw this method off the scent and
  cause it to return false.
  
  @param in Stream from which to read data to be tested.
  @return Best guess as to whether the data is in base64 format.
  @throws IOException if an IO error occurs.
  @since ostermillerutils 1.00.00