Skip to content

Commit 51862bf

Browse files
committed
use scala read
1 parent 3822ba9 commit 51862bf

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

core/src/main/scala/com/microsoft/azure/synapse/ml/fabric/FabricClient.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import spray.json._
88

99
import java.net.{MalformedURLException, URL}
1010
import java.util.UUID
11-
import java.nio.file.{Files, Paths}
1211
import scala.io.Source
1312

1413
object FabricClient extends RESTUtils {
@@ -124,13 +123,16 @@ object FabricClient extends RESTUtils {
124123
}
125124

126125
private def readClusterMetadata(): Map[String, String] = {
126+
val source = Source.fromFile(ClusterInfoPath)
127127
try {
128-
val jsonString = Files.readString(Paths.get(ClusterInfoPath))
128+
val jsonString = try source.mkString finally source.close()
129129
val jsValue = jsonString.parseJson
130130
val clusterMetadataJson = jsValue.asJsObject.fields("cluster_metadata")
131131
clusterMetadataJson.convertTo[Map[String, String]]
132132
} catch {
133133
case _: Exception => Map.empty[String, String]
134+
} finally {
135+
source.close()
134136
}
135137
}
136138

0 commit comments

Comments
 (0)