summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/io/File.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-04-02 21:09:34 +0000
committerPaul Phillips <paulp@improving.org>2010-04-02 21:09:34 +0000
commitd5c7049d4fe117e26a5e981c2449a966b017af49 (patch)
treefaaa6bfbcd86ba0de17a60361faf8547e68235d5 /src/compiler/scala/tools/nsc/io/File.scala
parentcd51ac694d82c68a5c02f9f20a9460adbac780b4 (diff)
downloadscala-d5c7049d4fe117e26a5e981c2449a966b017af49.tar.gz
scala-d5c7049d4fe117e26a5e981c2449a966b017af49.tar.bz2
scala-d5c7049d4fe117e26a5e981c2449a966b017af49.zip
Mostly IO tweaks related to my upcoming partest...
Mostly IO tweaks related to my upcoming partest patch, which to my chagrin is being held up by windows. Also updates the default ANT_OPTS to be the same as the ones the nightlies override it with. (If we know you can't build scala with those settings it seems kind of uncool to leave them for everyone else.) No review.
Diffstat (limited to 'src/compiler/scala/tools/nsc/io/File.scala')
-rw-r--r--src/compiler/scala/tools/nsc/io/File.scala30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/compiler/scala/tools/nsc/io/File.scala b/src/compiler/scala/tools/nsc/io/File.scala
index 7f2c736408..efa4ab46da 100644
--- a/src/compiler/scala/tools/nsc/io/File.scala
+++ b/src/compiler/scala/tools/nsc/io/File.scala
@@ -17,8 +17,7 @@ import java.io.{
import java.nio.channels.{ Channel, FileChannel }
import scala.io.Codec
-object File
-{
+object File {
def pathSeparator = JFile.pathSeparator
def separator = JFile.separator
@@ -34,6 +33,17 @@ object File
def closeQuietly(target: Closeable) {
try target.close() catch { case e: IOException => }
}
+
+ // this is a workaround for http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6503430
+ // we are using a static initializer to statically initialize a java class so we don't
+ // trigger java.lang.InternalErrors later when using it concurrently.
+ {
+ val tmp = JFile.createTempFile("bug6503430", null, null)
+ val in = new FileInputStream(tmp).getChannel()
+ val out = new FileOutputStream(tmp, true).getChannel()
+ out.transferFrom(in, 0, 0)
+ ()
+ }
}
import File._
import Path._
@@ -58,6 +68,8 @@ with Streamable.Chars {
override def normalize: File = super.normalize.toFile
override def isValid = jfile.isFile() || !jfile.exists()
override def length = super[Path].length
+ override def walkFilter(cond: Path => Boolean): Iterator[Path] =
+ if (cond(this)) Iterator.single(this) else Iterator.empty
/** Obtains an InputStream. */
def inputStream() = new FileInputStream(jfile)
@@ -86,8 +98,14 @@ with Streamable.Chars {
finally out close
}
- def copyFile(destPath: Path, preserveFileDate: Boolean = false) = {
- val FIFTY_MB = 1024 * 1024 * 50
+ def appendAll(strings: String*): Unit = {
+ val out = bufferedWriter(append = true)
+ try strings foreach (out write _)
+ finally out close
+ }
+
+ def copyTo(destPath: Path, preserveFileDate: Boolean = false): Boolean = {
+ val CHUNK = 1024 * 1024 * 16 // 16 MB
val dest = destPath.toFile
if (!isValid) fail("Source %s is not a valid file." format name)
if (this.normalize == dest.normalize) fail("Source and destination are the same.")
@@ -104,7 +122,7 @@ with Streamable.Chars {
val size = in.size()
var pos, count = 0L
while (pos < size) {
- count = (size - pos) min FIFTY_MB
+ count = (size - pos) min CHUNK
pos += out.transferFrom(in, pos, count)
}
}
@@ -116,6 +134,6 @@ with Streamable.Chars {
if (preserveFileDate)
dest.lastModified = this.lastModified
- ()
+ true
}
}