PageRenderTime 55ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/scala-2.12/dk/mehmedbasic/audiobook/execution/CommandFactory.scala

https://bitbucket.org/mehmedbasic/scalaudiobookconverter
Scala | 40 lines | 22 code | 9 blank | 9 comment | 0 complexity | bb4b1d50706963bd39fee3cf5183d73e MD5 | raw file
  1. package dk.mehmedbasic.audiobook.execution
  2. import dk.mehmedbasic.audiobook.io.StreamReader
  3. /**
  4. * The command factory abstract class.
  5. *
  6. * Handles variability in operatingsystems.
  7. *
  8. * @author Jesenko Mehmedbasic
  9. * created 25-01-13, 01:27
  10. */
  11. abstract class CommandFactory {
  12. def createCommand(): Command = {
  13. val command: Command = OperatingSystem.locate match {
  14. case Windows => createWindowsCommand()
  15. case Unix => createUnixCommand()
  16. }
  17. addParametersToCommand(command)
  18. command
  19. }
  20. protected def createWindowsCommand(): Command
  21. protected def createUnixCommand(): Command
  22. protected def addParametersToCommand(command: Command):Unit
  23. def createProcess(): Process = {
  24. val system: OperatingSystem = OperatingSystem.locate
  25. val executor: ShellExecution = system.shellExecution()
  26. val process: Process = executor.execute(createCommand())
  27. // Read stdout and stderr
  28. new StreamReader(process.getInputStream).start()
  29. process
  30. }
  31. }