Added more @Throws to methods

master
Robinson 2021-01-26 22:14:13 +01:00
parent e93d1c1424
commit 6bd8ab87e1
7 changed files with 30 additions and 2 deletions

View File

@ -293,6 +293,7 @@ class JvmExecOptions(private val executor: Executor) {
* @throws TimeoutException timeout set by [.timeout] was reached.
* @throws InvalidExitValueException if invalid exit value was returned (@see [.exitValues]).
*/
@Throws(IOException::class, InterruptedException::class, TimeoutException::class, InvalidExitValueException::class)
suspend fun start(): SyncProcessResult {
return executor.start()
}

View File

@ -43,4 +43,5 @@ internal class ProcessAttributes(
/**
* Set of accepted exit codes or `null` if all exit codes are allowed.
*/
val allowedExitValues: Set<Int> = setOf())
val allowedExitValues: Set<Int> = setOf()
)

View File

@ -18,6 +18,8 @@ package dorkbox.executor
import net.schmizz.sshj.SSHClient
import net.schmizz.sshj.connection.channel.direct.Session
import net.schmizz.sshj.connection.channel.direct.Signal
import net.schmizz.sshj.transport.TransportException
import java.io.IOException
import java.io.InputStream
import java.io.OutputStream
@ -50,9 +52,29 @@ class SshProcess(private val ssh: SSHClient,
return exitValue()
}
/**
* Send a signal to the remote command.
*
* @param signal the signal
*
* @throws TransportException if error sending the signal
*/
@Throws(TransportException::class)
fun signal(signal: Signal) {
command.signal(signal)
}
/**
* If the command exit violently [with a signal][.getExitSignal], information about whether a core dump
* took place would have been received and can be retrieved via this method.
*/
fun exitWasCoreDumped(): Boolean {
return command.exitWasCoreDumped ?: false
}
override fun exitValue(): Int {
return if (command.isOpen) {
-1
PidHelper.INVALID.toInt()
} else {
return command.exitStatus
}

View File

@ -116,6 +116,7 @@ open class AsyncProcessOutput(private val channel: Channel<Byte>, private val pr
*
* @throws IllegalStateException if the char set was not supported.
*/
@Throws(IllegalStateException::class)
suspend fun string(charset: Charset): String {
return try {
String(getBuffered(), charset)

View File

@ -37,6 +37,7 @@ class NopProcessResult(pid: Long, exitValue: Int) : SyncProcessResult(pid, exitV
*
* @throws IllegalStateException if reading the output was not enabled.
*/
@get:Throws(IllegalStateException::class)
override val output: ProcessOutput
get() {
throw IllegalStateException("Process output was not read. " +

View File

@ -67,6 +67,7 @@ class ProcessOutput(internal val bytes_: ByteArray) {
*
* @throws IllegalStateException if the char set was not supported.
*/
@Throws(IllegalStateException::class)
fun string(charset: Charset): String {
return try {
String(bytes_, charset)

View File

@ -52,6 +52,7 @@ open class SyncProcessResult(
*
* @throws IllegalStateException if reading the output was not enabled.
*/
@get:Throws(IllegalStateException::class)
open val output: ProcessOutput by lazy {
ProcessOutput(out)
}