Skip to content

Commit bc507f2

Browse files
authored
@W-8295960@ avoid repeated codec factory initialization (#526)
1 parent 41c9a2b commit bc507f2

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

core/src/main/scala/com/salesforce/op/OpWorkflowModelReader.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ private object WorkflowFileReader {
268268
val rawModel = "rawModel"
269269
val zipModel = "Model.zip"
270270
def modelStagingDir: String = s"modelStagingDir/model-${System.currentTimeMillis}"
271+
val confWithDefaultCodec = new Configuration(false)
272+
val codecFactory = new CompressionCodecFactory(confWithDefaultCodec)
271273

272274
def loadFile(pathString: String)(implicit conf: Configuration): String = {
273275
Try {
@@ -290,11 +292,10 @@ private object WorkflowFileReader {
290292
}
291293

292294
private def readAsString(path: Path)(implicit conf: Configuration): String = {
293-
val codecFactory = new CompressionCodecFactory(conf)
294-
val codec = Option(codecFactory.getCodec(path))
295295
val in = FileSystem.getLocal(conf).open(path)
296296
try {
297-
val read = codec.map(c => Source.fromInputStream(c.createInputStream(in)).mkString)
297+
val read = Option(codecFactory.getCodec(path))
298+
.map(c => Source.fromInputStream(c.createInputStream(in)).mkString)
298299
.getOrElse(IOUtils.toString(in, "UTF-8"))
299300
read
300301
} finally {

0 commit comments

Comments
 (0)