private static Optional<MemoryUnit> parseUnit(String unit) {
    if (matchesAny(unit, BYTES)) {
      return Optional.of(BYTES);
    } else if (matchesAny(unit, KILO_BYTES)) {
      return Optional.of(KILO_BYTES);
    } else if (matchesAny(unit, MEGA_BYTES)) {
      return Optional.of(MEGA_BYTES);
    } else if (matchesAny(unit, GIGA_BYTES)) {
      return Optional.of(GIGA_BYTES);
    } else if (matchesAny(unit, TERA_BYTES)) {
      return Optional.of(TERA_BYTES);
    } else if (!unit.isEmpty()) {
      throw new IllegalArgumentException(
          "Memory size unit '"
              + unit
              + "' does not match any of the recognized units: "
              + MemoryUnit.getAllUnits());
    }

    return Optional.empty();
  }
Parses the given string as bytes. The supported expressions are listed under {@link
MemorySize}.

@param text The string to parse
@return The parsed size, in bytes.
@throws IllegalArgumentException Thrown, if the expression cannot be parsed.
amoro-common/src/main/java/org/apache/amoro/utils/MemorySize.java