blob: d54bc6cdf9edac7f1b05860f25e233aa5d72368a [file] [log] [blame] [raw]
package li.cil.oc.server.fs
import java.io
trait FileInputStreamFileSystem extends InputStreamFileSystem {
protected val root: io.File
// ----------------------------------------------------------------------- //
override def spaceTotal = 0
override def spaceUsed = 0
// ----------------------------------------------------------------------- //
override def exists(path: String) = new io.File(root, path).exists()
override def size(path: String) = new io.File(root, path) match {
case file if file.isFile => file.length()
case _ => 0L
}
override def isDirectory(path: String) = new io.File(root, path).isDirectory
override def lastModified(path: String) = new io.File(root, path).lastModified
override def list(path: String) = new io.File(root, path) match {
case file if file.exists() && file.isFile => Array(file.getName)
case directory if directory.exists() && directory.isDirectory =>
directory.listFiles().map(file => if (file.isDirectory) file.getName + "/" else file.getName)
case _ => throw new io.FileNotFoundException("no such file or directory")
}
// ----------------------------------------------------------------------- //
override protected def openInputStream(path: String): Option[io.InputStream] =
Some(new io.FileInputStream(new io.File(root, path)))
}