Github user vanzin commented on a diff in the pull request: https://github.com/apache/spark/pull/1256#discussion_r15597630 --- Diff: core/src/main/scala/org/apache/spark/util/Utils.scala --- @@ -1298,6 +1298,48 @@ private[spark] object Utils extends Logging { } } + /** Load properties present in the given file. */ + def getPropertiesFromFile(filename: String): Seq[(String, String)] = { + val file = new File(filename) + require(file.exists(), s"Properties file $file does not exist") + require(file.isFile(), s"Properties file $file is not a normal file") + val inputStream = new FileInputStream(file) + getPropertiesFromInputStream(inputStream) + } + + /** Load properties present in the given inputStream. + * + * @param inputStream The given input stream will be closed. + */ + private[spark] def getPropertiesFromInputStream(inputStream: InputStream): + Seq[(String, String)] = { + val inReader = new InputStreamReader(inputStream, "UTF-8") + try { + val properties = new Properties() + properties.load(inReader) + properties.stringPropertyNames().toSeq.map(k => (k, properties(k).trim)) + } catch { + case e: IOException => + val message = s"Failed when loading Spark properties" + throw new SparkException(message, e) + } finally { + inReader.close() + } + } + + private[spark] def getDefaultSparkPropertiesFile: Option[String] = { + sys.env.get("SPARK_HOME").map { sparkHome => + val sep = File.separator + val defaultPath = s"${sparkHome}${sep}conf${sep}spark-defaults.conf" + val file = new File(defaultPath) + if (file.exists()) { + file.getAbsolutePath + } --- End diff -- nit: `else` belongs on this line
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---