diff options
author | Paul Phillips <paulp@improving.org> | 2009-08-30 21:10:45 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2009-08-30 21:10:45 +0000 |
commit | dd22c570ab3b7114b280685245ace0e666bb25a9 (patch) | |
tree | 6f39efb2f064c7c747359dee12f1fe11cca4c986 /src/library | |
parent | fe334907b39f63c6a010466f5b1f43fcee156756 (diff) | |
download | scala-dd22c570ab3b7114b280685245ace0e666bb25a9.tar.gz scala-dd22c570ab3b7114b280685245ace0e666bb25a9.tar.bz2 scala-dd22c570ab3b7114b280685245ace0e666bb25a9.zip |
A little smoothing the last patch with codecs a...
A little smoothing the last patch with codecs and mkdirs().
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/io/File.scala | 9 | ||||
-rw-r--r-- | src/library/scala/io/Path.scala | 6 |
2 files changed, 12 insertions, 3 deletions
diff --git a/src/library/scala/io/File.scala b/src/library/scala/io/File.scala index 23ab25cfb1..248f8b7176 100644 --- a/src/library/scala/io/File.scala +++ b/src/library/scala/io/File.scala @@ -17,7 +17,10 @@ import collection.Traversable object File { - def apply(path: Path) = path.toFile + def apply(path: Path)(implicit codec: Codec = null) = { + val res = path.toFile + if (codec == null) res else res withCodec codec + } // Create a temporary file def makeTemp(prefix: String = Path.randomPrefix, suffix: String = null, dir: JFile = null) = @@ -40,6 +43,10 @@ extends Path(jfile) private def getCodec(): Codec = if (creationCodec == null) Codec.default else creationCodec + /** For explicitly setting the creation codec if necessary. + */ + def withCodec(codec: Codec) = new File(jfile)(codec) + override def toDirectory: Directory = new Directory(jfile) override def toFile: File = this override def create(): Boolean = jfile.createNewFile() diff --git a/src/library/scala/io/Path.scala b/src/library/scala/io/Path.scala index 41ecfceee5..33c893b9be 100644 --- a/src/library/scala/io/Path.scala +++ b/src/library/scala/io/Path.scala @@ -138,9 +138,11 @@ class Path private[io] (val jfile: JFile) // creations def create(): Boolean = true - def createDirectory(): Directory = - if (jfile.mkdirs()) new Directory(jfile) + def createDirectory(force: Boolean = true): Directory = { + val res = if (force) jfile.mkdirs() else jfile.mkdir() + if (res) new Directory(jfile) else fail("Failed to create new directory.") + } def createFile(): File = if (jfile.createNewFile()) new File(jfile) else fail("Failed to create new file.") |