Created
March 17, 2014 10:02
-
-
Save markusjura/9596777 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package controllers | |
import play.api._ | |
import play.api.mvc._ | |
import models.Files | |
import play.api.libs.json.Json | |
import scala.concurrent.Future | |
import play.api.libs.concurrent.Execution.Implicits._ | |
object FileController extends SecuredController { | |
def countChars = Action.async { | |
Future { | |
val chars = Files.countChars("public/files/chars.txt") | |
Ok(Json.obj("chars" -> chars)) | |
} | |
} | |
def countCharsBlocking = Action { | |
val chars = Files.countChars("public/files/chars.txt") | |
Ok(Json.obj("chars" -> chars)) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package models | |
import scala.io.Source | |
object Files { | |
def countChars(filePath: String): Long = { | |
val source = Source.fromFile(filePath) | |
var chars = 0L | |
for (line <- source.getLines) { | |
chars += line.toCharArray.size | |
} | |
source.close() | |
chars | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GET /count controllers.FileController.countChars() | |
GET /countBlocking controllers.FileController.countCharsBlocking() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment