fun parseRulesFile(`is`: InputStream): LinkedHashMap<Pattern, String>? { val rules: LinkedHashMap<Pattern, String> = LinkedHashMap() val br = BufferedReader( sun.security.util.IOUtils.getDecodingReader( `is`, StandardCharsets.UTF_  ) ) var line: String try { var linenum = 0 while (br.readLine().also { line = it } != null) { linenum++ val arr = line.split("#").toTypedArray() if (arr.size > 0) line = arr[0].trim { it <= ' ' } if (line.length == 0) continue val sep = line.indexOf("=") if (sep <= 0) { log.warn("Wrong format of password line $linenum") continue } val pass = line.substring(sep + 1).trim { it <= ' ' } val regex = line.substring(0, sep).trim { it <= ' ' } try { val pattern: Pattern = Pattern.compile(regex) rules[pattern] = pass } catch (pse: PatternSyntaxException) { log.warn("Key of line $linenum was not a valid regex pattern", pse) continue }  } `is`.close() } catch (e: IOException) { throw RuntimeException(e) } return rules }
Parses rule file from stream and returns a Map of all rules found