A basic readLines method and moving the filtered class loader

This commit is contained in:
Mark Harrah 2009-11-25 13:03:41 -05:00
parent a872ebc5e5
commit dfb7397b8a
2 changed files with 32 additions and 0 deletions

View File

@ -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
}

View File

@ -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)