From dfb7397b8ac09aaedac56e5863c7a9be3613803c Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Wed, 25 Nov 2009 13:03:41 -0500 Subject: [PATCH] A basic readLines method and moving the filtered class loader --- scripted/FilteredLoader.scala | 18 ++++++++++++++++++ util/io/FileUtilities.scala | 14 ++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 scripted/FilteredLoader.scala diff --git a/scripted/FilteredLoader.scala b/scripted/FilteredLoader.scala new file mode 100644 index 000000000..983edf040 --- /dev/null +++ b/scripted/FilteredLoader.scala @@ -0,0 +1,18 @@ +/* sbt -- Simple Build Tool + * Copyright 2009 Mark Harrah + */ +package xsbt.test + +final class FilteredLoader(parent: ClassLoader) extends ClassLoader(parent) with NotNull +{ + @throws(classOf[ClassNotFoundException]) + override final def loadClass(className: String, resolve: Boolean): Class[_] = + { + if(className.startsWith("java.") || className.startsWith("javax.")) + super.loadClass(className, resolve) + else + throw new ClassNotFoundException(className) + } + override def getResources(name: String) = null + override def getResource(name: String) = null +} \ No newline at end of file diff --git a/util/io/FileUtilities.scala b/util/io/FileUtilities.scala index be115bda8..06034befd 100644 --- a/util/io/FileUtilities.scala +++ b/util/io/FileUtilities.scala @@ -380,6 +380,20 @@ object FileUtilities out.toByteArray } + // Not optimized for large files + def readLines(file: File): List[String] = readLines(file, defaultCharset) + def readLines(file: File, charset: Charset): List[String] = + { + fileReader(charset)(file){ in => + def readLine(accum: List[String]): List[String] = + { + val line = in.readLine() + if(line eq null) accum.reverse else readLine(line :: accum) + } + readLine(Nil) + } + } + /** A pattern used to split a String by path separator characters.*/ private val PathSeparatorPattern = java.util.regex.Pattern.compile(File.pathSeparator)