Skip to content
This repository has been archived by the owner on Oct 18, 2021. It is now read-only.

remove the close for hdfs system #147

Merged
merged 1 commit into from
Sep 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,23 @@ object HDFSUtils {
conf.set("fs.default.name", namenode)
conf.set("fs.defaultFS", namenode)
}
conf.set("fs.hdfs.impl.disable.cache", "true")
FileSystem.get(conf)
}

def list(path: String): List[String] = {
val system = getFileSystem()
try {
system.listStatus(new Path(path)).map(_.getPath.getName).toList
} finally {
system.close()
}
system.listStatus(new Path(path)).map(_.getPath.getName).toList
}

def exists(path: String): Boolean = {
val system = getFileSystem()
try {
system.exists(new Path(path))
} finally {
system.close()
}
system.exists(new Path(path))
}

def getContent(path: String): String = {
val system = getFileSystem()
val inputStream = system.open(new Path(path))
try {
Source.fromInputStream(inputStream).mkString
} finally {
system.close()
}
Source.fromInputStream(inputStream).mkString
}

def saveContent(path: String,
Expand Down Expand Up @@ -79,10 +66,6 @@ object HDFSUtils {
e)
}
val system = getFileSystem(namenode)
try {
system.copyFromLocalFile(new Path(localPath), new Path(remotePath))
} finally {
system.close()
}
system.copyFromLocalFile(new Path(localPath), new Path(remotePath))
}
}