[2.x] refactor: Use Files.writeString instead of Files.write (#9093)

This commit is contained in:
kenji yoshida 2026-04-16 11:29:19 +09:00 committed by GitHub
parent 60cbde453f
commit 9d620f3b1f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
23 changed files with 23 additions and 24 deletions

View File

@ -31,7 +31,7 @@ object LockFile {
val json = Converter.toJson(data).get
val content = PrettyPrinter(json)
lockFile.getParentFile.mkdirs()
Files.write(lockFile.toPath, content.getBytes(StandardCharsets.UTF_8))
Files.writeString(lockFile.toPath, content)
} match {
case Success(_) => Right(())
case Failure(ex) => Left(s"Failed to write lock file: ${ex.getMessage}")

View File

@ -3,6 +3,6 @@ import java.nio.file.Files
object Main {
def main(args: Array[String]): Unit = {
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
Files.writeString(new File("output").toPath, "OK")
}
}

View File

@ -29,6 +29,6 @@ object Main {
"Expected not to find classes from argonaut"
)
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
Files.writeString(new File("output").toPath, "OK")
}
}

View File

@ -34,6 +34,6 @@ object Main {
"Expected not to find class from cats-mtl"
)
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
Files.writeString(new File("output").toPath, "OK")
}
}

View File

@ -5,6 +5,6 @@ import org.apache.zookeeper.ZooKeeper
object Main {
def main(args: Array[String]): Unit = {
Files.write(new File("output").toPath, classOf[ZooKeeper].getSimpleName.getBytes("UTF-8"))
Files.writeString(new File("output").toPath, classOf[ZooKeeper].getSimpleName)
}
}

View File

@ -4,6 +4,6 @@ import java.nio.file.Paths
object Main {
def main(args: Array[String]): Unit = {
val msg = Bar.value
Files.write(Paths.get("baz/output"), msg.getBytes("UTF-8"))
Files.writeString(Paths.get("baz/output"), msg)
}
}

View File

@ -10,6 +10,6 @@ object Main {
def main(args: Array[String]): Unit = {
val msg = CC(2, A.msg).asJson.spaces2
Files.write(new File("output").toPath, msg.getBytes("UTF-8"))
Files.writeString(new File("output").toPath, msg)
}
}

View File

@ -16,6 +16,6 @@ object Main {
assert(hadoopVersion == "2.6.0")
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
Files.writeString(new File("output").toPath, "OK")
}
}

View File

@ -8,6 +8,6 @@ object Main {
// assert(Thread.currentThread.getContextClassLoader.getResource("org/nlogo/nvm/Task.class") != null)
// Thread.currentThread.getContextClassLoader.getResource("org/nlogo/nvm/Task.class")
def main(args: Array[String]): Unit = {
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
Files.writeString(new File("output").toPath, "OK")
}
}

View File

@ -13,7 +13,7 @@ csrExtraCredentials += {
|foo.https-only=false
""".stripMargin
val dest = (ThisBuild / baseDirectory).value / "project" / "target" / "cred"
Files.write(dest.toPath, content.getBytes("UTF-8"))
Files.writeString(dest.toPath, content)
lmcoursier.credentials.FileCredentials(dest.toString)
}

View File

@ -8,6 +8,6 @@ object Main {
// assert(Thread.currentThread.getContextClassLoader.getResource("org/nlogo/nvm/Task.class") != null)
// Thread.currentThread.getContextClassLoader.getResource("org/nlogo/nvm/Task.class")
def main(args: Array[String]): Unit = {
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
Files.writeString(new File("output").toPath, "OK")
}
}

View File

@ -11,6 +11,6 @@ object Main {
val l = Generic[CC].to(cc)
val msg = l.head
Files.write(new File("output").toPath, msg.getBytes("UTF-8"))
Files.writeString(new File("output").toPath, msg)
}
}

View File

@ -11,6 +11,6 @@ object Main {
val l = Generic[CC].to(cc)
val msg = l.head
Files.write(new File("output").toPath, msg.getBytes("UTF-8"))
Files.writeString(new File("output").toPath, msg)
}
}

View File

@ -6,6 +6,6 @@ object Main {
// TODO Use some jvm-repr stuff as a test
def main(args: Array[String]): Unit = {
Files.write(new File("output").toPath, A.default.msg.getBytes("UTF-8"))
Files.writeString(new File("output").toPath, A.default.msg)
}
}

View File

@ -10,6 +10,6 @@ import java.nio.file.Files
*/
object Main {
def main(args: Array[String]): Unit = {
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
Files.writeString(new File("output").toPath, "OK")
}
}

View File

@ -6,6 +6,6 @@ object Main {
// TODO Use some jvm-repr stuff
def main(args: Array[String]): Unit = {
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
Files.writeString(new File("output").toPath, "OK")
}
}

View File

@ -3,6 +3,6 @@ import java.nio.file.Files
object Main {
def main(args: Array[String]): Unit = {
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
Files.writeString(new File("output").toPath, "OK")
}
}

View File

@ -63,6 +63,6 @@ object Main {
notFromCoursierCache("scala-library")
assert(props.lengthCompare(1) == 0, s"Found several library.properties files in classpath: $props")
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
Files.writeString(new File("output").toPath, "OK")
}
}

View File

@ -3,6 +3,6 @@ import java.nio.file.Files
object Main {
def main(args: Array[String]): Unit = {
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
Files.writeString(new File("output").toPath, "OK")
}
}

View File

@ -3,6 +3,6 @@ import java.nio.file.Files
object Main {
def main(args: Array[String]): Unit = {
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
Files.writeString(new File("output").toPath, "OK")
}
}

View File

@ -5,6 +5,6 @@ import org.apache.zookeeper.ZooKeeper
object Main {
def main(args: Array[String]): Unit = {
Files.write(new File("output").toPath, classOf[ZooKeeper].getSimpleName.getBytes("UTF-8"))
Files.writeString(new File("output").toPath, classOf[ZooKeeper].getSimpleName)
}
}

View File

@ -2,4 +2,4 @@ import java.io.File
import java.nio.file.Files
@main def hello() =
Files.write(new File("output").toPath, "OK".getBytes("UTF-8"))
Files.writeString(new File("output").toPath, "OK")

View File

@ -10,7 +10,6 @@ package sbt
package internal
package librarymanagement
import java.nio.charset.StandardCharsets.UTF_8
import java.nio.file.Files
import lmcoursier.definitions.{ Configuration, Project }
@ -66,7 +65,7 @@ object IvyXml {
val content0 = rawContent(currentProject, shadedConfigOpt, bomForcedDeps)
cacheIvyFile.getParentFile.mkdirs()
log.debug(s"writing Ivy file $cacheIvyFile")
Files.write(cacheIvyFile.toPath, content0.getBytes(UTF_8))
Files.writeString(cacheIvyFile.toPath, content0)
// Just writing an empty file here... Are these only used?
cacheIvyPropertiesFile.getParentFile.mkdirs()