Made some minor style changes

This commit is contained in:
Karen Feng 2013-07-10 13:15:42 -07:00
parent cfb6447ac4
commit 04263e4d46
2 changed files with 8 additions and 9 deletions

View file

@ -622,16 +622,15 @@ private object Utils extends Logging {
}
/** Return a string containing part of a file from byte 'a' to 'b'. */
def offsetBytes(path: String, a: Long, b: Long): String = {
def offsetBytes(path: String, start: Long, end: Long): String = {
val file = new File(path)
val length = file.length()
val B = math.min(length, b)
val A = math.max(0, a)
val buff = new Array[Byte]((B-A).toInt)
val skip = A
val effectiveStart = math.min(length, start)
val effectiveEnd = math.max(0, end)
val buff = new Array[Byte]((effectiveEnd-effectiveStart).toInt)
val stream = new FileInputStream(file)
stream.skip(skip)
stream.skip(effectiveStart)
stream.read(buff)
stream.close()
Source.fromBytes(buff).mkString

View file

@ -91,13 +91,13 @@ class UISuite extends FunSuite {
// Read last few bytes
assert(Utils.offsetBytes(f1Path, 12, 18) === "7\n8\n9\n")
//Read some nonexistent bytes in the beginning
// Read some nonexistent bytes in the beginning
assert(Utils.offsetBytes(f1Path, -5, 5) === "1\n2\n3")
//Read some nonexistent bytes at the end
// Read some nonexistent bytes at the end
assert(Utils.offsetBytes(f1Path, 12, 22) === "7\n8\n9\n")
//Read some nonexistent bytes on both ends
// Read some nonexistent bytes on both ends
assert(Utils.offsetBytes(f1Path, -3, 25) === "1\n2\n3\n4\n5\n6\n7\n8\n9\n")
FileUtils.deleteDirectory(tmpDir2)