-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d94f7c
commit 1341560
Showing
12 changed files
with
299 additions
and
77 deletions.
There are no files selected for viewing
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
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
31 changes: 31 additions & 0 deletions
31
src/main/kotlin/com/jillesvangurp/kotlin4example/BlockOutputCapture.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.jillesvangurp.kotlin4example | ||
|
||
import java.io.ByteArrayOutputStream | ||
import java.io.PrintWriter | ||
|
||
/** | ||
* Simple facade that captures calls to print and println and collects | ||
* what would have been printed in a buffer. | ||
*/ | ||
class BlockOutputCapture { | ||
private val byteArrayOutputStream = ByteArrayOutputStream() | ||
private val printWriter = PrintWriter(byteArrayOutputStream) | ||
|
||
fun print(message: Any?) { | ||
printWriter.print(message) | ||
} | ||
|
||
fun println(message: Any?) { | ||
printWriter.println(message) | ||
} | ||
|
||
fun output(): String { | ||
printWriter.flush() | ||
return byteArrayOutputStream.toString() | ||
} | ||
|
||
fun reset() { | ||
printWriter.flush() | ||
byteArrayOutputStream.reset() | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/kotlin/com/jillesvangurp/kotlin4example/ExampleOutput.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.jillesvangurp.kotlin4example | ||
|
||
/** | ||
* When you use [Kotlin4Example.example] it uses this as the return value. | ||
*/ | ||
data class ExampleOutput<T>( | ||
val result: Result<T?>, | ||
val stdOut: String, | ||
) |
Oops, something went wrong.